Skip to main content
# asyncpgdb

`asyncpgdb` is a Python library that provides an asynchronous database interface built on top of `asyncpg`. One of its unique features is a custom query formatting style that allows you to write parameterized queries using a more readable syntax.

## Installation

You can install `asyncpgdb` using pip:

```bash
pip install asyncpgdb

Features

  • Asynchronous database operations.
  • Connection pooling for efficient resource management.
  • Simplified query execution and result handling.
  • Custom query formatting style for better readability.

Usage

Database Connection

To establish a connection to your PostgreSQL database, create an instance of the Database class:

from asyncpgdb import Database

db = Database(dsn="your_database_dsn_here")
await db.connect()

Executing Queries

You can execute queries using the execute method. The library supports a custom query formatting style that allows you to parameterize your queries using named variables, enclosed in $( ):

query = "SELECT name, age FROM users WHERE name = $(name) AND age > $(age)"
result = await db.execute(query, vars={"name": "John", "age": 30})

# For SELECT queries, you can fetch the results in various formats
rows = await result.fetch_all()

Connection Management

asyncpgdb provides automatic connection management, so you don't need to worry about acquiring and releasing connections manually:

async with db.acquire_connection() as conn:
    # Use the connection for queries within this block
    pass  # Connection is automatically released after this block

Connection Pool

asyncpgdb manages a connection pool by default, so you can specify the minimum and maximum number of connections in the pool when creating a Database instance:

db = Database(dsn="your_database_dsn_here", min_size=2, max_size=10)

Examples

Selecting Data

query = "SELECT name, age FROM users WHERE age > $(age)"
results = await db.execute(query, vars={"age": 30})
users = await results.fetch_all()

Inserting Data

query = "INSERT INTO products (name, price) VALUES ($(name), $(price))"
await db.execute(query, vars={"name": "Widget", "price": 19.99})

Updating Data

query = "UPDATE orders SET status = $(status) WHERE id = $(id)"
await db.execute(query, vars={"status": "shipped", "id": 123})

Documentation

For more details and advanced usage, refer to the documentation.

License

This library is licensed under the MIT License.


Please replace `"your_database_dsn_here"` with your actual database DSN, and ensure that you have the required dependencies installed to use `asyncpgdb`. You can find detailed documentation and usage examples in the official documentation.

Metadata

Release files for asyncpgdb 0.0.23

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asyncpgdb 0.0.23
File Size Uploaded
asyncpgdb-0.0.23.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asyncpgdb 0.0.23
File Interpreter ABI Platform
asyncpgdb-0.0.23-py3-none-any.whl Python 3 none any Details

Total release size: 16.9 kB

Release files / asyncpgdb-0.0.23.tar.gz

Download URL asyncpgdb-0.0.23.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
94e6058093cb06cab58480002765cd1954eda6aeffb7410c013bde4025721fe9
BLAKE2b-256 checksum
How to use checksums
f398fa1f32ac01e763a8827d5885e147ab3241f5f94c0beb5df142a0e76a8111
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.9.13 Darwin/23.0.0

Release files / asyncpgdb-0.0.23-py3-none-any.whl

Download URL asyncpgdb-0.0.23-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4eddaac5a93d8caa650a97072adeb7d701e42000733e8d9a479fef7b9b573416
BLAKE2b-256 checksum
How to use checksums
9da239879f2c9811eaf2ee51081cff571a8a017b292095e86351e8832a905a6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.9.13 Darwin/23.0.0

Release history Release notifications | RSS feed

This release

0.0.23 This release

2 release files

0.0.22

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release 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