Skip to main content

TravisCI Build Status Coverage Status Requirements Status


Utilities for Asyncpg.

How to install

pip install asyncpg-utils

How to Use

Python code:

import asyncio
from datetime import date

from asyncpg_utils.databases import Database

loop = asyncio.get_event_loop()
database = Database('postgresql://postgres:postgres@localhost/asyncpg-utils')


async def create_table():
    conn = await database.get_connection()
    await conn.execute(
        """
        CREATE TABLE IF NOT EXISTS users(
            id serial PRIMARY KEY,
            name text,
            dob date
        )
        """
    )
    await conn.close()
    return True


async def insert_row(data):
    return await database.insert('users', data)


async def query_all():
    return await database.query(
        """
        SELECT * FROM users
        """
    )


async def query_one():
    return await database.query_one(
        """
        SELECT * FROM users
        WHERE name = $1
        """,
        'Jane Doe'
    )


async def main():
    print('create_table users, {!r}'.format(await create_table()))
    print('insert row, {!r}'.format(await insert_row({'name': 'John Doe', 'dob': date(2000, 1, 1)})))
    print('insert row, {!r}'.format(await insert_row({'name': 'Jane Doe', 'dob': date(2000, 1, 1)})))
    print('query all results, {!r}'.format(await query_all()))
    print('query one result, {!r}'.format(await query_one()))

loop.run_until_complete(main())

Code executed:

create_table users, True
insert row, <Record id=1 name='John Doe' dob=datetime.date(2000, 1, 1)>
insert row, <Record id=2 name='Jane Doe' dob=datetime.date(2000, 1, 1)>
query all results, [<Record id=1 name='John Doe' dob=datetime.date(2000, 1, 1)>, <Record id=2 name='Jane Doe' dob=datetime.date(2000, 1, 1)>]
query one result, <Record id=2 name='Jane Doe' dob=datetime.date(2000, 1, 1)>

Check https://github.com/allisson/asyncpg-utils/tree/master/examples for more code examples.

Download files

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

Source Distribution

asyncpg-utils-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

asyncpg_utils-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file asyncpg-utils-0.1.0.tar.gz.

File metadata

  • Download URL: asyncpg-utils-0.1.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for asyncpg-utils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7e69665afa63bd847c8cd5e4dc2a85fed80606884bd4e0029cd9ea55502f6f9b
MD5 b92069eee46e21f30f4e1ec9ebd48ea6
BLAKE2b-256 30458f51841e323f7caef7226a171e284a61cc3b5922d51a8107f3edd0bc9f44

See more details on using hashes here.

File details

Details for the file asyncpg_utils-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for asyncpg_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7932e5209aebcba6245f69e3dbde31e7ccacf31b841476b332216ac822b5939c
MD5 bc39a2a44874b3427d2e7b5c318215a8
BLAKE2b-256 baf1b7c08d8e3604e473db19e5e9efb29732f512d1d0c5bbc87d032c28adc1d3

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page