Skip to main content

aio_tiny_healthcheck

PyPI Build Status Build Status

Tiny asynchronous implementation of healthcheck provider and server

Installation

pip install aio-tiny-healthcheck

Usage

By default, the Checker returns 200 if all checks successfully finish or 500 in opposite case.

Using with aiohttp

from aiohttp import web

from aio_tiny_healthcheck.checker import Checker

def some_sync_check():
    return True

async def some_async_check():
    return False

healthcheck_provider = Checker()
healthcheck_provider.add_check('sync_check_true', some_async_check)
healthcheck_provider.add_check('async_check_false', some_async_check)


app = web.Application()
app.router.add_get('/healthcheck', healthcheck_provider.aiohttp_handler)
web.run_app(app)

Using with Sanic

from sanic import Sanic
from sanic.response import json
from aio_tiny_healthcheck.checker import Checker

app = Sanic()

def some_sync_check():
    return True

async def some_async_check():
    return False

healthcheck_provider = Checker(success_code=201, fail_code=400)
healthcheck_provider.add_check('sync_check_true', some_async_check)
healthcheck_provider.add_check('async_check_false', some_async_check)

@app.route("/healthcheck")
async def test(request):
    hc_response = healthcheck_provider.check_handler()
    return json(hc_response.body, status=hc_response.code)

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

Using in concurrent mode

You should want to run healthcheck in background if you already have some blocking operation in your execution flow. So, you can just use built-in server for this.

from aio_tiny_healthcheck.checker import Checker
from aio_tiny_healthcheck.http_server import HttpServer
import asyncio


async def some_long_task():
    await asyncio.sleep(3600)


def some_sync_check():
    return True


async def some_async_check():
    return True


aio_thc = Checker()
hc_server = HttpServer(
    aio_thc,
    path='/health',
    host='localhost',
    port=9090
)

aio_thc.add_check('sync_check_true', some_async_check)
aio_thc.add_check('async_check_false', some_async_check)


async def main():
    # Run healthcheck concurrently
    asyncio.create_task(hc_server.run())

    # Run long task
    await some_long_task()


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

Utility for health checking

python -m aio_tiny_healthcheck http://localhost:9192/healthcheck

Useful for running health check without external dependencies like curl.

By default, concurrent server and health checking utility are working with a port and query path http://localhost:8000/healthcheck. So, if you run concurrent server with no using arguments, you can also run the utility with without arguments python -m aio_tiny_healthcheck.

Release files for aio-tiny-healthcheck 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aio-tiny-healthcheck 1.1.3
File Size Uploaded
aio_tiny_healthcheck-1.1.3.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aio-tiny-healthcheck 1.1.3
File Interpreter ABI Platform
aio_tiny_healthcheck-1.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 17.8 kB

Release files / aio_tiny_healthcheck-1.1.3.tar.gz

Download URL aio_tiny_healthcheck-1.1.3.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b9954ca4ba36d18839fb301f05e0058a9bab90da04ce3288a16aa96d6c936eb3
BLAKE2b-256 checksum
How to use checksums
b311d5078ba62b676161c0e1d2da4f1292262ef7f31317eddd0345b1f535e626
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.15

Release files / aio_tiny_healthcheck-1.1.3-py3-none-any.whl

Download URL aio_tiny_healthcheck-1.1.3-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
523c9f617fa45c5deb25b2c2bd2e9c6c10274a54292486cbd413cee65c4aded9
BLAKE2b-256 checksum
How to use checksums
056038e28a1909b1efe9b63cf20a73f740f95f4cda6d3e4a6c5c30839cbdd7f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.15

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page