Skip to main content

EOAP HTTP API Health Check

Project description

EOAP OpenAPI Health Check

PyPI - Version PyPI - Python Version

EOAP OpenAPI Health Check provides a shared contract for reporting the health of EOAP services and their dependencies. The contract follows the application/health+json Internet-Draft and exposes it as an OpenAPI 3.1 definition for a conventional GET /health endpoint.

The OpenAPI definition is the source of truth. It is used to generate:

  • Pydantic models, published on PyPI as eoap-api-health-check;
  • a rendered OpenAPI reference for the project documentation; and
  • a reusable API contract for services and tooling in any language.

What the contract describes

A health response has one of three outcomes:

  • pass (including the compatible aliases ok and up) for a healthy service;
  • warn for a service that remains available but has concerns; or
  • fail (including error and down) for an unhealthy service.

Responses can include service metadata, diagnostic notes, links, and checks grouped by dependency or sub-component. Each check can report an observed value, its unit, the observation time, affected endpoints, and diagnostic output.

See the project documentation for the design and usage overview, or inspect the OpenAPI source for the complete contract.

Install the Python models

pip install eoap-api-health-check

The generated models can be used to construct and validate health payloads:

from eoap_api_health_check import ComponentHealth, HealthyResponse, HealthyStatus

health = HealthyResponse(
    status=HealthyStatus.PASS,
    version="1.0.0",
    checks={
        "database:responseTime": [
            ComponentHealth(
                componentType="datastore",
                observedValue=42,
                observedUnit="ms",
                status=HealthyStatus.PASS,
            )
        ]
    },
)

payload = health.model_dump(by_alias=True, mode="json", exclude_none=True)

Property names in Python use snake_case; passing aliases such as componentType is also supported. Serializing with by_alias=True produces the camel-cased names defined by the wire format.

FastAPI integration

Since version 0.3.0, an optional FastAPI extension provides the HealthJSONResponse convenience response. Install it with:

pip install "eoap-api-health-check[fastapi]"

Use the response in a route to serialize a health model as application/health+json and add a default Cache-Control: max-age=60 header:

from fastapi import FastAPI

from eoap_api_health_check import HealthyResponse
from eoap_api_health_check.fastapi import HealthJSONResponse

app = FastAPI()


@app.get("/health", response_class=HealthJSONResponse)
def health() -> HealthJSONResponse:
    return HealthJSONResponse(
        HealthyResponse(
            status="pass",
            version="1.0.0",
            service_id="catalogue-api",
        )
    )

Pass status_code or cache_control to customize the HTTP response. Set cache_control=None to omit the cache header.

Development

Do not edit src/eoap_api_health_check/__init__.py directly: it is regenerated from schemas/openapi.yaml.

With Task installed, run the complete generation and validation workflow with:

task

Useful focused tasks are:

task process_schema         # regenerate the Pydantic models
task generate_openapi_docs  # refresh the documentation artifacts
task serve_docs             # build and serve the documentation locally

License

This project is licensed under the Apache License 2.0.

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

eoap_api_health_check-0.3.0.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

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

eoap_api_health_check-0.3.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file eoap_api_health_check-0.3.0.tar.gz.

File metadata

  • Download URL: eoap_api_health_check-0.3.0.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for eoap_api_health_check-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a1f06dff7429861bd8771629601cf28168888bc9cfc2f2be9294abb183cbb29f
MD5 aa014471c6c9177ff684dc21cfb07c85
BLAKE2b-256 c9a0c9a8359df9fccc32f53d9b16bebeaad8dc602f5b5af5193c68340ca9657f

See more details on using hashes here.

Provenance

The following attestation bundles were made for eoap_api_health_check-0.3.0.tar.gz:

Publisher: package.yaml on Terradue/api-health-check

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file eoap_api_health_check-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for eoap_api_health_check-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 acf89f30613c63838d887fb3f506b01820e1c7845bb56181d8c18dbf011553c1
MD5 dba407dadebbce72714b14efb3f64412
BLAKE2b-256 b41385d6e0c39439aba67d754b656cf3698e8e3c6d0380dda346f014f0944796

See more details on using hashes here.

Provenance

The following attestation bundles were made for eoap_api_health_check-0.3.0-py3-none-any.whl:

Publisher: package.yaml on Terradue/api-health-check

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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