MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / connect

Function connect

asyncpg/connection.py:2116–2521  ·  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

2114
2115
2116async def connect(dsn=None, *,
2117 host=None, port=None,
2118 user=None, password=None, passfile=None,
2119 service=None,
2120 servicefile=None,
2121 database=None,
2122 loop=None,
2123 timeout=60,
2124 statement_cache_size=100,
2125 max_cached_statement_lifetime=300,
2126 max_cacheable_statement_size=1024 * 15,
2127 command_timeout=None,
2128 ssl=None,
2129 direct_tls=None,
2130 connection_class=Connection,
2131 record_class=protocol.Record,
2132 server_settings=None,
2133 target_session_attrs=None,
2134 krbsrvname=None,
2135 gsslib=None):
2136 r"""A coroutine to establish a connection to a PostgreSQL server.
2137
2138 The connection parameters may be specified either as a connection
2139 URI in *dsn*, or as specific keyword arguments, or both.
2140 If both *dsn* and keyword arguments are specified, the latter
2141 override the corresponding values parsed from the connection URI.
2142 The default values for the majority of arguments can be specified
2143 using `environment variables <postgres envvars_>`_.
2144
2145 Returns a new :class:`~asyncpg.connection.Connection` object.
2146
2147 :param dsn:
2148 Connection arguments specified using as a single string in the
2149 `libpq connection URI format`_:
2150 ``postgres://user:password@host:port/database?option=value``.
2151 The following options are recognized by asyncpg: ``host``,
2152 ``port``, ``user``, ``database`` (or ``dbname``), ``password``,
2153 ``passfile``, ``sslmode``, ``sslcert``, ``sslkey``, ``sslrootcert``,
2154 and ``sslcrl``. Unlike libpq, asyncpg will treat unrecognized
2155 options as `server settings`_ to be used for the connection.
2156
2157 .. note::
2158
2159 The URI must be *valid*, which means that all components must
2160 be properly quoted with :py:func:`urllib.parse.quote_plus`, and
2161 any literal IPv6 addresses must be enclosed in square brackets.
2162 For example:
2163
2164 .. code-block:: text
2165
2166 postgres://dbuser@[fe80::1ff:fe23:4567:890a%25eth0]/dbname
2167
2168 :param host:
2169 Database host address as one of the following:
2170
2171 - an IP address or a domain name;
2172 - an absolute path to the directory containing the database
2173 server Unix-domain socket (not supported on Windows);

Calls 1

_check_record_classFunction · 0.85

Tested by 3

_run_connection_testMethod · 0.68