Skip to main content

Python 3 library to write simple asynchronous health checks (probes)

Project description

PROB🧪RKA

Python 3 library to write simple asynchronous health checks (probes).

Ruff PyPI PyPI

Overview

Probirka is a Python library designed to facilitate the creation of simple asynchronous health checks, also known as probes. It allows you to define custom probes to monitor the health of various services and components in your application.

Features

  • Simple API for defining asynchronous health checks
  • Support for custom probes
  • Integration with FastAPI and aiohttp
  • Ability to add custom information to health check results
  • Grouping of probes for selective execution
  • Timeout support for probes

Installation

Install Probirka using pip:

pip install probirka

Usage

Here is a simple example of how to use Probirka to create an asynchronous health check:

import asyncio
from probirka import Probe, HealthCheck

class DatabaseProbe(Probe):
    async def check(self):
        # Simulate a database check
        await asyncio.sleep(1)
        return True

class CacheProbe(Probe):
    async def check(self):
        # Simulate a cache check
        await asyncio.sleep(1)
        return False  # Simulate a failed check

async def main():
    health_check = HealthCheck(probes=[DatabaseProbe(), CacheProbe()])
    health_check.add_info("version", "1.0.0")
    health_check.add_info("environment", "production")
    results = await health_check.run()
    print(results)

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

This example defines two probes, DatabaseProbe and CacheProbe, and runs them as part of a health check. The CacheProbe simulates a failed check. Additionally, it adds custom user data using the add_info method.

Example output:

HealthCheckResult(
    ok=False,
    info={'version': '1.0.0', 'environment': 'production'},
    started_at=datetime.datetime(2023, 10, 10, 10, 0, 0),
    total_elapsed=datetime.timedelta(seconds=1),
    checks=[
        ProbeResult(name='DatabaseProbe', ok=True, elapsed=datetime.timedelta(seconds=1)),
        ProbeResult(name='CacheProbe', ok=False, elapsed=datetime.timedelta(seconds=1))
    ]
)

Integration with FastAPI

You can integrate Probirka with FastAPI as follows:

from fastapi import FastAPI
from probirka import Probirka
from probirka._fastapi import make_fastapi_endpoint

app = FastAPI()

probirka_instance = Probirka()
fastapi_endpoint = make_fastapi_endpoint(probirka_instance)

app.add_api_route("/run", fastapi_endpoint)

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

Integration with aiohttp

You can integrate Probirka with aiohttp as follows:

from aiohttp import web
from probirka import Probirka
from probirka._aiohttp import make_aiohttp_endpoint

app = web.Application()

probirka_instance = Probirka()
aiohttp_endpoint = make_aiohttp_endpoint(probirka_instance)

app.router.add_get('/run', aiohttp_endpoint)

if __name__ == '__main__':
    web.run_app(app)

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License.

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

probirka-0.3.2.tar.gz (119.7 kB view details)

Uploaded Source

Built Distribution

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

probirka-0.3.2-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file probirka-0.3.2.tar.gz.

File metadata

  • Download URL: probirka-0.3.2.tar.gz
  • Upload date:
  • Size: 119.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.13

File hashes

Hashes for probirka-0.3.2.tar.gz
Algorithm Hash digest
SHA256 0ff0a1835a4bb15571a76c7cf74eb26365be837482775aca19adbf20636fb721
MD5 1af9518689656b2c436f2bb3112ee755
BLAKE2b-256 367782d788ec71fbc2771fc8040009a54ad66c8671be08ada2abcdc998d66eb3

See more details on using hashes here.

File details

Details for the file probirka-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: probirka-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.13

File hashes

Hashes for probirka-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3bc0c2ad7d9fbbe9dd3275e1a97e1d85bf9c08cb6742ee4eb9e8dda217ebc684
MD5 87379db8706ecf175d9739af59771577
BLAKE2b-256 e327d2859162d4caff514db3e85808f1b19a00b5b5332ea0b5db08e819ccb50d

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