Skip to main content

No project description provided

Project description

# asyncpgdb

`asyncpgdb` is a Python library that provides an asynchronous database interface built on top of `asyncpg`. It simplifies database operations by offering a high-level abstraction for executing queries and managing database connections.

## 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.

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:

query = "SELECT * FROM your_table"
result = await db.execute(query)

# 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 > $1"
results = await db.execute(query, vars={"age": 30})
users = await results.fetch_all()

Inserting Data

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

Updating Data

query = "UPDATE orders SET status = $1 WHERE id = $2"
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


Download files

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

Source Distribution

asyncpgdb-0.0.8.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

asyncpgdb-0.0.8-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file asyncpgdb-0.0.8.tar.gz.

File metadata

  • Download URL: asyncpgdb-0.0.8.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.9.13 Darwin/22.6.0

File hashes

Hashes for asyncpgdb-0.0.8.tar.gz
Algorithm Hash digest
SHA256 2ef1fa1ffc6028ad7984bf3c7bcc04e3024c239a259e4eecb4ca8b36ad4ca6cb
MD5 3e66b3ee7216d833ddbecfe0d67dff2b
BLAKE2b-256 471a306d026478d56327db049cdd250ebb3cfa6e62a895916ef8aaab7647be76

See more details on using hashes here.

File details

Details for the file asyncpgdb-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: asyncpgdb-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.9.13 Darwin/22.6.0

File hashes

Hashes for asyncpgdb-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 8bc6f3a569d0fa7b9d2da50be6532c27db40bfe0356bd36bd6f9e8e3485ddee0
MD5 ecafe3ea059b6645ecce62cfbf42c11e
BLAKE2b-256 807cb8eeffe9b222361d62ca53129664a6186d04343bc196e3d72a567ad8bbcf

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