Skip to main content

An asyncio PostgreSQL driver

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.6 or later and is supported for PostgreSQL versions 9.5 to 13. 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 Distribution

asyncpg-0.24.0.tar.gz (787.5 kB view details)

Uploaded Source

Built Distributions

asyncpg-0.24.0-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

asyncpg-0.24.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

asyncpg-0.24.0-cp310-cp310-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

asyncpg-0.24.0-cp39-cp39-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

asyncpg-0.24.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

asyncpg-0.24.0-cp39-cp39-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

asyncpg-0.24.0-cp38-cp38-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

asyncpg-0.24.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

asyncpg-0.24.0-cp38-cp38-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

asyncpg-0.24.0-cp37-cp37m-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.7m Windows x86-64

asyncpg-0.24.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

asyncpg-0.24.0-cp37-cp37m-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

Details for the file asyncpg-0.24.0.tar.gz.

File metadata

  • Download URL: asyncpg-0.24.0.tar.gz
  • Upload date:
  • Size: 787.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for asyncpg-0.24.0.tar.gz
Algorithm Hash digest
SHA256 dd2fa063c3344823487d9ddccb40802f02622ddf8bf8a6cc53885ee7a2c1c0c6
MD5 8cbc95eb340f867f34c2d340779380f6
BLAKE2b-256 ba29cca39b99164d9e99a2b30c207e1a8fb682d062b39cef0f214a293bba113c

See more details on using hashes here.

File details

Details for the file asyncpg-0.24.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: asyncpg-0.24.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for asyncpg-0.24.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8ff5073d4b654e34bd5eaadc01dc4d68b8a9609084d835acd364cd934190a08d
MD5 c13c50b6384bc2a4ba1271e29c2237d1
BLAKE2b-256 4d9a2965aaec1568e519c89314ccb5c0d1f981deb5ed24e4938b8d9617021f4b

See more details on using hashes here.

File details

Details for the file asyncpg-0.24.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for asyncpg-0.24.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a7095890c96ba36f9f668eb552bb020dddb44f8e73e932f8573efc613ee83843
MD5 cfe9b0647d6aae3232257bc75207dd26
BLAKE2b-256 7349b3bfdcaac7168bf0f3fb5528ecb959e8b3d15dc634b4408aa094d00be54a

See more details on using hashes here.

File details

Details for the file asyncpg-0.24.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: asyncpg-0.24.0-cp310-cp310-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.10, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for asyncpg-0.24.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c4fc0205fe4ddd5aeb3dfdc0f7bafd43411181e1f5650189608e5971cceacff1
MD5 2546e35e3677519402ce97423b00d37a
BLAKE2b-256 6c0d332a2d3e6c1906420483912d94eda4ae97010d039497c3a1362493d43bd5

See more details on using hashes here.

File details

Details for the file asyncpg-0.24.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: asyncpg-0.24.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for asyncpg-0.24.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a738f4807c853623d3f93f0fea11f61be6b0e5ca16ea8aeb42c2c7ee742aa853
MD5 4b180fefa88997ef1fc288046cdc4510
BLAKE2b-256 fca762ebc193e65bf5b732cad2906cafa9c9e07575b2c35c7366b5db51203dee

See more details on using hashes here.

File details

Details for the file asyncpg-0.24.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for asyncpg-0.24.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 556b0e92e2b75dc028b3c4bc9bd5162ddf0053b856437cf1f04c97f9c6837d03
MD5 6e0ec00632a7aeaee59f53fd512ca570
BLAKE2b-256 d47d551b8af310d4e2e94c941247c48a0df41ab5db490f8a1f208bc2dc0a71d4

See more details on using hashes here.

File details

Details for the file asyncpg-0.24.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: asyncpg-0.24.0-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for asyncpg-0.24.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a458fc69051fbb67d995fdda46d75a012b5d6200f91e17d23d4751482640ed4c
MD5 be2b050e861f3daa777399f88f70bf7c
BLAKE2b-256 fcc3f517553ef975e96b0931ed180b3057fd060982941cfd9f8d42acdceca1ee

See more details on using hashes here.

File details

Details for the file asyncpg-0.24.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: asyncpg-0.24.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for asyncpg-0.24.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 129d501f3d30616afd51eb8d3142ef51ba05374256bd5834cec3ef4956a9b317
MD5 cd7247481056b857191e4bb5a6c8c570
BLAKE2b-256 ba4df3a0282c01f300bdea95b37c701d066973e7441f8a9d5d95481b33afeb7d

See more details on using hashes here.

File details

Details for the file asyncpg-0.24.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for asyncpg-0.24.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 eed43abc6ccf1dc02e0d0efc06ce46a411362f3358847c6b0ec9a43426f91ece
MD5 8e594b4cb5618c99bedd6b9ac6bc0ec6
BLAKE2b-256 31f9a9f5320296f75d2624592823a78779c24d6096bf9d3623134fb3de6ea83d

See more details on using hashes here.

File details

Details for the file asyncpg-0.24.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: asyncpg-0.24.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for asyncpg-0.24.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 29ef6ae0a617fc13cc2ac5dc8e9b367bb83cba220614b437af9b67766f4b6b20
MD5 6e7fa04ef8df565d22d88bf6ff6b2bf1
BLAKE2b-256 3148efbff357a8ee7a3b25a2d3d421b36dc4ca6260bfef0abc980936c20bd9f4

See more details on using hashes here.

File details

Details for the file asyncpg-0.24.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: asyncpg-0.24.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for asyncpg-0.24.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 41704c561d354bef01353835a7846e5606faabbeb846214dfcf666cf53319f18
MD5 953018f5a2e512ed8669afb4633adbeb
BLAKE2b-256 d1f7afe99ec1f75efe79976d11bbdc9d06feac7622d0a226bb80e529374ab8ad

See more details on using hashes here.

File details

Details for the file asyncpg-0.24.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for asyncpg-0.24.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 ddffcb85227bf39cd1bedd4603e0082b243cf3b14ced64dce506a15b05232b83
MD5 e028bfd9e3848363fc922bae9bdd36b4
BLAKE2b-256 eafed7083bef979ac5e0a27f7c432f36d166d40b76141caddddd8a3a2e0798bc

See more details on using hashes here.

File details

Details for the file asyncpg-0.24.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: asyncpg-0.24.0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for asyncpg-0.24.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e36c6806883786b19551bb70a4882561f31135dc8105a59662e0376cf5b2cbc5
MD5 a94f6310e09dd4b9d05919e050305561
BLAKE2b-256 545ce6b63eafdab6054867e4e2c8bc399cb8f370cb9835856e1acc8e79dc450b

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