MCPcopy Index your code
hub / github.com/MagicStack/asyncpg / connect

Function connect

asyncpg/connection.py:2083–2466  ·  view source on GitHub ↗

r"""A coroutine to establish a connection to a PostgreSQL server. The connection parameters may be specified either as a connection URI in *dsn*, or as specific keyword arguments, or both. If both *dsn* and keyword arguments are specified, the latter override the corresponding value

(dsn=None, *,
                  host=None, port=None,
                  user=None, password=None, passfile=None,
                  service=None,
                  servicefile=None,
                  database=None,
                  loop=None,
                  timeout=60,
                  statement_cache_size=100,
                  max_cached_statement_lifetime=300,
                  max_cacheable_statement_size=1024 * 15,
                  command_timeout=None,
                  ssl=None,
                  direct_tls=None,
                  connection_class=Connection,
                  record_class=protocol.Record,
                  server_settings=None,
                  target_session_attrs=None,
                  krbsrvname=None,
                  gsslib=None)

Source from the content-addressed store, hash-verified

2081
2082
2083async def connect(dsn=None, *,
2084 host=None, port=None,
2085 user=None, password=None, passfile=None,
2086 service=None,
2087 servicefile=None,
2088 database=None,
2089 loop=None,
2090 timeout=60,
2091 statement_cache_size=100,
2092 max_cached_statement_lifetime=300,
2093 max_cacheable_statement_size=1024 * 15,
2094 command_timeout=None,
2095 ssl=None,
2096 direct_tls=None,
2097 connection_class=Connection,
2098 record_class=protocol.Record,
2099 server_settings=None,
2100 target_session_attrs=None,
2101 krbsrvname=None,
2102 gsslib=None):
2103 r"""A coroutine to establish a connection to a PostgreSQL server.
2104
2105 The connection parameters may be specified either as a connection
2106 URI in *dsn*, or as specific keyword arguments, or both.
2107 If both *dsn* and keyword arguments are specified, the latter
2108 override the corresponding values parsed from the connection URI.
2109 The default values for the majority of arguments can be specified
2110 using `environment variables <postgres envvars_>`_.
2111
2112 Returns a new :class:`~asyncpg.connection.Connection` object.
2113
2114 :param dsn:
2115 Connection arguments specified using as a single string in the
2116 `libpq connection URI format`_:
2117 ``postgres://user:password@host:port/database?option=value``.
2118 The following options are recognized by asyncpg: ``host``,
2119 ``port``, ``user``, ``database`` (or ``dbname``), ``password``,
2120 ``passfile``, ``sslmode``, ``sslcert``, ``sslkey``, ``sslrootcert``,
2121 and ``sslcrl``. Unlike libpq, asyncpg will treat unrecognized
2122 options as `server settings`_ to be used for the connection.
2123
2124 .. note::
2125
2126 The URI must be *valid*, which means that all components must
2127 be properly quoted with :py:func:`urllib.parse.quote_plus`, and
2128 any literal IPv6 addresses must be enclosed in square brackets.
2129 For example:
2130
2131 .. code-block:: text
2132
2133 postgres://dbuser@[fe80::1ff:fe23:4567:890a%25eth0]/dbname
2134
2135 :param host:
2136 Database host address as one of the following:
2137
2138 - an IP address or a domain name;
2139 - an absolute path to the directory containing the database
2140 server Unix-domain socket (not supported on Windows);

Callers 2

_run_connection_testMethod · 0.85

Calls 1

_check_record_classFunction · 0.85

Tested by 2

_run_connection_testMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…