{"library":"py-healthcheck","title":"py-healthcheck: Flask and Tornado Healthcheck Endpoints","description":"py-healthcheck is a Python library that simplifies adding healthcheck and environment dump endpoints to Flask or Tornado web applications. It allows developers to define custom check functions to monitor application dependencies and internal state, exposing their status via a configurable HTTP route. The latest stable version is 1.10.1, though its release cadence appears irregular based on PyPI and GitHub history, with the most recent update in June 2022.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install py-healthcheck"],"cli":null},"imports":["from healthcheck import HealthCheck","from healthcheck import EnvironmentDump","from healthcheck import TornadoHandler"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from flask import Flask\nfrom healthcheck import HealthCheck, EnvironmentDump\nimport os\n\napp = Flask(__name__)\n\nhealth = HealthCheck(app, '/healthcheck')\nenvdump = EnvironmentDump(app, '/environment')\n\ndef redis_available():\n    # Simulate a Redis check\n    # In a real app, you'd connect to Redis here\n    if os.environ.get('MOCK_REDIS_FAILURE') == 'true':\n        return False, \"Redis connection failed (mocked)\"\n    return True, \"redis ok\"\n\ndef database_check():\n    # Simulate a database check\n    # In a real app, you'd check DB connection/query\n    if os.environ.get('MOCK_DB_FAILURE') == 'true':\n        return False, \"Database connection failed (mocked)\"\n    return True, \"database ok\"\n\nhealth.add_check(redis_available)\nhealth.add_check(database_check)\n\ndef application_data():\n    return {\n        \"maintainer\": \"Your Name\",\n        \"git_repo\": \"https://github.com/your/repo\",\n        \"version\": \"1.0.0\"\n    }\n\nenvdump.add_section(\"application\", application_data)\n\n# To run the Flask app (for demonstration, use 'flask run' in production)\nif __name__ == '__main__':\n    # Example usage: http://127.0.0.1:5000/healthcheck\n    # Example usage: http://127.0.0.1:5000/environment\n    app.run(debug=True)","lang":"python","description":"This Flask quickstart demonstrates setting up `/healthcheck` and `/environment` endpoints. Custom functions (`redis_available`, `database_check`) are added to the health check. The `EnvironmentDump` also includes custom application data. Run with `python your_app.py` or `flask run` and access `/healthcheck` and `/environment` in your browser. Set `MOCK_REDIS_FAILURE=true` or `MOCK_DB_FAILURE=true` environment variables to see failure states.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}