A fast Postgres client library for Python
Project description
fastpg
A fast Postgres client library for Python.
The only dependency for fastpg is asyncpg, and the api wrapper is very similar to the api provided by the databases package.
Installation
$ pip install fastpg
Quickstart
from fastpg import Database
database = Database("postgresql://username:password@localhost:5432/postgres")
await database.connect()
# Execute a query
query = """
create table high_scores (
id uuid primary key default gen_random_uuid(),
name varchar(100) not null,
score integer not null
)
"""
await database.execute(query)
# Execute many queries
query = "insert into high_scores (name, score) values (:name, :score)"
values = [
{"name": "George", "score": 43},
{"name": "Jess", "score": 67},
{"name": "Kevin", "score": 30}
]
await database.execute_many(query, values)
# Fetch many rows
query = "select * from high_scores"
records = await database.fetch_many(query)
assert(len(records) == 3)
# Fetch a row
query = "select * from high_scores where name = :name"
values = {"name": "George"}
record = await database.fetch_one(query, values)
assert(record.score == 43)
# Fetch a value
query = "select name from high_scores where score = :score"
values = {"score": 30}
value = await database.fetch_val(query, values)
assert(value == "Kevin")
# Copy records to a table (via Postgres COPY)
await database.copy_records_to_table(
"high_scores",
records=[("Mav", 200), ("Connor", 134)],
columns=["name", "score"]
)
# Work with individual connections
async with database.connection() as connection:
...
# Create a transaction
async with connection.transaction():
...
await database.disconnect()
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
fastpg-0.0.6.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file fastpg-0.0.6.tar.gz
.
File metadata
- Download URL: fastpg-0.0.6.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.23.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91127b92d7098803e543b77d1cbb76946e6360845e3064e7a0fbb0cde005b7b2 |
|
MD5 | 3fda90dba50505d65f6995dca54f8719 |
|
BLAKE2b-256 | 977fcc61050507f544a9e2fa80843f3f70c56ab1479afa5876a43a2f31aa2d88 |
File details
Details for the file fastpg-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: fastpg-0.0.6-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.23.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13251d255ad176270ad274d551e595d98577def68516c913c0205e07e2e28f44 |
|
MD5 | 227bc8f5dcc4acfcf65a5ccbf3d70ae8 |
|
BLAKE2b-256 | 4aa8e42d373d0c856bed073c509fddcfb590c4ebf18fa3d15c232d9e6bd3909f |