buildpg
Query building for the postgresql prepared statements and asyncpg.
What it is and what it does
buildpg is a query builder that translates Python expressions into PostgreSQL prepared statements with parameter binding. It accepts named placeholders (`:foo`, `:bar`) in SQL strings and replaces them with positional parameters (`$1`, `$2`) suitable for asyncpg, while collecting the parameter values into a list. It also provides a `V()` wrapper for SQL identifiers and constants, allowing you to build complex WHERE clauses using Python operators (`&` for AND, `|` for OR, `==` for equality, etc.) and SQL functions like `funcs.count()`, `funcs.upper()`, and `funcs.position()`.
The package includes an optional asyncpg integration layer that wraps pool and connection methods with `*_b` variants (e.g., `fetch_b`, `fetchval_b`, `execute_b`) that accept buildpg-style named parameters and handle the rendering internally. It has no external runtime dependencies and installs as a pure Python wheel. However, the project is no longer maintained—the last release was in March 2022 and the repository has seen no commits since July 2023.
Use it for:
- Build parameterized SELECT queries with dynamic WHERE clauses by combining V() objects with Python operators instead of string concatenation.
- Insert multiple rows using the Values() helper to generate column names and placeholders from keyword arguments.
- Construct complex conditionals programmatically—add AND/OR conditions only when certain flags are true, avoiding manual SQL string building.
- Wrap asyncpg pool operations to accept named parameters directly without manually calling render() before each query.
- Generate SQL with PostgreSQL-specific operators (contains @>, overlap &&, text search @@) using Python method calls on V() objects.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
buildpg constructs PostgreSQL prepared statements with named parameter substitution and asyncpg integration, supporting complex WHERE clauses, value sets, and SQL operators via Python expressions.
Yes, if you are using asyncpg and want to avoid manual string concatenation for parameterized queries, and you accept the maintenance risk. The package is stable and has no known vulnerabilities, but it is abandoned and will not adapt to breaking changes in asyncpg or Python. Use it for new projects only if you are comfortable pinning asyncpg and Python versions, or if you plan to fork and maintain it yourself.
Install
buildpg on PyPI
pip
pip install buildpguv
uv add buildpgpoetry
poetry add buildpgInstalling buildpg
Before you install
Low install friction with no runtime dependencies. However, the package is abandoned—last release was 2022-03-01 and no commits since 2023-07-20. It remains functional for Python 3.7–3.9 but will not receive updates for breaking changes in asyncpg or Python itself.
License in practice
MIT license is permissive; you may use, modify, and distribute buildpg freely in proprietary or open-source projects with minimal restrictions.
Quickstart
from buildpg import render, V
sql, params = render('select * from mytable where x=:foo', foo=123)
# Returns: ('select * from mytable where x=$1', [123])
# With asyncpg wrapper:
import asyncio
from buildpg import asyncpg
async def query():
async with asyncpg.create_pool_b('postgres://localhost/db') as pool:
result = await pool.fetchval_b('select count(*) from t where id=:id', id=42)
Requires asyncpg to be installed separately if using the asyncpg wrapper methods; PostgreSQL server required for actual query execution.
Verify before relying
- Whether the package remains compatible with recent asyncpg versions (last tested with versions from early 2022).
- Whether Python 3.10+ support is confirmed despite classifiers listing only up to 3.9.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 1,627 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 103,200/month — #12,823 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: buildpg-0.4-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
asyncpgasyncpg is an asyncio-native PostgreSQL client…
permissive · top 1,000 on PyPI
pgsanityPgSanity validates PostgreSQL SQL syntax by…
permissive · top 15,000 on PyPI
queriesQueries is a simplified wrapper around psycopg2…
permissive · top 15,000 on PyPI
django-query-builderBuilds and executes complex SQL queries…
permissive · top 15,000 on PyPI
jinjasql2Generates parameterized SQL queries from Jinja2…
permissive · top 15,000 on PyPI
sqlparamsConverts SQL queries between different…
permissive · top 5,000 on PyPI
jinjasqlGenerates parameterized SQL queries from Jinja2…
permissive · top 15,000 on PyPI
opentelemetry-instrumentation-asyncpgAdds distributed tracing to PostgreSQL queries…
permissive · top 5,000 on PyPI
asyncpg-trekManages database migrations for asyncpg by…
permissive · top 15,000 on PyPI
datafusion-query-builderBuilds DataFusion SQL queries programmatically…
permissive · top 15,000 on PyPI