Skip to main content

aiohttp-healthcheck

A minimalist healthcheck library using aiohttp.

Installation

Install the package using pip:

pip install aio-healthcheck-python

Usage

Here is a basic example of how to use the aio-healthcheck-python library:

from aiohttp import web
from aio_healthcheck_python import start_healthcheck


async def check_database():
    # Implement your actual database check here.
    return True


async def handle_main_page(request):
    return web.Response(text="Hello, world")


async def start_web_server():
    app = web.Application()
    # Define routes here
    app.router.add_get('/', handle_main_page)

    # Set up and start the web server
    runner = web.AppRunner(app)
    await runner.setup()
    site = web.TCPSite(runner, '127.0.0.1', 8080)
    await site.start()

    print("Web server started on http://127.0.0.1:8080")
    return runner


async def main():
    # Start the web server and print its status
    web_runner = await start_web_server()

    # Start the healthcheck server with database check and print its status
    health_runner = await start_healthcheck(
        async_callables=[check_database],  # Asynchronous checks, including database
        host="127.0.0.1",
        path="/healthcheck",
        port=8000,
        success_code=200,
        error_code=500,
    )

    print("Healthcheck server started on http://127.0.0.1:8000")

    # Return the runners for potential further management
    return web_runner, health_runner


# Start the aiohttp application with the main coroutine
if __name__ == '__main__':
    web.run_app(main())

In this example, we define an asynchronous function check_database that performs a health check (in this case, it always returns True). We then start the healthcheck server with this function as an asynchronous callable. The server will respond with a 200 status code if the check passes, and a 500 status code if it fails.

Testing

To run the tests, use the following command:

PYTHONPATH=aio_healthcheck_python poetry run python -m unittest discover -s tests

License

This project is licensed under the terms of the Apache-2.0 license.

Metadata

Release files for aio-healthcheck-python 0.1.0

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-healthcheck-python 0.1.0
File Size Uploaded Provenance
aio_healthcheck_python-0.1.0.tar.gz 6.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aio-healthcheck-python 0.1.0
File Interpreter ABI Platform
aio_healthcheck_python-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / aio_healthcheck_python-0.1.0.tar.gz

Download URL aio_healthcheck_python-0.1.0.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7aa481979bb3cfbde9af8d44256b84123ef6f0bc633f3302a5cd052f2cf6c417
BLAKE2b-256 checksum
How to use checksums
cf2fe1fad73f24d7c58be26f428715319caabbb19341eaf3404cf3770194ef41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.9.18 Linux/6.5.0-1016-azure

Release files / aio_healthcheck_python-0.1.0-py3-none-any.whl

Download URL aio_healthcheck_python-0.1.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f469a82595c4ed434fc1fa3bf6e59624b87d732ed7fcc1a672c8a1303920717d
BLAKE2b-256 checksum
How to use checksums
93cec002272572e2035df8c43890f511e6fa761ce6d1bf1d4bb4982405c05409
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.9.18 Linux/6.5.0-1016-azure

Security for aio-healthcheck-python 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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