Skip to main content

pg-promise like wrapper for asyncpg

Project description

AsyncPGPromise

Motivation

The creation of AsyncPGPromise was primarily driven by an aspiration to bring the clean API and named arguments support, common in Node.js' `pg-promise``, to the Python ecosystem. The lack of such an approach in Python became more pronounced upon transitioning from Node.js, sparking the motivation to develop a solution. With Python's ultra-fast writing mold being a major encouraging factor, this tiny wrapper, AsyncPGPromise, was brought into existence to fill this gap and to provide a sleek and efficient means of handling PostgreSQL database operations.

Features

  • Simplicity: By using named arguments in your SQL queries, you can keep your code clean and readable.
  • Flexibility: All the power of the asyncpg library is still at your fingertips, with additional convenience provided by AsyncPGPromise.

Installation

pip install asyncpgpromise

Getting Started

You can create a new AsyncPGPromise instance with an existing asyncpg connection object:

from asyncpgpromise import AsyncPGPromise
import asyncpg

# First create an asyncpg connection
conn = await asyncpg.connect(user='user', password='password', database='database', host='127.0.0.1')

# Then pass it to AsyncPGPromise
pg = AsyncPGPromise(conn)

Usage

Querying

You can perform SQL queries with named arguments:

rows = await pg.query('SELECT * FROM users WHERE name = $name', name='John')

The query method returns a list of dictionaries, each representing a row from the SQL query.

Fetching One Row

If you're only expecting a single row result, you can use the one method:

row = await pg.one('SELECT * FROM users WHERE id = $id', id=1)

Note

This is a new project and may still have some rough edges. Contributions are very welcome!

To-Do

  • Parsing of fields with JSON data

License

AsyncPGPromise is available under the MIT license. See the LICENSE file for more info.

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

asyncpgpromise-0.1.4.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

asyncpgpromise-0.1.4-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file asyncpgpromise-0.1.4.tar.gz.

File metadata

  • Download URL: asyncpgpromise-0.1.4.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for asyncpgpromise-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f751711a0da6722abc3eea5203608dbaa762b1bebd9f8c3a8767f85d61beaa0d
MD5 ad31ea725d5d3b10062755ecd2921d39
BLAKE2b-256 6a7767c941231354d5409cfa7f3c00e80a9eb56c64de61882fb0184cae519d61

See more details on using hashes here.

File details

Details for the file asyncpgpromise-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for asyncpgpromise-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6d886520574bcbb050d5f8f123b78e4dab93816dbf8d139a1c4515b8b6934fbb
MD5 aecc0a59d3e3886810aca3dc2e9ee4bf
BLAKE2b-256 c6b5477faa312d801748dd395a891cd60d79fc76b1b953d24253a059aa5815b5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page