Postgres integration with asyncio.
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())
For yield from based code, see the ./examples folder, files with old_style part in their names.
$ make test
for executing the project’s unittests. See CONTRIBUTING.rst for details on how to set up your environment to run the tests.
- Added connection poll recycling logic #373
- Add async with support to .begin_nested() #208
- Fix connection.cancel() #212 #223
- Raise informative error on unexpected connection closing #191
- Added support for python types columns issues #217
- Added support for default values in SA table issues #206
- Add an on_connect callback parameter to pool #141
- Fixed connection to work under both windows and posix based systems #142
- Immediately remove callbacks from a closed file descriptor #139
- Drop Python 3.3 support
- Refactor tests to use dockerized Postgres server #107
- Reduce default pool minsize to 1 #106
- Explicitly enumerate packages in setup.py #85
- Remove expired connections from pool on acquire #116
- Don’t crash when Connection is GC’ed #124
- Use loop.create_future() if available
- Make pool.release return asyncio.Future, so we can wait on it in __aexit__ #102
- Add support for uuid type #103
- Documentation update #101
- Add async context managers for transactions #91
- Support async iterator in ResultProxy #92
- Add async with for engine #90
- 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
- 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().
- Accept dict, list, tuple, named and positional parameters in SAConnection.execute()
- Minor release, fixes a bug that leaves connection in broken state after cursor.execute() failure.
- Fix a bug for processing transactions in line.
- 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).
- make cursor iterable
- update docs
- 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
- change signature to cursor.execute(operation, parameters=None) to follow psycopg2 convention.
- Forward arguments to cursor constructor for pooled connections.
- Allow executing SQLAlchemy DDL statements.
- Fix bug with race conditions on acquiring/releasing connections from pool.
- Fix bug in connection pool.
- Fix bug with passing parameters into SAConnection.execute when executing raw SQL expression.
- Close connection with invalid transaction status on returning to pool.
- Implemented optional support for sqlalchemy functional sql layer.
- Implemented plain connections: connect, Connection, Cursor.
- Implemented database pools: create_pool and Pool.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|aiopg-0.13.1-py3-none-any.whl (32.6 kB) Copy SHA256 Checksum SHA256||py3||Wheel||Sep 10, 2017|
|aiopg-0.13.1.tar.gz (27.0 kB) Copy SHA256 Checksum SHA256||–||Source||Sep 10, 2017|