- Notifications
You must be signed in to change notification settings - Fork435
A fast PostgreSQL Database Client Library for Python/asyncio.
License
MagicStack/asyncpg
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
asyncpg is a database interface library designed specifically forPostgreSQL and Python/asyncio. asyncpg is an efficient, clean implementationof PostgreSQL server binary protocol for use with Python'sasyncioframework. You can read more about asyncpg in an introductoryblog post.
asyncpg requires Python 3.9 or later and is supported for PostgreSQLversions 9.5 to 18. Other PostgreSQL versions or other databasesimplementing the PostgreSQL protocolmay work, but are not beingactively tested.
The project documentation can be foundhere.
In our testing asyncpg is, on average,5x faster than psycopg3.

The above results are a geometric mean of benchmarks obtained with PostgreSQLclient driver benchmarking toolbenchin June 2023 (click on the chart to see full details).
asyncpg implements PostgreSQL server protocol natively and exposes itsfeatures directly, as opposed to hiding them behind a generic facadelike 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
asyncpg is available on PyPI. When not using GSSAPI/SSPI authentication ithas no dependencies. Use pip to install:
$ pip install asyncpg
If you need GSSAPI/SSPI authentication, use:
$ pip install 'asyncpg[gssauth]'
For more details, pleasesee the documentation.
importasyncioimportasyncpgasyncdefrun():conn=awaitasyncpg.connect(user='user',password='password',database='database',host='127.0.0.1')values=awaitconn.fetch('SELECT * FROM mytable WHERE id = $1',10, )awaitconn.close()asyncio.run(run())
asyncpg is developed and distributed under the Apache 2.0 license.
About
A fast PostgreSQL Database Client Library for Python/asyncio.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.