Postgres integration with asyncio.
Project description
aiopg is a library for accessing a PostgreSQL database from the asyncio (PEP-3156/tulip) framework. It wraps asynchronous features of the Psycopg database driver.
Example
import asyncio
import aiopg
dsn = 'dbname=aiopg user=aiopg password=passwd host=127.0.0.1'
async def go():
pool = await aiopg.create_pool(dsn)
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
ret = []
async for row in cur:
ret.append(row)
assert ret == [(1,)]
loop = asyncio.get_event_loop()
loop.run_until_complete(go())
Example of SQLAlchemy optional integration
import asyncio
from aiopg.sa import create_engine
import sqlalchemy as sa
metadata = sa.MetaData()
tbl = sa.Table('tbl', metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('val', sa.String(255)))
async def create_table(engine):
async with engine.acquire() as conn:
await conn.execute('DROP TABLE IF EXISTS tbl')
await conn.execute('''CREATE TABLE tbl (
id serial PRIMARY KEY,
val varchar(255))''')
async def go():
async with create_engine(user='aiopg',
database='aiopg',
host='127.0.0.1',
password='passwd') as engine:
async with engine.acquire() as conn:
await conn.execute(tbl.insert().values(val='abc'))
async for row in conn.execute(tbl.select()):
print(row.id, row.val)
loop = asyncio.get_event_loop()
loop.run_until_complete(go())
Please use:
$ make test
for executing the project’s unittests. See https://aiopg.readthedocs.io/en/stable/contributing.html for details on how to set up your environment to run the tests.
Changelog
1.2.0b0 (2020-12-15)
Implement timeout on acquiring connection from pool #766
1.1.0 (2020-12-10)
1.1.0b2 (2020-12-09)
Added missing slots to context managers #763
1.1.0b1 (2020-12-07)
1.0.0 (2019-09-20)
Removal of an asynchronous call in favor of issues # 550
Big editing of documentation and minor bugs #534
0.16.0 (2019-01-25)
0.15.0 (2018-08-14)
Support Python 3.7 #437
0.14.0 (2018-05-10)
Add get_dialect func to have ability to pass json_serializer #451
0.13.2 (2018-01-03)
0.13.1 (2017-09-10)
Added connection poll recycling logic #373
0.13.0 (2016-12-02)
0.12.0 (2016-10-09)
0.11.0 (2016-09-12)
Immediately remove callbacks from a closed file descriptor #139
Drop Python 3.3 support
0.10.0 (2016-07-16)
0.9.2 (2016-01-31)
0.9.1 (2016-01-17)
Documentation update #101
0.9.0 (2016-01-14)
0.8.0 (2015-12-31)
0.7.0 (2015-04-22)
Get rid of resource leak on connection failure.
Report ResourceWarning on non-closed connections.
Deprecate iteration protocol support in cursor and ResultProxy.
Release sa connection to pool on connection.close().
0.6.0 (2015-02-03)
Accept dict, list, tuple, named and positional parameters in SAConnection.execute()
0.5.2 (2014-12-08)
Minor release, fixes a bug that leaves connection in broken state after cursor.execute() failure.
0.5.1 (2014-10-31)
Fix a bug for processing transactions in line.
0.5.0 (2014-10-31)
Add .terminate() to Pool and Engine
Reimplement connection pool (now pool size cannot be greater than pool.maxsize)
Add .close() and .wait_closed() to Pool and Engine
Add minsize, maxsize, size and freesize properties to sa.Engine
Support echo parameter for logging executed SQL commands
Connection.close() is not a coroutine (but we keep backward compatibility).
0.4.1 (2014-10-02)
make cursor iterable
update docs
0.4.0 (2014-10-02)
add timeouts for database operations.
Autoregister psycopg2 support for json data type.
Support JSON in aiopg.sa
Support ARRAY in aiopg.sa
Autoregister hstore support if present in connected DB
Support HSTORE in aiopg.sa
0.3.2 (2014-07-07)
change signature to cursor.execute(operation, parameters=None) to follow psycopg2 convention.
0.3.1 (2014-07-04)
Forward arguments to cursor constructor for pooled connections.
0.3.0 (2014-06-22)
Allow executing SQLAlchemy DDL statements.
Fix bug with race conditions on acquiring/releasing connections from pool.
0.2.3 (2014-06-12)
Fix bug in connection pool.
0.2.2 (2014-06-07)
Fix bug with passing parameters into SAConnection.execute when executing raw SQL expression.
0.2.1 (2014-05-08)
Close connection with invalid transaction status on returning to pool.
0.2.0 (2014-05-04)
Implemented optional support for sqlalchemy functional sql layer.
0.1.0 (2014-04-06)
Implemented plain connections: connect, Connection, Cursor.
Implemented database pools: create_pool and Pool.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aiopg-1.2.0b0.tar.gz
.
File metadata
- Download URL: aiopg-1.2.0b0.tar.gz
- Upload date:
- Size: 33.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8ecfddfbc026121163c71a67a0552de70508cf6e76165720abd9b1a4ad62342 |
|
MD5 | a33b471b2bacddc9c4426d2dd7c0b5bc |
|
BLAKE2b-256 | 1ea1057987562c2fc0c70d72ebc8ef4b1319a36340342cb34cdcda03e4941dd0 |
File details
Details for the file aiopg-1.2.0b0-py3-none-any.whl
.
File metadata
- Download URL: aiopg-1.2.0b0-py3-none-any.whl
- Upload date:
- Size: 33.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d2a616ef61569d3daca2c59a82d36d64869c35c7ba26e69c226789b8fdc10c1 |
|
MD5 | 5218ae663abd48dc796ab54b1ec780e1 |
|
BLAKE2b-256 | 2f3c663ee0125a17c0841670ccee67d2f7bb89c98c593c0a7f3e6ea101ef041b |