Skip to main content

An asyncio PostgreSQL driver

Reason this release was yanked:

official asyncpg 0.28 release

Project description

GitHub Actions status https://img.shields.io/pypi/v/asyncpg.svg

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.

asyncpg requires Python 3.7 or later and is supported for PostgreSQL versions 9.5 to 15. Older 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.

Performance

In our testing asyncpg is, on average, 3x faster than psycopg2 (and its asyncio variant – aiopg).

https://raw.githubusercontent.com/MagicStack/asyncpg/master/performance.png

The above results are a geometric mean of benchmarks obtained with PostgreSQL client driver benchmarking toolbench in November 2020 (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 and has no dependencies. Use pip to install:

$ pip install asyncpg

Basic Usage

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()

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

License

asyncpg is developed and distributed under the Apache 2.0 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

asyncpg_dev-0.28.0.dev1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

asyncpg_dev-0.28.0.dev1-cp311-cp311-macosx_10_9_universal2.whl (1.1 MB view details)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file asyncpg_dev-0.28.0.dev1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for asyncpg_dev-0.28.0.dev1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 091f2f44d01771677d0ca77dfaa0e7dd37eb8840d3cdde8897030d408b5b4f44
MD5 85179778c2ff335258157e81a5c3d555
BLAKE2b-256 1f9815328953e385a783d094eb6666a29d70562522aacdf8f02d5df386b96225

See more details on using hashes here.

File details

Details for the file asyncpg_dev-0.28.0.dev1-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for asyncpg_dev-0.28.0.dev1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 20849420cfc1fddd4be43b63f07f2002f3816b8d37a0f3a09aaeeba0f7fb3e87
MD5 283c113a677fdb96beb9e1f1cf7252c5
BLAKE2b-256 0e63e1fe59c12ff5e91661404ed2c70c545c02e83217830ebb46c6e289c53af4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page