Metadata-Version: 2.4
Name: dbpulse-agent
Version: 1.1.0
Summary: Lightweight database query capture agent for DBPulse — real-time monitoring for PostgreSQL, MySQL, and MongoDB
Author: DBPulse
License: MIT
Keywords: dbpulse,database,monitoring,postgresql,psycopg2,mysql,mongodb,pymongo,query,performance,apm,observability,agent,flask,django,fastapi
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Database
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.25.0
Provides-Extra: postgresql
Requires-Dist: psycopg2-binary>=2.9.0; extra == "postgresql"
Provides-Extra: psycopg3
Requires-Dist: psycopg>=3.1; extra == "psycopg3"
Provides-Extra: asyncpg
Requires-Dist: asyncpg>=0.27.0; extra == "asyncpg"
Provides-Extra: mysql
Requires-Dist: mysql-connector-python>=8.0.0; extra == "mysql"
Provides-Extra: mongodb
Requires-Dist: pymongo>=4.0.0; extra == "mongodb"
Provides-Extra: flask
Requires-Dist: flask>=2.0.0; extra == "flask"
Provides-Extra: django
Requires-Dist: django>=3.2; extra == "django"
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.68.0; extra == "fastapi"
Requires-Dist: starlette>=0.14.0; extra == "fastapi"
Provides-Extra: all
Requires-Dist: psycopg2-binary>=2.9.0; extra == "all"
Requires-Dist: psycopg>=3.1; extra == "all"
Requires-Dist: asyncpg>=0.27.0; extra == "all"
Requires-Dist: mysql-connector-python>=8.0.0; extra == "all"
Requires-Dist: pymongo>=4.0.0; extra == "all"

# dbpulse-agent (Python)

Application-layer PostgreSQL query monitoring for Flask, Django, FastAPI, and
other Python applications. Queries are timed, correlated with the current HTTP
request, buffered, and sent to DBPulse without requiring PostgreSQL monitoring
roles.

## Supported PostgreSQL drivers

- `psycopg2` — Flask, Django, SQLAlchemy, and raw connections
- `psycopg` v3 — sync/async applications and modern Django
- `asyncpg` — FastAPI and SQLAlchemy async engines

Install the agent and the driver used by your application:

```bash
pip install dbpulse-agent[postgresql]  # psycopg2
pip install dbpulse-agent[psycopg3]    # psycopg v3
pip install dbpulse-agent[asyncpg]     # asyncpg
```

Initialize DBPulse before creating database connections:

```python
import os
from dbpulse_agent import DBPulseAgent

DBPulseAgent.init(
    api_key=os.environ["DBPULSE_API_KEY"],
    connection_id=os.environ["DBPULSE_CONNECTION_ID"],
    db_type="postgresql",
)
```

### Flask

```python
app = Flask(__name__)
DBPulseAgent.flask_middleware()(app)
```

### Django

Initialize the agent near the top of `settings.py`, then add:

```python
MIDDLEWARE = [
    "dbpulse_agent.middleware.django_mw.DBPulseDjangoMiddleware",
    # ...
]
```

### FastAPI

```python
app = FastAPI()
app.middleware("http")(DBPulseAgent.fastapi_middleware())
```

Call `DBPulseAgent.shutdown()` during application shutdown to flush remaining
logs.
