No project description provided
Project description
# 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asyncpgdb-0.0.15.tar.gz.
File metadata
- Download URL: asyncpgdb-0.0.15.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.9.13 Darwin/23.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a7d9a3b4340dcd6e7206875b4f8303e969440c821e31b6c05db0d182273a161
|
|
| MD5 |
039f15d7b20fd1bbcd1fac7e67cca51d
|
|
| BLAKE2b-256 |
467a7de26fca976cf01c970658468f1e097a3e7151da8125968b5a37ca321f92
|
File details
Details for the file asyncpgdb-0.0.15-py3-none-any.whl.
File metadata
- Download URL: asyncpgdb-0.0.15-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.9.13 Darwin/23.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b65509c511955dbbdd199cea25fe8679a32f21d37909f7e513aa519cc8a67289
|
|
| MD5 |
55a939969ed7419f777772ef6b927d07
|
|
| BLAKE2b-256 |
1f56e473cd67f36119626d3002627e9121605c94f78192b3eb3d14f7f8725bc0
|