pgspecial
Meta-commands handler for Postgres Database.
What it is and what it does
pgspecial is a Python library that wraps PostgreSQL's meta-commands—the backslash commands you'd normally type in psql—into a callable API. It lets you execute commands programmatically against a live database connection, returning structured results you can process in code.
The library is designed for tools that need to expose PostgreSQL introspection and administration commands without reimplementing them. It depends on click, sqlparse, and psycopg for the database connection itself. You instantiate PGSpecial, pass it a cursor and a command string, and iterate over the results. It also supports loading named queries from config files via the NamedQueries class.
Use it for:
- Building a PostgreSQL REPL or interactive shell that supports backslash commands.
- Adding database introspection to a Jupyter notebook or IPython environment.
- Implementing a web-based database management tool that needs to expose PostgreSQL admin commands.
- Automating database inspection tasks in scripts without reimplementing meta-command logic.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Executes PostgreSQL meta-commands (backslash commands) programmatically through a Python API, enabling applications to run special commands on a database connection.
Yes, if you need to execute PostgreSQL meta-commands programmatically. The library is stable, has low install friction, carries a permissive license, and is actively used by established projects. The 473-day release gap is a minor concern for a mature, narrow-scope package, but verify compatibility with your PostgreSQL and psycopg versions before production use.
Install
pgspecial on PyPI
pip
pip install pgspecialuv
uv add pgspecialpoetry
poetry add pgspecialInstalling pgspecial
Before you install
Low friction installation with three lightweight runtime dependencies. Maintenance status is aging—last release was 473 days ago—but the package remains in use by established projects.
License in practice
BSD permissive license allows use in commercial and proprietary projects with minimal restrictions, requiring only license attribution.
Quickstart
pip install pgspecial
from pgspecial.main import PGSpecial
pgspecial = PGSpecial()
for result in pgspecial.execute(cur, sql):
print(result)
Requires Python >=3.9 and an active psycopg database connection.
Verify before relying
- Whether the 473-day gap since last release reflects stable maturity or abandonment risk for future PostgreSQL compatibility.
- Current state of the repository (archived status, recent commits) to assess ongoing maintenance.
- Compatibility with current versions of psycopg and PostgreSQL.
Package facts
| License | BSD (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — click, sqlparse, psycopg |
| Maintenance | aging — 473 days since the last release |
| First released | |
| Downloads | 650,487/month — #5,561 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pgspecial-2.2.1-py3-none-any.whl
Keywords: postgres, database, cli, meta-commands
Tags
More Front-Ends packages
SQLAlchemy is a Python SQL toolkit and Object…
permissive · top 100 on PyPI
psycopg2-binarypsycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
alembicAlembic generates and manages database schema…
permissive · top 1,000 on PyPI
weaviate-clientA Python client library for connecting to and…
permissive · top 1,000 on PyPI
databricks-sql-connectorA Python client library that connects to…
permissive · top 1,000 on PyPI
psycopgPsycopg 3 is a PostgreSQL database adapter for…
copyleft · top 1,000 on PyPI
pgclipgcli is a command-line interface for…
permissive · top 15,000 on PyPI
pgdbWraps PostgreSQL connections to return query…
permissive · top 15,000 on PyPI
jupysqlAdds SQL execution to Jupyter and IPython…
permissive · top 15,000 on PyPI
pgsanityPgSanity validates PostgreSQL SQL syntax by…
permissive · top 15,000 on PyPI
postgresProvides a lightweight abstraction layer over…
permissive · top 15,000 on PyPI
litecliA command-line client for SQLite databases with…
permissive · top 15,000 on PyPI
psycopg2PostgreSQL database adapter for Python that…
copyleft · top 1,000 on PyPI
sqlalchemy-pgspiderProvides a SQLAlchemy dialect that enables…
permissive · top 15,000 on PyPI
PyPgConfigPyPgConfig detects and exposes PostgreSQL…
permissive · top 15,000 on PyPI
testing.postgresqlAutomatically creates and tears down temporary…
permissive · top 5,000 on PyPI