Metadata-Version: 2.1
Name: query_summary
Version: 0.1.1
Summary: A Flask middleware to track MongoDB queries and provide query statistics.
Home-page: https://github.com/mstfsu/query_summary
Author: mstfsu
Author-email: su.mustafa@hotmail.com
Project-URL: Bug Tracker, https://github.com/mstfsu/query_summary/issues
Project-URL: Documentation, https://github.com/mstfsu/query_summary#readme
Project-URL: Source Code, https://github.com/mstfsu/query_summary
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Flask>=2.0
Requires-Dist: pymongo>=4.0
Requires-Dist: mongoengine>=0.24.0

# 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:

```python
# 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.

```python
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
<img width="1280" alt="Screenshot 2025-05-22 at 15 32 54" src="https://github.com/user-attachments/assets/17547730-c330-478c-a1a6-b5d3601dd917" />
