skillfed

buildpg

Query building for the postgresql prepared statements and asyncpg.

buildpg v0.4 103.2K downloads/30d#12,823 on PyPI87
Permissive license MIT Abandoned released

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 buildpg

uv

uv add buildpg

poetry

poetry add buildpg

Installing 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

Development Status :: 3 - AlphaEnvironment :: ConsoleEnvironment :: MacOS XIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: System AdministratorsLicense :: OSI Approved :: MIT LicenseOperating System :: POSIX :: LinuxOperating System :: UnixProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: SQLTopic :: InternetTopic :: Software Development :: Libraries :: Python Modules

Tags

postgresql query builderasyncpg prepared statementssql parameter substitutionpostgres where clause builderdynamic sql constructionasyncpg query wrappernamed parameter sql
query-builderasyncpgsql-generation

More Python Modules packages