Skip to main content

Health check endpoint builder for web applications.

Project description

philiprehberger-health-check

Tests PyPI version GitHub release Last updated License Bug Reports Feature Requests Sponsor

Health check endpoint builder for web applications.

Installation

pip install philiprehberger-health-check

Usage

Basic Health Check

from philiprehberger_health_check import HealthCheck, checks

hc = HealthCheck()
hc.add("database", lambda: True)
hc.add(*checks.tcp("redis", "localhost", 6379))
hc.add(*checks.disk_space("disk", "/", min_free_gb=2))

result = hc.run()
print(result.status)  # "healthy" or "unhealthy"

for check in result.checks:
    print(f"{check.name}: {'OK' if check.healthy else check.message}")

Check Dependencies

hc = HealthCheck()
hc.add("database", check_db)
hc.add("migrations", check_migrations, depends_on=["database"])

result = hc.run()
# If "database" fails, "migrations" is skipped automatically

Async Execution

import asyncio

hc = HealthCheck()
hc.add("database", check_db)
hc.add("cache", check_cache)
hc.add("migrations", check_migrations, depends_on=["database"])

result = await hc.run_async()
# Independent checks run concurrently; dependencies are respected

Built-in Checks

# TCP connectivity
hc.add(*checks.tcp("postgres", "db.example.com", 5432, timeout=3))

# Disk space
hc.add(*checks.disk_space("storage", "/data", min_free_gb=5))

# Memory usage (Linux only, skipped on other platforms)
hc.add(*checks.memory("ram", max_percent=85))

# Custom check
hc.add(*checks.custom("cache", lambda: cache.ping()))

API

Name Description
HealthCheck() Create a health check builder
hc.add(name, fn, depends_on=None) Register a check with optional dependencies
hc.run() Run all checks sequentially and return HealthResult
hc.run_async() Run checks concurrently, respecting dependency order
checks.tcp(name, host, port, timeout=2) TCP connectivity check
checks.disk_space(name, path, min_free_gb=1) Disk free space check
checks.memory(name, max_percent=90) Memory usage check (Linux)
checks.custom(name, fn) Wrap any callable as a check
CheckResult Dataclass: name, healthy, message, duration_ms
HealthResult Dataclass: status, checks, uptime_seconds

Development

pip install -e .
python -m pytest tests/ -v

Support

If you find this package useful, consider starring the repository.

LinkedIn More packages

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_health_check-0.2.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_health_check-0.2.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_health_check-0.2.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_health_check-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7f04393a959948cb8b119dd9f0ce4b016c5a37bce1bd375953cb609b6582ef6f
MD5 765d216eae2cdf8c68086abca44271fa
BLAKE2b-256 06fe293166525f308c9e45a83b46c7740e1a77ccdea1e7caee63b985447c70b0

See more details on using hashes here.

File details

Details for the file philiprehberger_health_check-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_health_check-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eed5ff11addd6637ab259b16406d10298bd2dc52f063dafeba34c56314b11de5
MD5 98b4659560e7a6c32d1a8f905353cc7a
BLAKE2b-256 d61bdafe97548dc5a58274dc0fdc1fcb97524cbdacdc01a0fdf88cae943dd224

See more details on using hashes here.

Supported by

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