Skip to main content

Production-ready database query optimization and performance monitoring for Python

Project description

QueryMaster

Production-ready database query optimization and performance monitoring for Python applications.

Features

  • Query analysis: N+1 detection, full table scan hints, complexity, slow query flagging
  • Performance monitoring: In-memory query history, stats, terminal dashboard
  • Optimization engine: Suggestions and index advisor based on WHERE/JOIN columns
  • Integrations: Generic cursor wrapper, SQLAlchemy events, context manager for raw SQL

Installation

This package is published on PyPI as query-master-optimizer (the name "querymaster" is already taken). You still import it as querymaster:

pip install query-master-optimizer

Optional extras:

pip install query-master-optimizer[sqlalchemy]   # SQLAlchemy engine recording
pip install query-master-optimizer[django]       # Django (future)
pip install query-master-optimizer[fastapi]      # FastAPI (optional)
pip install query-master-optimizer[flask]        # Flask (optional)

Quick Start

from querymaster import (
    QueryRecorder,
    QueryMasterConfig,
    analyze_query,
    print_dashboard,
)

# Configure and create recorder
config = QueryMasterConfig(slow_query_threshold_ms=50.0)
recorder = QueryRecorder(config)

# Record some queries (e.g. from your app)
recorder.record("SELECT * FROM users WHERE id = 1", execution_time_ms=12.5)
recorder.record("SELECT * FROM orders WHERE user_id = 1", execution_time_ms=120.0)

# Analyze a single query
issues = analyze_query(
    "SELECT * FROM users WHERE 1=1",
    execution_time=0.5,
)
for issue in issues:
    print(issue.message, issue.suggestion)

# Print terminal dashboard
print_dashboard(recorder)

SQLAlchemy Integration

from sqlalchemy import create_engine
from querymaster import QueryRecorder
from querymaster.integrations.sqlalchemy_events import install_sqlalchemy

engine = create_engine("postgresql://...")
recorder = QueryRecorder()
install_sqlalchemy(engine, recorder)
# All statements executed via this engine are now recorded

License

MIT

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

query_master_optimizer-0.1.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

query_master_optimizer-0.1.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file query_master_optimizer-0.1.0.tar.gz.

File metadata

  • Download URL: query_master_optimizer-0.1.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Darwin/25.2.0

File hashes

Hashes for query_master_optimizer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8670a2616e62ee79bec1c5b778ea49b35dc98bc00ff9058d1626c6eaed89d7fd
MD5 089aec730e58349b2c9f92ae67856ae8
BLAKE2b-256 2eafe3beeac9442342b61620437929ea06636938dc57189211d95239a270383f

See more details on using hashes here.

File details

Details for the file query_master_optimizer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for query_master_optimizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4b60977b5e98ed9bac3ff84668befa5d15863894416da2daac8703fae8b1849
MD5 9853423cfdc96dcba7c132d0cc685225
BLAKE2b-256 4102e8e9874337c3b5e6ba29ce721ce46eb57d19d93cd6a06153c63e545b3252

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