Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aio-libs/aiopg
aiopg is a library for accessing a PostgreSQL database from the asyncio
https://github.com/aio-libs/aiopg
asyncio postgresql sqlalchemy
Last synced: 20 days ago
JSON representation
aiopg is a library for accessing a PostgreSQL database from the asyncio
- Host: GitHub
- URL: https://github.com/aio-libs/aiopg
- Owner: aio-libs
- License: bsd-2-clause
- Created: 2014-04-03T09:58:33.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-03-20T17:00:20.000Z (8 months ago)
- Last Synced: 2024-05-23T07:46:55.594Z (5 months ago)
- Topics: asyncio, postgresql, sqlalchemy
- Language: Python
- Homepage: http://aiopg.readthedocs.io
- Size: 1.13 MB
- Stars: 1,380
- Watchers: 39
- Forks: 156
- Open Issues: 72
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.txt
- Contributing: CONTRIBUTING.rst
- License: LICENSE
Awesome Lists containing this project
- awesome-asyncio - aiopg - Library for accessing a PostgreSQL database. (Database Drivers)
- starred-awesome - aiopg - aiopg is a library for accessing a PostgreSQL database from the asyncio (Python)
README
aiopg
=====
.. image:: https://github.com/aio-libs/aiopg/workflows/CI/badge.svg
:target: https://github.com/aio-libs/aiopg/actions?query=workflow%3ACI
.. image:: https://codecov.io/gh/aio-libs/aiopg/branch/master/graph/badge.svg
:target: https://codecov.io/gh/aio-libs/aiopg
.. image:: https://badges.gitter.im/Join%20Chat.svg
:target: https://gitter.im/aio-libs/Lobby
:alt: Chat on Gitter**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
-------.. code:: python
import asyncio
import aiopgdsn = '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
------------------------------------------.. code:: python
import asyncio
from aiopg.sa import create_engine
import sqlalchemy as sametadata = 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()).. _PostgreSQL: http://www.postgresql.org/
.. _asyncio: https://docs.python.org/3/library/asyncio.htmlPlease 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.