Description
asyncpg -- A fast PostgreSQL Database Client Library for Python/asyncio ======================================================================= .. image:: https://github.com/MagicStack/asyncpg/workflows/Tests/badge.svg :target: https://github.com/MagicStack/asyncpg/actions?query=workflow%3ATests+branch%3Amaster :alt: GitHub Actions status .. image:: https://img.shields.io/pypi/v/asyncpg.svg :target: https://pypi.python.org/pypi/asyncpg **asyncpg** is a database interface library designed specifically for PostgreSQL and Python/asyncio. asyncpg is an efficient, clean implementation of PostgreSQL server binary protocol for use with Python's ``asyncio`` framework. You can read more about asyncpg in an introductory `blog post <http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/>`_. asyncpg requires Python 3.9 or later and is supported for PostgreSQL versions 9.5 to 18. Other PostgreSQL versions or other databases implementing the PostgreSQL protocol *may* work, but are not being actively tested. Documentation ------------- The project documentation can be found `here <https://magicstack.github.io/asyncpg/current/>`_. Performance ----------- In our testing asyncpg is, on average, **5x** faster than psycopg3. .. image:: https://raw.githubusercontent.com/MagicStack/asyncpg/master/performance.png?fddca40ab0 :target: https://gistpreview.github.io/?0ed296e93523831ea0918d42dd1258c2 The above results are a geometric mean of benchmarks obtained with PostgreSQL `client driver benchmarking toolbench <https://github.com/MagicStack/pgbench>`_ in June 2023 (click on the chart to see full details). Features -------- asyncpg implements PostgreSQL server protocol natively and exposes its features directly, as opposed to hiding them behind a generic facade like DB-API. This enables asyncpg to have easy-to-use support for: * **prepared statements** * **scrollable cursors** * **partial iteration** on query results * automatic encoding and decoding of composite types, arrays, and any combination of those * straightforward support for custom data types Installation ------------ asyncpg is available on PyPI. When not using GSSAPI/SSPI authentication it has no dependencies. Use pip to install:: $ pip install asyncpg If you need GSSAPI/SSPI authentication, use:: $ pip install 'asyncpg[gssauth]' For more details, please `see the documentation <https://magicstack.github.io/asyncpg/current/installation.html>`_. Basic Usage ----------- .. code-block:: python import asyncio import asyncpg async def run(): conn = await asyncpg.connect(user='user', password='password', database='database', host='127.0.0.1') values = await conn.fetch( 'SELECT * FROM mytable WHERE id = $1', 10, ) await conn.close() asyncio.run(run()) License ------- asyncpg is developed and distributed under the Apache 2.0 license.
Release History
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 0.31.0 | Imported from PyPI (0.31.0) | Low | 4/21/2026 |
| v0.31.0 | Enable Python 3.14 with experimental subinterpreter/freethreading support. Improvements ============ * Add Python 3.14 support, experimental subinterpreter/freethreading support (#1279) (by @elprans in 9e42642b) * Avoid performing type introspection on known types (#1243) (by @elprans in 5c9986c4) * Make `prepare()` not use named statements by default when cache is disabled (#1245) (by @elprans in 5b14653e) * Implement connection service file functionality (#1223) (by @AndrewJackson | Low | 11/24/2025 |
| v0.30.0 | Support Python 3.13 and PostgreSQL 17. Improvements ============ * Implement GSSAPI authentication (by @eltoder in 1d4e5680 for #1122) * Implement SSPI authentication (by @eltoder in 1aab2094 for #1128) * Add initial typings (by @bryanforbes in d42432bf for #1127) * Allow building with Cython 3 (by @musicinmybrain in 258d8a95 for #1101) * docs: fix connection pool close call (#1125) (by @paulovitorweb in e8488149 for #1125) * Add support for the `sslnegotiation` parameter (by | Low | 10/20/2024 |
| v0.29.0 | Minor fixes and improvements. Improvements ============ * Python 3.12 and PostgreSQL 16 support (#1084) (by @elprans in deea86ce) * Add support for tuple-format custom codecs on composite types (#1061) (by @elprans in 922fcd10) * Support `target_session_attrs` in URL format, add tests (#1073) (by @elprans in 7cb4e70d) * Infinity numeric support (#1067) (by @krokoziabla in 0c3bf600 for #1020) * Add support for the `WHERE` clause in `copy_to` methods (#941) (by @kaylynn234 in b7ffa | Low | 11/5/2023 |
| v0.28.0 | Minor fixes and improvements. Changes ======= * Do not try to cleanup statements (#981) (by @fvannee in d2e710fe for #981) * Add Pool.is_closing() method (#973) (by @singingwolfboy in 9cb2c1ce for #973) * Fix test_tls_version for LibreSSL (#974) (by @CyberTailor in 7df9812a for #974) * Handle environments without home dir (#1011) (by @LeonardBesson in 172b8f69 for #1011) * fix: salt and iterations parsing for scram (#1026) (by @trigonometr in 7443a9e7 for #1026) * Add support fo | Low | 7/7/2023 |
| v0.27.0 | Support Python 3.11 and PostgreSQL 15. This release also drops support for Python 3.6. Changes ======= * Add arm64 mac and linux wheels (by @ddelange in 7bd6c49f for #954) * Add Python 3.11 to the test matrix (by @elprans in 5f908e67 for #948) * Exclude .venv from flake8 (#958) (by @jparise in 40b16ea6 for #958) * Upgrade to flake8 5.0.4 (from 3.9.2) (#961) (by @jparise in 0e73fec2 for #961) * Show an example of a custom Record class (#960) (by @jparise in 84c99bfd for #960) * | Low | 10/26/2022 |
| v0.26.0 | Changes ------- * Add support to use awaitable object in password function. (#889) (by @kwarunek in fb3b6bf7 for #889) * Support direct TLS connections (i.e. no STARTTLS) (#923) (by @jackwotherspoon in f2a937d2 for #923) Fixes ----- * Fix invalid `pyproject.toml` (#900) (by @Rongronggg9 in eddb649c for #900) * Add `record_class` parameter Pool.fetch and Pool.fetchrow (#896) (by @baltitenger in 2519cf38 for #896) * Domain basetypes are introspected (#886) (#887) (by @QuantumTM i | Low | 7/7/2022 |
| v0.25.0 | Changes ------- * Improve SSL option compatibility in URIs (by @fantix in 383c711e for #827) * Add `Pool` methods to determine its min, max, current and idle size (by @elprans in 603e3868 for #849) * Make it possible to specify a statement name in `Connection.prepare()` (by @elprans in 03a3d18f for #846) * Implement support for `multirange` types (by @elprans in d64a44a1 for #851) Fixes ----- * Make sure timeout callbacks always get cleaned up (by @elprans in dad26913 for #831) | Low | 11/16/2021 |
| v0.24.0 | Changes ------- * Drop support for Python 3.5 (#777) (by @and-semakin in da58cd26 for #777) * Add support for Python 3.10 (#795) (by @elprans in abf55699 for #795) * Add support for asynchronous iterables to `copy_records_to_table()` (#713) (by @elprans in 1d33ff62 for #713) * Add support for coroutine functions as listener callbacks (#802) (by @elprans in 41da093e for #802) * Add support for sslcert, sslkey and sslrootcert parameters to DSN (#768) (by @jdobes and @elprans in c674 | Low | 8/10/2021 |
| v0.23.0 | Fixes ----- * Avoid TypeError in `Transaction.__repr__` (#703) (by @BeatButton in d6eea8ed for #703) * Feed memoryview to `writelines()` (#715) (by @fantix in 359a34c4 for #715) * Add sslmode=allow support and fix =prefer retry (#720) (by @fantix in 075114c1 for #720) * Loosen message test in `test_invalid_input` (#751) (by @musicinmybrain in bc4127f4 for #751) * Support readonly and deferrable for non-serializable transactions (#747) (by @pauldraper in 5cf4089a for #747) * Fix a | Low | 5/17/2021 |
| v0.22.0 | A new asyncpg release is here. Notable additions include Python 3.9 support, support for recently added PostgreSQL types like `jsonpath`, and last but not least, vastly improved `executemany()` performance. Importantly, `executemany()` is also now _atomic_, which means that either all iterations succeed, or none at all, whereas previously partial results would have remained in place, unless `executemany()` was called in a transaction. There is also the usual assortment of improvement | Low | 2/10/2021 |
| v0.21.0 | Improvements ------------ * Add support for password functions (useful for RDS IAM auth) (#554) (by Harvey Frye in 1d9457f0 for #554) * Add support for connection termination listeners (#525) (by @iomintz in 8141b93c for #525) * Update CI matrix, aarch64 builds (#595) (by @Gelbpunkt in ac6a2fcf for #595) Fixes ----- * Fix possible uninitalized pointer access on unexpected array message data (CVE-2020-17446, by @elprans in 69bcdf5b, reported by @risicle) * Fix | Low | 8/10/2020 |
| v0.20.0 | ## Improvements * Support Python 3.8 (by @1st1 in #504) * Support PgBouncer by sending only a single SYNC message per query (by @fvannee in b043fbd3) ## Bug Fixes * Handle IP values with prefix in "inet" type as `ipaddress.IPvXInterface` (by @elprans in 5a4daf71 for #497) * Close transport if connection times out (by @hexrain in 926f4833 for #468) * Use faster UUID codecs; make UUID decoding/encoding/operations 2-7x faster (by @1st1 in edde3ff4) * Use `loop.s | Low | 11/21/2019 |
| v0.19.0 | Improvements ------------ * Add support for SCRAM-SHA-256 authentication. (by @jkatz in 2d76f50d) * Add PostgreSQL 12 support (by @elprans in 23261532) Bug Fixes --------- * Remove preexec_fn hack from test cluster management (by @elprans in 36ed11d2) * Fix DeprecationWarning in the docstring of copy_from_query() (by @elprans in 482a39ae) * Allow specifying the target version when generating the release log (by @elprans in 43a7b213) * Check for .flake8 after | Low | 10/9/2019 |
| v0.18.2 | Bug Fixes --------- * Revert "Stop treating ReadyForQuery as a universal result indicator" to fix stability regression. (by @elprans in 04b67480) * Correctly ignore all incoming messages after the Terminate message (by @elprans in 787317fb) * Properly cleanup connections closed by remote (by @elprans in 4393a159 for #385) | Low | 11/10/2018 |
| v0.18.1 | Bug Fixes --------- * Fix DSN parsing regression (by @elprans in 8b98e7b4) | Low | 10/31/2018 |
| v0.18.0 | Improvements ------------ * Implement `Record.get()` (by @elprans in 2b93ee55 for #330) * Internal asyncpg errors are now consistently raised as `InternalClientError` (by @elprans in 263de3ff) * Allow mappings as composite type input (by @elprans in eaa2fa1a for #349) * Add `BitString.to_int()` and `BitString.from_int()` (by @percontation in ffd134e8) * Allow 'sslmode' in DSNs (by @percontation in 0304288e) * Add support for specifying multiple host addresses w | Low | 10/30/2018 |
| v0.17.0 | Improvements ------------ Official support for Python 3.7. Bug Fixes --------- * Fix garbage collection of connections and emit a `ResourceWarning` if an unclosed connection is garbage collected. (by @1st1 in d9a236e7 for #323) * Raise a clear error if there's a race in pool intialization. (by @1st1 in 3565ef8c for #320) * Channel names in `Connection.add_listener()` and `Connection.remove_listener()` are now quoted properly. (by @sqwishy in 3e6ade62) * Fixed e | Low | 7/10/2018 |
| v0.16.0 | Behavior Changes ---------------- `Pool.close()` now waits until all acquired connections are released. Hence, the below code will now hang indefinitely: ```python conn = await pool.acquire() await pool.close() ``` Asyncpg will log a warning if `pool.close()` takes over 60 seconds to complete. It is advisable to use `asyncio.wait_for()` to set a timeout. Improvements ------------ * Add support for reading passwords from .pgpass (by @elprans in 55a372fc for #267) * | Low | 6/6/2018 |
| v0.15.0 | Behavior Changes ---------------- asyncpg no longer uses the common statement cache for explicit prepared statements, so `Connection.prepare()` always returns a new prepared statement (by @vangheem in a19ce50f). Bug Fixes --------- * Initialize statement codecs immediately after Prepare (by @elprans in 803c1155 for #241) * Fix server version parsing when it contains trailing data (by @elprans in 05dce25f for #250) | Low | 2/15/2018 |
| v0.14.0 | Backwards Incompatible Changes ------------------------------ asyncpg now reports the server version as x.0.y for PostgreSQL 10.0 and later. This is in alignment with how upstream is interpreting the "minor" version component now. (@elprans in 1fa12fe2) Improvements ------------ * Support timeouts in `Connection.close()` and `Pool.release()` (by @elprans in bdfdd898 for #220) * Invalidate type cache on schema changes affecting statement result. A new `Connection.reload_sche | Low | 12/29/2017 |
| v0.13.0 | ### Backwards Incompatible Changes * Drop support for PostgreSQL 9.1 (by @elprans in eaf298b4) * Remove the deprecated "binary" parameter from `Connection.set_type_codec()` (by @elprans in 9ad6625a) ### New Features * Add support for PostgreSQL 10 (by @elprans) ### Bug Fixes * Document that single fetches can return None (by @khazhyk in 23394c9d) * Fix type introspection being very slow on large databases (by @elprans in e0c44ced for #186) * Fix copy te | Low | 10/20/2017 |
| v0.12.0 | ### New Features * Implement `as_dict()` method for `PostgresMessage`. (by @vitaly-burovoy in 90725f1f) * Add API for receiving log messages `connection.add_log_listener()`. (by @vitaly-burovoy and @1st1 in 1b1893df and f072f883 for #144) * Add support for "tuple" exchange format for codec overrides. (by @elprans in 0453243b and d27dda72) * Implement binary format codec for numeric type. (by @elprans in a5413eb0 for #157) ### Bug Fixes * Fix boundary checks for in | Low | 7/7/2017 |
| v0.11.0 | ### Backwards Incompatible Changes * Make `timeout` param of `executemany()` a keyword-only kwarg. (by @1st1 in bb326fc0) * Prohibit passing non-string instances as text arguments to queries. (by @elprans in ccc5f7a5) * `connect()` and `create_pool()` no longer accept arbitrary keyword arguments for server settings. Use new `server_settings` argument for that. ### New Features * Add support for COPY IN. (by @elprans in 10d95d43 for #123) * Add support for COPY | Low | 5/11/2017 |
| v0.10.1 | ### New features * Add new Connection parameter: `max_cacheable_statement_size`. (by @1st1 in b1f87ebe for #115) ### Bug fixes * Require `command_timeout` argument of `connect()` be greater than 0. (by @1st1 in 7b7ce990) * Fix SSL support in connection pool. (by @elprans in b89fb458 for #119) * Make timeout in connect() consistent. (by @1st1 in 1d8f5cf1 for #117) | Low | 4/6/2017 |
| v0.10.0 | ### New features * Add support for SSL connections. (by @1st1 in 5836a8fc for #25) * Add `max_cached_statement_lifetime` parameter to `asyncpg.connect()`. (by @1st1 in 10955fdd for #76) * Add `max_inactive_connection_lifetime` parameter to `asyncpg.create_pool()`. (by @1st1 in a2935aed) * Expose some of `Connection` methods directly on the Pool object. (by @1st1 in 1b3a847c for #39) * Allow overriding codecs for builtin types on a connection. (by @elprans in 71de129 | Low | 4/4/2017 |
| v0.8.4 | Release v0.8.4 | Low | 1/7/2017 |
| v0.8.3 | Elvis Pranskevichus (9): - Increase pool.acquire timeout in tests to avoid failures on Travis - Silence a few -Wmaybe-uninitialized warnings - Increase test timeouts - Attempt to fix spurious failures of test_auth_reject on Windows - Use ssize_t for buffer sizes consistently - Add infrastructure for multiformat data codecs - Implement text array decoder (#60) - ci: Make sure wheel builds on macOS start from a clean slate (#61) Vitaly Burovoy (3): - Make TYPEMAP be stable and avoid extra endline | Low | 1/4/2017 |
| v0.8.1 | Elvis Pranskevichus (7): - Fix Connection.reset() on read-only connections (#48) - Add compatibility with PostgreSQL server versions 9.1-9.3 - travis: Test on all available PostgreSQL versions - travis: Also build on Python 3.6 - Fix setup.py metadata and README rst issues - ci: Switch to staged release process - travis: Fix documentation deploy on tagged builds (#52) Lele Gaifax (1): - Fix typo in API documentation Yury Selivanov (2): - cython: Make async def coroutines awaitable in cythonize | Low | 12/22/2016 |
| v0.7.0 | Chris Lamb (1): - Fix parsing pg_ctl output in some locales Elvis Pranskevichus (9): - Fix building of wheels on macOS - setup.py: Support --cython-directives properly - Decode arrays as lists, handle arrays of composite types (#33) - Ignore system and dropped attributes in composite types (#43) - Fix handling of CIDR input to "inet" data type (#37) - Implement the Connection.executemany() method (#36) Yury Selivanov (3): - Allow empty Record objects. - cluster: Fix how settings args are passe | Low | 11/17/2016 |
| v0.6.0 | Elvis Pranskevichus (5): Merge pull request #24 from johnkingsley/master Make it possible to override cluster connection parameters Move compilation logic to setup.py Add Windows support (#31) asyncpg v0.6.0 John Kingsley (1): Fixed copy-and-paste error in Line type | Low | 10/20/2016 |
| v0.5.3 | - Fix timestamp codec on 32-bit systems - Allow any non-trivial Container to be passed as an array argument - Fix pool connection failure when a password is present (#16) - Various portability and robustness improvements | Low | 8/5/2016 |
| v0.5.2 | Release v0.5.2 | Low | 7/26/2016 |
