Metadata-Version: 2.4
Name: fastapi-nplusone
Version: 0.1.0
Summary: A middlewere to help find n+1 queries in sqlalchemy.
License-Expression: BSD-3-Clause
License-File: LICENSE
Classifier: Environment :: Web Environment
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Dist: fastapi
Requires-Dist: sqlalchemy
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# FastAPI / SQLAlchemy N+1 query middleware

A FastAPI middleware to find N+1 queries in development.
This middleware helps developers identify and fix N+1 query issues in their FastAPI applications.
It provides logging information to help locate the query and the number of N+1 query occurrences.

This middleware should probably not be used in production, but it can be useful during development and 
testing.

## Installation

Pip Install:
```bash
pip install fastapi-nplusone
```

UV install:
```bash
uv install fastapi-nplusone
```

Poetry install:
```bash
poetry add fastapi-nplusone
```

## Usage

This middleware while suitable to run in production should probably be limited to development and tesring. The code 
snippet below shows how to add the middleware to your application.

```python
from fastapi import FastAPI
from fastapi_nplusone import NPlusOneMiddleware

app = FastAPI()
if not app.debug:
    app.add_middleware(NPlusOneMiddleware)

```

Example Output:

> 
> WARNING:fastapi_nplusone:Potential N+1 query detected on GET /api/changes: Query executed 3 times. Normalized query: 
>   SELECT change.id AS change_id
>

### Tests

To run the tests:

```bash
uv run pytest ./tests
```
