skillfed

google-cloud-sqlcommenter

Augment SQL statements with meta information about frameworks and the running environment.

google-cloud-sqlcommenter v2.0.0 534.3K downloads/30d#6,136 on PyPI
Permissive license BSD Abandoned released

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-sqlcommenter

uv

uv add google-cloud-sqlcommenter

poetry

poetry add google-cloud-sqlcommenter

Installing 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

Development Status :: 4 - BetaEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 2.1Framework :: Django :: 2.2Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Utilities

Tags

sql query annotationdjango sqlalchemy psycopg2 middlewaresql comment injectiondatabase query metadatatrace context sql loggingframework-aware sql commentsquery instrumentation
sql-instrumentationobservabilityabandoned

More Utilities packages

idna

Converts domain names between Unicode and…

permissive · top 100 on PyPI

charset-normalizer

Detects and normalizes text encoding from…

permissive · top 100 on PyPI

setuptools

Setuptools is a Python build backend and…

permissive · top 100 on PyPI

pluggy

Pluggy provides a plugin system that lets you…

permissive · top 100 on PyPI

Pygments

Pygments is a syntax highlighter that colorizes…

permissive · top 100 on PyPI

six

Six provides utility functions to write Python…

permissive · top 100 on PyPI

opentelemetry-instrumentation-psycopg2

Adds distributed tracing instrumentation to…

permissive · top 1,000 on PyPI

django-contrib-comments

Provides a Django framework for attaching…

permissive · top 15,000 on PyPI

opentelemetry-instrumentation-psycopg

Adds OpenTelemetry tracing instrumentation to…

permissive · top 5,000 on PyPI

opentelemetry-instrumentation-sqlalchemy

Adds distributed tracing to SQLAlchemy database…

permissive · top 1,000 on PyPI

sqlalchemy-cockroachdb

A SQLAlchemy dialect that enables ORM and SQL…

permissive · top 5,000 on PyPI

sqltap

sqltap hooks into SQLAlchemy to collect and…

permissive · top 15,000 on PyPI

sqlalchemy-mixins

Provides Active Record-style mixins for…

permissive · top 15,000 on PyPI

sqlalchemy-pgspider

Provides a SQLAlchemy dialect that enables…

permissive · top 15,000 on PyPI

opentelemetry-instrumentation-pymysql

Adds OpenTelemetry tracing instrumentation to…

permissive · top 5,000 on PyPI

sqlbag

sqlbag provides a collection of SQLAlchemy…

unclear · top 15,000 on PyPI