Asyncpg released - PostgreSQL client library for Python / asyncio
At EuroPython 2016, Yuri Selivanov (author of async / await syntax and author of uvloop ) introduced a new high-performance library for asynchronous access to PostgreSQL - asyncpg . Tests demonstrate on average twice as fast speed as psycopg2 (and its asynchronous version - aiopg).
The reason for the high performance is that asyncpg implements the PostgreSQL binary protocol natively, without using abstractions like the DB-API. In addition, this allowed us to obtain an easy-to-use implementation:
asyncpg is available on PyPI. Use to install pip:
PS I left some terms, such as “prepared statement” without translation, and also took the liberty of using English in the text, since I believe that the meticulous translation of technical texts can distort the original meaning or make it difficult to understand. Please forgive me for this.
The reason for the high performance is that asyncpg implements the PostgreSQL binary protocol natively, without using abstractions like the DB-API. In addition, this allowed us to obtain an easy-to-use implementation:
- prepared statements
- scrollable cursors
- partial iteration of query results
- automatic coding and decoding of composite types , arrays and their combination
- intuitive support for custom types
Installation
asyncpg is available on PyPI. Use to install pip:
$ pip install asyncpg
Usage example
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''')
await conn.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
PS I left some terms, such as “prepared statement” without translation, and also took the liberty of using English in the text, since I believe that the meticulous translation of technical texts can distort the original meaning or make it difficult to understand. Please forgive me for this.