Skip to main content

Psycopg2 logging / profiling tool

Project description

Psycopg2Logger

Psycopg2Logger is made to work with https://github.com/larswise/pgquerymon and is a logging library that captures PostgreSQL database queries from psycopg2 and transmits them via TCP to the monitoring application in real-time. It provides detailed SQL query logging with parameter interpolation, execution duration tracking. The logger is optimized for development use with connection pooling, reflection caching, compiled regex patterns, and async logging to minimize performance impact on your application. Do not run this in production; this is intended for development only.

Installation

Install the package via pip:

pip install psycopg2logger

Usage

For FastAPI Applications

from fastapi import FastAPI
from psycopg2logger.middleware import SQLInterceptorMiddleware

app = FastAPI()

# Add the middleware to your FastAPI application
app.add_middleware(Psycopg2InterceptorMiddleware)

@app.get("/example")
async def example_endpoint():
    # Your database logic here
    return {"message": "Example endpoint"}

# Run your FastAPI application
# uvicorn main:app --reload

Monitoring Application

To view the captured SQL queries, you'll need the companion monitoring application pgquerymon which provides a real-time dashboard for analyzing your database interactions.

Features

  • Real-time SQL logging with parameter interpolation
  • Execution duration tracking for performance analysis
  • Intelligent caller detection to identify source business logic
  • High-performance design with connection pooling and caching
  • Async logging to prevent blocking your application
  • Support for FastAPI applications
  • Configurable performance settings for different use cases

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

psycopg2logger-0.3.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

psycopg2logger-0.3.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file psycopg2logger-0.3.0.tar.gz.

File metadata

  • Download URL: psycopg2logger-0.3.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for psycopg2logger-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b4ac8483976e7bb6d312ad46871208f5234368907b5f9615072ff99b792a1540
MD5 0e95190b9e8e374b4082c463798e3f4f
BLAKE2b-256 8b4e4d81432cba6eb1f551cadab321c0e5a2b3cef75abb45490452d070d4e247

See more details on using hashes here.

File details

Details for the file psycopg2logger-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: psycopg2logger-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for psycopg2logger-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b9dcbcebcbfbb15d59167929b8a5c49433e9ec4166726d0ec4594d709c59a28
MD5 5696d4cc5532a9f064548b1d86539646
BLAKE2b-256 6bb5ce8ef2b4bd37bd97dddf5b82f1dfcf682fbd8bbd74bdf20ffdfd8293e472

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page