allure-db-client
A tiny helper around psycopg for running PostgreSQL queries in tests and utilities, with optional Allure reporting of executed SQL and results.
The package exposes two clients:
- DBClient — sync client (psycopg Connection)
- AsyncDBClient — async client (psycopg AsyncConnection)
Both clients support a small, convenient API for common cases and can be used as context managers to automatically open/close connections.
Requirements
- Python 3.11
- PostgreSQL accessible via a connection string
Installation
Install from PyPI:
pip install allure-db-client
Or with Poetry:
poetry add allure-db-client
Connection string
Use a standard psycopg connection URI, for example:
postgresql://USER:PASSWORD@HOST:PORT/DBNAME
Example for local Dockerized Postgres:
postgresql://postgres:postgres@localhost:5432/postgres
Quick start (sync)
from allure_db_client import DBClient
conn_str = "postgresql://postgres:postgres@localhost:5432/postgres"
# with_allure=True will attach query and result to Allure report (if Allure is used in your tests)
with DBClient(connection_string=conn_str, with_allure=True) as db:
# read examples
rows = db.select_all("SELECT 1 AS one, 2 AS two")
first_row = db.get_first_row("SELECT 42") # -> (42,)
first_value = db.get_first_value("SELECT 'hi'") # -> 'hi'
ids = db.get_list("SELECT generate_series(1, 3)") # -> [1, 2, 3]
# get_dict expects first two columns to be key/value
pairs = db.get_dict("SELECT 1, 'a' UNION ALL SELECT 2, 'b'") # -> {1: 'a', 2: 'b'}
# write example
db.execute("CREATE TEMP TABLE t(id int)")
db.execute("INSERT INTO t(id) VALUES (%(id)s)", params={"id": 7})
Quick start (async)
import asyncio
from allure_db_client import AsyncDBClient
conn_str = "postgresql://postgres:postgres@localhost:5432/postgres"
async def main():
async with AsyncDBClient(connection_string=conn_str, with_allure=True) as db:
rows = await db.select_all("SELECT 1")
value = await db.get_first_value("SELECT 'ok'")
await db.execute("CREATE TEMP TABLE t(id int)")
asyncio.run(main())
API overview
- select_all(query, params=None) -> list[tuple]
- get_first_row(query, params=None) -> tuple | None
- get_first_value(query, params=None) -> Any | None
- get_list(query, params=None) -> list[Any]
- get_dict(query, params=None) -> dict[Any, Any] | None
- execute(query, params=None) -> None
Notes:
- params is a dict passed to psycopg; use named placeholders like %(name)s in SQL.
- If with_allure=True, each call attaches the SQL and (for read queries) the result to the Allure report.
Using with Allure
The clients can attach SQL and results to Allure steps when with_allure=True. Add allure-pytest to your test environment and run tests with Allure:
pip install allure-pytest
pytest --alluredir=./allure-results
Then open the report with your Allure CLI.
Running tests locally
This repository includes a minimal test setup using Docker. It will start Postgres and run tests against it.
Prerequisites:
- Docker and docker-compose
Commands (from project root):
cd tests
docker compose up --build --abort-on-container-exit
The tests container will set PG_CONNECTION_STRING for the clients automatically, as defined in tests/docker-compose.yml.
License
MIT — see LICENSE.
Metadata
Release files for allure-db-client 25.298
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| allure_db_client-25.298.tar.gz | 5.1 kB | Without provenance | Details for allure_db_client-25.298.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| allure_db_client-25.298-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for allure_db_client-25.298-py2.py3-none-any.whl |
Total release size: 13.3 kB
Release files / allure_db_client-25.298.tar.gz
| Download URL | allure_db_client-25.298.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
090345f3e07cbbe34c96358c256120e56953f722130ec77fee861063d99c6116
|
|
BLAKE2b-256 checksum How to use checksums |
81110db6a2fcfddebc34f74ddca40e07d3a25ff229cd09f47a7f8a98e45d161a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.13.7 Linux/6.11.0-1018-azure
|
Release files / allure_db_client-25.298-py2.py3-none-any.whl
| Download URL | allure_db_client-25.298-py2.py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
042163ba18beaed6f92849aacfc6036f70ca4ad387a9095170e0b1011f14e895
|
|
BLAKE2b-256 checksum How to use checksums |
d3cb4d6c6567adfb05488562b9a659df6125b24094cc7becca35af702614e8df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.13.7 Linux/6.11.0-1018-azure
|
Security for allure-db-client 25.298
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.