@@ -1787,10 +1787,11 @@ async def connect(dsn=None, *,
17871787 Connection arguments specified using as a single string in the 
17881788 `libpq connection URI format`_: 
17891789 ``postgres://user:password@host:port/database?option=value``. 
1790-  The following options are recognized by asyncpg: host, port, 
1791-  user, database (or dbname), password, passfile, sslmode. 
1792-  Unlike libpq, asyncpg will treat unrecognized options 
1793-  as `server settings`_ to be used for the connection. 
1790+  The following options are recognized by asyncpg: ``host``, 
1791+  ``port``, ``user``, ``database`` (or ``dbname``), ``password``, 
1792+  ``passfile``, ``sslmode``, ``sslcert``, ``sslkey``, ``sslrootcert``, 
1793+  and ``sslcrl``. Unlike libpq, asyncpg will treat unrecognized 
1794+  options as `server settings`_ to be used for the connection. 
17941795
17951796 .. note:: 
17961797
@@ -1912,6 +1913,51 @@ async def connect(dsn=None, *,
19121913
19131914 *ssl* is ignored for Unix domain socket communication. 
19141915
1916+  Example of programmatic SSL context configuration that is equivalent 
1917+  to ``sslmode=verify-full&sslcert=..&sslkey=..&sslrootcert=..``: 
1918+ 
1919+  .. code-block:: pycon 
1920+ 
1921+  >>> import asyncpg 
1922+  >>> import asyncio 
1923+  >>> import ssl 
1924+  >>> async def main(): 
1925+  ... # Load CA bundle for server certificate verification, 
1926+  ... # equivalent to sslrootcert= in DSN. 
1927+  ... sslctx = ssl.create_default_context( 
1928+  ... ssl.Purpose.SERVER_AUTH, 
1929+  ... cafile="path/to/ca_bundle.pem") 
1930+  ... # If True, equivalent to sslmode=verify-full, if False: 
1931+  ... # sslmode=verify-ca. 
1932+  ... sslctx.check_hostname = True 
1933+  ... # Load client certificate and private key for client 
1934+  ... # authentication, equivalent to sslcert= and sslkey= in 
1935+  ... # DSN. 
1936+  ... sslctx.load_cert_chain( 
1937+  ... "path/to/client.cert", 
1938+  ... keyfile="path/to/client.key", 
1939+  ... ) 
1940+  ... con = await asyncpg.connect(user='postgres', ssl=sslctx) 
1941+  ... await con.close() 
1942+  >>> asyncio.run(run()) 
1943+ 
1944+  Example of programmatic SSL context configuration that is equivalent 
1945+  to ``sslmode=require`` (no server certificate or host verification): 
1946+ 
1947+  .. code-block:: pycon 
1948+ 
1949+  >>> import asyncpg 
1950+  >>> import asyncio 
1951+  >>> import ssl 
1952+  >>> async def main(): 
1953+  ... sslctx = ssl.create_default_context( 
1954+  ... ssl.Purpose.SERVER_AUTH) 
1955+  ... sslctx.check_hostname = False 
1956+  ... sslctx.verify_mode = ssl.CERT_NONE 
1957+  ... con = await asyncpg.connect(user='postgres', ssl=sslctx) 
1958+  ... await con.close() 
1959+  >>> asyncio.run(run()) 
1960+ 
19151961 :param dict server_settings: 
19161962 An optional dict of server runtime parameters. Refer to 
19171963 PostgreSQL documentation for 
@@ -1970,6 +2016,10 @@ async def connect(dsn=None, *,
19702016 .. versionchanged:: 0.22.0 
19712017 The *ssl* argument now defaults to ``'prefer'``. 
19722018
2019+  .. versionchanged:: 0.24.0 
2020+  The ``sslcert``, ``sslkey``, ``sslrootcert``, and ``sslcrl`` options 
2021+  are supported in the *dsn* argument. 
2022+ 
19732023 .. _SSLContext: https://docs.python.org/3/library/ssl.html#ssl.SSLContext 
19742024 .. _create_default_context: 
19752025 https://docs.python.org/3/library/ssl.html#ssl.create_default_context 
0 commit comments