fastapi-neo4j-healthcheck 🚀
Production-grade, zero-overhead Neo4j health check endpoint for FastAPI applications with Kubernetes liveness/readiness probe support.
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
def get_db_driver():
return current_app_state.neo4j_driver
app = FastAPI()
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: Could not perform discovery for database 'neo4j'"
}
}
Kubernetes Readiness Probe Configuration
livenessProbe:
httpGet:
path: /health/neo4j
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
httpGet:
path: /health/neo4j
port: 8000
initialDelaySeconds: 2
periodSeconds: 5
License
MIT License - Created by Gabaoun.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_neo4j_healthcheck-0.1.0.tar.gz.
File metadata
- Download URL: fastapi_neo4j_healthcheck-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6aa19a82c4ecef1e026b16d93ea7090ed848ccfd512bd7e71f7385ad1a654a6e
|
|
| MD5 |
09c669cc2557c1667e707dbfbee3b112
|
|
| BLAKE2b-256 |
a89e5984f456ae1f4a2abcde85c83894d081178368765ec5fbe0fb227f04a575
|
Provenance
The following attestation bundles were made for fastapi_neo4j_healthcheck-0.1.0.tar.gz:
Publisher:
publish.yml on gabaoun/fastapi-neo4j-healthcheck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_neo4j_healthcheck-0.1.0.tar.gz -
Subject digest:
6aa19a82c4ecef1e026b16d93ea7090ed848ccfd512bd7e71f7385ad1a654a6e - Sigstore transparency entry: 2453902301
- Sigstore integration time:
-
Permalink:
gabaoun/fastapi-neo4j-healthcheck@f73113fe6b26d2263729333e5d31755a61e1d491 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gabaoun
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f73113fe6b26d2263729333e5d31755a61e1d491 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fastapi_neo4j_healthcheck-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_neo4j_healthcheck-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1b8c5915a7f86194a34fb9498f7dacf3fdd9636d09f8311f78092151c5dc17c
|
|
| MD5 |
ad06ef49c33dc472d68c7e7da27af513
|
|
| BLAKE2b-256 |
28324d105ee100188b2cef2dcbace31768d925377e55aa30a9231f9f992d745d
|
Provenance
The following attestation bundles were made for fastapi_neo4j_healthcheck-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on gabaoun/fastapi-neo4j-healthcheck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_neo4j_healthcheck-0.1.0-py3-none-any.whl -
Subject digest:
b1b8c5915a7f86194a34fb9498f7dacf3fdd9636d09f8311f78092151c5dc17c - Sigstore transparency entry: 2453902530
- Sigstore integration time:
-
Permalink:
gabaoun/fastapi-neo4j-healthcheck@f73113fe6b26d2263729333e5d31755a61e1d491 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gabaoun
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f73113fe6b26d2263729333e5d31755a61e1d491 -
Trigger Event:
release
-
Statement type: