Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A fast PostgreSQL Database Client Library for Python/asyncio.

License

NotificationsYou must be signed in to change notification settings

MagicStack/asyncpg

Repository files navigation

GitHub Actions status

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.

Documentation

The project documentation can be foundhere.

Performance

In our testing asyncpg is, on average,5x faster than psycopg3.

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

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

Features

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

Installation

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.

Basic Usage

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

License

asyncpg is developed and distributed under the Apache 2.0 license.


[8]ページ先頭

©2009-2025 Movatter.jp