{"id":15288706,"url":"https://github.com/kludex/fastapi-health","last_synced_at":"2025-04-04T19:12:10.271Z","repository":{"id":41055167,"uuid":"332332801","full_name":"Kludex/fastapi-health","owner":"Kludex","description":"Implement the Health Check API pattern on your FastAPI application! :rocket: ","archived":false,"fork":false,"pushed_at":"2023-07-30T18:04:36.000Z","size":372,"stargazers_count":175,"open_issues_count":8,"forks_count":13,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-30T06:58:27.347Z","etag":null,"topics":["fastapi","healthcheck"],"latest_commit_sha":null,"homepage":"https://kludex.github.io/fastapi-health/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kludex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-01-23T23:57:27.000Z","updated_at":"2024-09-30T19:59:48.000Z","dependencies_parsed_at":"2024-01-14T06:56:11.852Z","dependency_job_id":null,"html_url":"https://github.com/Kludex/fastapi-health","commit_stats":{"total_commits":27,"total_committers":5,"mean_commits":5.4,"dds":"0.14814814814814814","last_synced_commit":"a489ffa3d0a363c40239f9e1c1149dc150947bcb"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kludex%2Ffastapi-health","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kludex%2Ffastapi-health/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kludex%2Ffastapi-health/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kludex%2Ffastapi-health/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kludex","download_url":"https://codeload.github.com/Kludex/fastapi-health/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247234923,"owners_count":20905854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","healthcheck"],"created_at":"2024-09-30T15:52:24.176Z","updated_at":"2025-04-04T19:12:10.248Z","avatar_url":"https://github.com/Kludex.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n    \u003cstrong\u003eFastAPI Health 🚑️\u003c/strong\u003e\n\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/Kludex/fastapi-health\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/last-commit/Kludex/fastapi-health\" alt=\"Latest Commit\"\u003e\n    \u003c/a\u003e\n        \u003cimg src=\"https://img.shields.io/github/workflow/status/Kludex/fastapi-health/Test\"\u003e\n        \u003cimg src=\"https://img.shields.io/codecov/c/github/Kludex/fastapi-health\"\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://pypi.org/project/fastapi-health\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/v/fastapi-health\" alt=\"Package version\"\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/pyversions/fastapi-health\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/Kludex/fastapi-health\"\u003e\n\u003c/p\u003e\n\nThe goal of this package is to help you to implement the [Health Check API](https://microservices.io/patterns/observability/health-check-api.html) pattern.\n\n## Installation\n\n``` bash\npip install fastapi-health\n```\n\n## Quick Start\n\nCreate the health check endpoint dynamically using different conditions. Each condition is a\ncallable, and you can even have dependencies inside of it:\n\n```python\nfrom fastapi import FastAPI, Depends\nfrom fastapi_health import health\n\n\ndef get_session():\n    return True\n\n\ndef is_database_online(session: bool = Depends(get_session)):\n    return session\n\n\napp = FastAPI()\napp.add_api_route(\"/health\", health([is_database_online]))\n```\n\n## Advanced Usage\n\nThe `health()` method receives the following parameters:\n- `conditions`: A list of callables that represents the conditions of your API, it can return either `bool` or a `dict`.\n- `success_handler`: An optional callable which receives the `conditions` results and returns a dictionary that will be the content response of a successful health call.\n- `failure_handler`: An optional callable analogous to `success_handler` for failure scenarios.\n- `success_status`: An integer that overwrites the default status (200) in case of success.\n- `failure_status`: An integer that overwrites the default status (503) in case of failure.\n\nIt's important to notice that you can have a _peculiar_ behavior in case of hybrid return statements (`bool` and `dict`) on the conditions.\nFor example:\n\n``` Python\nfrom fastapi import FastAPI\nfrom fastapi_health import health\n\n\ndef pass_condition():\n    return {\"database\": \"online\"}\n\n\ndef sick_condition():\n    return False\n\n\napp = FastAPI()\napp.add_api_route(\"/health\", health([pass_condition, sick_condition]))\n```\n\nThis will generate a response composed by the status being 503 (default `failure_status`), because `sick_condition` returns `False`, and the JSON body `{\"database\": \"online\"}`. It's not wrong, or a bug. It's meant to be like this.\n\n## License\n\nThis project is licensed under the terms of the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkludex%2Ffastapi-health","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkludex%2Ffastapi-health","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkludex%2Ffastapi-health/lists"}