Skip to main content

A Flask middleware to track MongoDB queries and provide query statistics.

Project description

Query Summary

Query Summary is a Flask middleware designed to track MongoDB queries and provide a summary of query statistics. It includes a web interface to display the last 10 requests and their associated query details.

Usage

Here's an example of how to use the package:

# Import the package
from query_summary import QuerySummaryMiddleware
from pymongo import MongoClient

# Initialize the Flask app
app = Flask(__name__)

# Initialize the QuerySummaryMiddleware
query_summary_middleware = QuerySummaryMiddleware(app)

# Use the same MongoClient instance with the QuerySummaryMiddleware
client = MongoClient("mongodb://host:port", event_listeners=[query_summary_middleware.query_counter])

# Example MongoDB operation
db = client["example_database"]
db["example_collection"].insert_one({"name": "Test Document"})

Notes:

  • If you are using mongoengine, it internally creates its own MongoClient instance unless you explicitly pass one to it. To ensure compatibility.
import mongoengine as me

# Use the same MongoClient instance with mongoengine
me.connect(alias="example_database", host=client)
  • The QuerySummaryMiddleware automatically tracks MongoDB commands executed by the MongoClient instance it is registered with.
  • go to /query_summary to see statistics
Screenshot 2025-05-22 at 15 32 54

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_summary-0.1.1.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.

query_summary-0.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file query_summary-0.1.1.tar.gz.

File metadata

  • Download URL: query_summary-0.1.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for query_summary-0.1.1.tar.gz
Algorithm Hash digest
SHA256 36a53d267f37a0d903cf3cb4919249561a179ae5f7cb12def5e6481fbb7edffe
MD5 a13bffc9e32ec476b90fecdf019fdd8f
BLAKE2b-256 02607e6acdcf05dc91539650d4796bf4b42e522c6fc6ea7e8ca1cba406b1b0cf

See more details on using hashes here.

File details

Details for the file query_summary-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: query_summary-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for query_summary-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 81b722e12ee71b41067c18579e4662f699cdbb3614e8b69ef6761ef042257e20
MD5 8550ada282802f6336a84b83528c23ee
BLAKE2b-256 5746c6986999fc8adc6dce901adca121428085023332b6c214bc185eec4456f5

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