📜 ⬆️ ⬇️

Asyncpg released - PostgreSQL client library for Python / asyncio

At the EuroPython 2016 conference, Yuri Selivanov (by async / await-syntax and by uvloop ) introduced a new high-performance library for asynchronous access to PostgreSQL - asyncpg . Tests demonstrate an average twice as fast 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 DB-API. In addition, it is possible to get an easy-to-use implementation:



')

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 Some terms, such as the “prepared statement,” I left without translation, and also took it upon myself to use Anglicism in the text, as I believe that the meticulous translation of technical texts can distort the original meaning or impede its understanding. Forgive me for this.

Source: https://habr.com/ru/post/306196/


All Articles