Skip to main content

fastapi-neo4j-healthcheck 🚀

PyPI version License: MIT Python Versions

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.AsyncGraphDatabase and neo4j.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 OK when healthy and 503 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

fastapi_neo4j_healthcheck-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_neo4j_healthcheck-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_neo4j_healthcheck-0.1.0.tar.gz.

File metadata

File hashes

Hashes for fastapi_neo4j_healthcheck-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6aa19a82c4ecef1e026b16d93ea7090ed848ccfd512bd7e71f7385ad1a654a6e
MD5 09c669cc2557c1667e707dbfbee3b112
BLAKE2b-256 a89e5984f456ae1f4a2abcde85c83894d081178368765ec5fbe0fb227f04a575

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_neo4j_healthcheck-0.1.0.tar.gz:

Publisher: publish.yml on gabaoun/fastapi-neo4j-healthcheck

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastapi_neo4j_healthcheck-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_neo4j_healthcheck-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1b8c5915a7f86194a34fb9498f7dacf3fdd9636d09f8311f78092151c5dc17c
MD5 ad06ef49c33dc472d68c7e7da27af513
BLAKE2b-256 28324d105ee100188b2cef2dcbace31768d925377e55aa30a9231f9f992d745d

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page