Google Cloud SQLCommenter

2.0.0 · active · verified Thu Apr 16

Google Cloud SQLCommenter augments SQL statements with meta information about frameworks and the running environment, enabling better observability for database operations. It acts as a meta-package to install framework-specific SQLCommenter integrations (e.g., for SQLAlchemy, Django, Flask). The current version is 2.0.0, with new versions typically released to align with major dependency updates or new feature integrations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate SQLCommenter with SQLAlchemy. After installing `google-cloud-sqlcommenter`, import `patch` from `sqlalchemy_sqlcommenter` and apply it to your SQLAlchemy engine. All subsequent queries through that engine will be augmented with comments.

from sqlalchemy import create_engine
from sqlalchemy_sqlcommenter import patch

# Configure a dummy engine for demonstration
engine = create_engine('sqlite:///:memory:')

# Patch the engine to enable SQL commenting
patch(engine)

# Execute a sample query
with engine.connect() as conn:
    result = conn.execute('SELECT 1 + 1').scalar()
    print(f"Query result: {result}")

# In a real application, you would observe the SQL comments 
# in your database logs or APM/tracing tools.

view raw JSON →