google-cloud-sqlcommenter
Augment SQL statements with meta information about frameworks and the running environment.
What it is and what it does
sqlcommenter is a set of middleware and cursor factories that automatically append SQL comments containing metadata to database queries. It works by intercepting queries at the ORM or driver level—Django middleware, SQLAlchemy event listeners, or Psycopg2 cursor factories—and injecting structured comments that capture framework version, HTTP route, controller/endpoint name, and optionally distributed trace context via OpenCensus or OpenTelemetry. The comments appear in database logs, making it easier to correlate slow queries or errors back to the application code that triggered them.
The package supports Django, SQLAlchemy, and Psycopg2 with configurable options for which metadata to include. It has no runtime dependencies for basic use, though OpenCensus and OpenTelemetry can be installed as optional extras. However, the project is abandoned—the last release was 2021-08-18—so it will not receive updates for compatibility with newer framework versions or security fixes.
Use it for:
- Add framework and route metadata to SQL logs in Django applications to correlate slow queries with specific views
- Inject trace IDs into SQLAlchemy queries for distributed tracing across microservices
- Embed driver and connection pool info in Psycopg2 logs to debug database connection issues
- Capture OpenTelemetry trace context in SQL comments for end-to-end request tracing
- Augment database audit logs with application context without modifying query code
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Automatically injects metadata comments into SQL queries executed through Django, SQLAlchemy, or Psycopg2, capturing framework version, route, controller, and optionally trace context.
No. The package is abandoned (last release 2021-08-18) and will not receive updates for compatibility with modern framework versions or security issues. While the core concept is sound and the BSD license is permissive, the lack of maintenance makes it a liability for new projects. Consider alternatives that are actively maintained.
Install
google-cloud-sqlcommenter on PyPI
pip
pip install google-cloud-sqlcommenteruv
uv add google-cloud-sqlcommenterpoetry
poetry add google-cloud-sqlcommenterInstalling google-cloud-sqlcommenter
Before you install
Installation is straightforward with no runtime dependencies for the base package. However, the project is abandoned—last release was 2021-08-18, over 1822 days ago—so no maintenance or security updates are expected.
License in practice
BSD license is permissive, allowing commercial use, modification, and distribution with minimal restrictions. No licensing barrier to adoption.
Quickstart
# Django
pip install google-cloud-sqlcommenter
# Add to settings.py MIDDLEWARE:
MIDDLEWARE = [
'google.cloud.sqlcommenter.django.middleware.SqlCommenter',
]
# SQLAlchemy
from google.cloud.sqlcommenter.sqlalchemy.executor import BeforeExecuteFactory
listener = BeforeExecuteFactory(with_db_driver=True)
sqlalchemy.event.listen(engine, 'before_cursor_execute', listener, retval=True)
# Psycopg2
from google.cloud.sqlcommenter.psycopg2.extension import CommenterCursorFactory
cursor_factory = CommenterCursorFactory(with_db_driver=True)
conn = psycopg2.connect(..., cursor_factory=cursor_factory)
Verify before relying
- Whether the package works correctly with modern versions of Django, SQLAlchemy, or Psycopg2 released after 2021-08-18
- Whether OpenCensus and OpenTelemetry optional dependencies are still compatible with current versions
- Whether the package is maintained under a different repository or organization
Package facts
| License | BSD (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 1,822 days since the last release |
| First released | |
| Downloads | 534,275/month — #6,136 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: google_cloud_sqlcommenter-2.0.0-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
opentelemetry-instrumentation-psycopg2Adds distributed tracing instrumentation to…
permissive · top 1,000 on PyPI
django-contrib-commentsProvides a Django framework for attaching…
permissive · top 15,000 on PyPI
opentelemetry-instrumentation-psycopgAdds OpenTelemetry tracing instrumentation to…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-sqlalchemyAdds distributed tracing to SQLAlchemy database…
permissive · top 1,000 on PyPI
sqlalchemy-cockroachdbA SQLAlchemy dialect that enables ORM and SQL…
permissive · top 5,000 on PyPI
sqltapsqltap hooks into SQLAlchemy to collect and…
permissive · top 15,000 on PyPI
sqlalchemy-mixinsProvides Active Record-style mixins for…
permissive · top 15,000 on PyPI
sqlalchemy-pgspiderProvides a SQLAlchemy dialect that enables…
permissive · top 15,000 on PyPI
opentelemetry-instrumentation-pymysqlAdds OpenTelemetry tracing instrumentation to…
permissive · top 5,000 on PyPI
sqlbagsqlbag provides a collection of SQLAlchemy…
unclear · top 15,000 on PyPI