fastapi-neo4j-healthcheck 🚀
Lightweight Neo4j readiness endpoint for FastAPI.
Features
- ⚡ Sync & Async Driver Support: Seamlessly works with
neo4j.AsyncGraphDatabaseandneo4j.GraphDatabase. - 🩺 Non-Blocking Ping: Executes lightweight Cypher queries (
RETURN 1 AS ping) off the main thread or via async I/O. - ⏱️ Timeout Protection: Configurable timeout (default
3.0s) to prevent health check hangs during database failover or high load. - ⚓ Kubernetes Ready: Returns
200 OKwhen healthy and503 Service Unavailable(customizable) when degraded. - 📊 Observability & Latency: Includes latency in milliseconds (
latency_ms) and database target details in the response payload.
Installation
pip install fastapi-neo4j-healthcheck
Or with neo4j driver included:
pip install fastapi-neo4j-healthcheck[neo4j]
Quickstart
1. Using Async Neo4j Driver (Recommended)
from fastapi import FastAPI
from neo4j import AsyncGraphDatabase
from fastapi_neo4j_healthcheck import create_neo4j_health_router
app = FastAPI(title="Graph API")
# Initialize Neo4j Async Driver
driver = AsyncGraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))
# Include Health Check Router
app.include_router(
create_neo4j_health_router(
driver_provider=driver,
prefix="/health/neo4j",
tags=["Health"],
)
)
2. Using Sync Neo4j Driver
from fastapi import FastAPI
from neo4j import GraphDatabase
from fastapi_neo4j_healthcheck import create_neo4j_health_router
app = FastAPI()
driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))
app.include_router(
create_neo4j_health_router(driver_provider=driver, prefix="/healthcheck")
)
3. Dynamic / Dependency-Injected Driver Provider
from fastapi import FastAPI
from fastapi_neo4j_healthcheck import create_neo4j_health_router
app = FastAPI()
def get_db_driver():
# Resolved on every request, e.g. a driver created in the app lifespan
return app.state.neo4j_driver
app.include_router(
create_neo4j_health_router(driver_provider=get_db_driver)
)
Response Schema
Healthy (HTTP 200)
{
"status": "healthy",
"database": "neo4j",
"latency_ms": 3.45,
"details": {
"connected": true
}
}
Unhealthy (HTTP 503)
{
"status": "unhealthy",
"database": "neo4j",
"latency_ms": 3001.12,
"details": {
"connected": false,
"error": "ServiceUnavailable"
}
}
By default only the exception class name is returned, because raw driver messages can leak
host, port and database names to unauthenticated callers. The full error is logged with
logging (logger fastapi_neo4j_healthcheck.health, with traceback). To include the raw
message in the response (e.g. on an internal-only endpoint), pass expose_errors=True.
Kubernetes Readiness Probe Configuration
readinessProbe:
httpGet:
path: /health/neo4j
port: 8000
initialDelaySeconds: 2
periodSeconds: 5
Use this endpoint as a readiness probe only. Do not point a livenessProbe at it: a
database outage would make Kubernetes restart every healthy pod, which does not fix the
database and turns a partial outage into a full one. Liveness should only check that the
process itself is responsive. For that, pass liveness_prefix and the router registers a
separate endpoint that never touches Neo4j:
app.include_router(
create_neo4j_health_router(
driver_provider=driver,
prefix="/health/neo4j",
liveness_prefix="/livez",
)
)
livenessProbe:
httpGet:
path: /livez
port: 8000
periodSeconds: 10
/livez returns 200 {"status": "alive"} while the process can serve a request. It is
off by default (liveness_prefix=None).
License
MIT License - Created by Gabaoun.
Metadata
Release files for fastapi-neo4j-healthcheck 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_neo4j_healthcheck-0.2.0.tar.gz | 5.7 kB | With provenance | Details for fastapi_neo4j_healthcheck-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_neo4j_healthcheck-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for fastapi_neo4j_healthcheck-0.2.0-py3-none-any.whl |
Total release size: 12.3 kB
Release files / fastapi_neo4j_healthcheck-0.2.0.tar.gz
| Download URL | fastapi_neo4j_healthcheck-0.2.0.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2eec40d9ac91f13bd94018b339a86139a0f7f52b34d923984948bf19354960a2
|
|
BLAKE2b-256 checksum How to use checksums |
e8c19c60e0dd7b6a26ff06208822c30f17fc5fc895b931f04b45e3ece0c2b53d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / fastapi_neo4j_healthcheck-0.2.0-py3-none-any.whl
| Download URL | fastapi_neo4j_healthcheck-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dac1f3f31fa7d9417a1f7525ec63941444a78e3cb59cde698c2eaf8961a0fb5c
|
|
BLAKE2b-256 checksum How to use checksums |
b0009209fbce7fe1a5029f409b57be7f7573eb15a84d0ba84eace64dbca57a76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logSecurity for fastapi-neo4j-healthcheck 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for fastapi_neo4j_healthcheck-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.