Skip to main content

Tiny and fast async readiness and liveness healthcheck server with no dependencies

Project description

hcheckz

Tests Coverage Python Version

Tiny asynchronous healthcheck server.

Installation

pip install hcheckz

Usage

import asyncio
import hcheckz

async def main():
    # Start the healthcheck server in the background
    hcheck_task = hcheckz.start_healthchecks(host="0.0.0.0", port=8080)
    
    # Register your dependency points
    hcheckz.readiness_point("kafka")
    hcheckz.readiness_point("redis")
    
    # Start main application background tasks
    await asyncio.sleep(2) 
    hcheckz.set_ready("kafka")

    await asyncio.sleep(2) 
    hcheckz.set_ready("redis")

    
    # Keep the main loop alive and handle graceful shutdown
    try:
        await asyncio.Event().wait() 
    except asyncio.CancelledError:
        hcheck_task.cancel()

if __name__ == "__main__":
    asyncio.run(main())

Endpoints:

  • /healthz
  • /readyz

/healthz

200 OK status if service is at least running

/readyz

200 OK status if all of readiness points are ready and registred more than zero readiness points unless 503 Service Unavailable

200 OK

200 OK

503 Service Unavailable (0 points registred)

{
    "reason": "Nothing Registred"
}

503 Service Unavailable (problems)

{
    "reason": "Unreadinesses",
    "details": {
        "kafka": {
            "code": "FATAL ERROR",
            "message": "Some unknown fatal error, Kafka dead."
        }
    }
}

HTTP Status Codes Reference

  • 200 OK
  • 400 Bad Request
  • 404 Not Found
  • 405 Method Not Allowed
  • 503 Service Unavailable

200 OK

Always returns text/plain body: 200 OK

400 Bad Request

Always returns text/plain body

400 Bad Request: Request line too long

404 Not Found

Always returns text/plain body

404 Not Found

405 Method Not Allowed

Always returns text/plain body

405 Method Not Allowed

503 Service Unavailable

Always returns application/json body Watch endpoint [[README.md#readyz/|readyz/]]

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

hcheckz-1.0.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

hcheckz-1.0.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file hcheckz-1.0.0.tar.gz.

File metadata

  • Download URL: hcheckz-1.0.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for hcheckz-1.0.0.tar.gz
Algorithm Hash digest
SHA256 59a6e02f7cfaf9339666c68a6041a732245ec9c9f1db449f3a202716e54e78af
MD5 195c639c8888de66666007d9eac363f0
BLAKE2b-256 8a4d9ae1871a0fb3a09d2ee1578306c4cb5f91a0cfc1290914b47cbd11e9e2d6

See more details on using hashes here.

File details

Details for the file hcheckz-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: hcheckz-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for hcheckz-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a5adca09d5de82dd4687ba7f994e9b28ab25d2646a734803e9a8aa35a87e7e6
MD5 38d0fcf32a297f88e81e21b07816d03d
BLAKE2b-256 09067180622272789edb27c7606aae2fbb016c6c3cbd3d0d8bf532b3f8b5582b

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