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 cur: 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 from sqlalchemy.schema import CreateTable 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))) @asyncio.coroutine def go(): engine = yield from create_engine(user='aiopg', database='aiopg', host='127.0.0.1', password='passwd') with (yield from engine) as conn: yield from conn.execute(CreateTable(tbl)) yield from conn.execute(tbl.insert().values(val='abc')) res = yield from conn.execute(tbl.select()) for row in res: print(row.id, row.val) asyncio.get_event_loop().run_until_complete(go())
For yield from based code see ./examples folder, files with old_style part in their names.
Please use:
$ python3 runtests.py
for executing the project’s unittests. See CONTRIBUTING.rst for details on how to set up your environment to run the tests.
CHANGES
0.8.0 (2015-12-31)
Add PostgreSQL notification support #58
Support pools with unlimited size #59
Cancel current DB operation on asyncio timeout #66
Add async with support for Pool, Connection, Cursor #88
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-0.8.0.tar.gz
.
File metadata
- Download URL: aiopg-0.8.0.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a795881900722862d5f2e5cf571f7a89a341abd1ddc3faed5518d2daee95057 |
|
MD5 | b4c6810fb0f6f57cff31d6d824c0c42a |
|
BLAKE2b-256 | f81c1b25169483bc3df12e31aee9a36f9c233f16cab976dbce86983b97f1f7e8 |
File details
Details for the file aiopg-0.8.0-py3-none-any.whl
.
File metadata
- Download URL: aiopg-0.8.0-py3-none-any.whl
- Upload date:
- Size: 29.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf7749d9bc9e57b8c3a667404bf1299a4ddbeed1954cca4d74aba37047ce75e3 |
|
MD5 | 4e79f380b69c4dd869da054ddc6da53e |
|
BLAKE2b-256 | 99b905c6fc21cc52884ce4c900fd32346223663e9d7e8f03e6505fd5bba0f4f9 |