Skip to main content

Postgres integration with asyncio.

Project description

https://travis-ci.org/aio-libs/aiopg.svg?branch=master https://coveralls.io/repos/aio-libs/aiopg/badge.svg

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


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)

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:

$ make test

for executing the project’s unittests. See CONTRIBUTING.rst for details on how to set up your environment to run the tests.

CHANGES

0.9.2 (2016-01-31)

  • Make pool.release return asyncio.Future, so we can wait on it in __aexit__ #102

  • Add support for uuid type #103

0.9.1 (2016-01-17)

  • Documentation update #101

0.9.0 (2016-01-14)

  • Add async context managers for transactions #91

  • Support async iterator in ResultProxy #92

  • Add async with for engine #90

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiopg-0.9.2.tar.gz (25.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

aiopg-0.9.2-py3.5.egg (64.2 kB view details)

Uploaded Egg

aiopg-0.9.2-py3-none-any.whl (30.2 kB view details)

Uploaded Python 3

File details

Details for the file aiopg-0.9.2.tar.gz.

File metadata

  • Download URL: aiopg-0.9.2.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiopg-0.9.2.tar.gz
Algorithm Hash digest
SHA256 166c7f8ca40d49219ee815d8441ba720a7ddf44a3584354c83f52c028bd967ce
MD5 6121a45b5303df471c73d9d0e35a6845
BLAKE2b-256 269d8e7f5ddece9a7dd95830657b36a90e97db90384f592fac9f4b07df892cc7

See more details on using hashes here.

File details

Details for the file aiopg-0.9.2-py3.5.egg.

File metadata

  • Download URL: aiopg-0.9.2-py3.5.egg
  • Upload date:
  • Size: 64.2 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiopg-0.9.2-py3.5.egg
Algorithm Hash digest
SHA256 da3115aa1e60bd4a7c10df622deb72c3e32d1af57d4a497aed1afc1f6da21f1c
MD5 8a45de3d280b65676a281e4c79e5b963
BLAKE2b-256 aa278feba8f97872f406f2c39d529caeb071cf473fbd3d04c89e950be140c191

See more details on using hashes here.

File details

Details for the file aiopg-0.9.2-py3-none-any.whl.

File metadata

File hashes

Hashes for aiopg-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1bc256e8b76666d681aa4826d99114cea78c341327b2d2545f6e07837aa42b81
MD5 fcbc79e82f1bcd8de179d8dee0dcb0e3
BLAKE2b-256 60ec45b8d05d57e4c6ddf3aa1fe7f623f901a9c71cffd1776a9641b8f40b16cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page