Skip to content

service_info

Service info as per the GA4GH service-info specification (version 1.0.0), served at GET /service-info from the configuration, without a database and without code of your own:

service_info:
  package: my-app
  runtime_fields: my_app.service_info.runtime_fields
  service:
    id: org.example.my-service
    name: My service
    type:
      group: org.ga4gh
      artifact: wes
      version: 1.1.0
    description: Runs workflows.
    organization:
      name: Example
      url: https://example.org
    contactUrl: mailto:support@example.org
    documentationUrl: https://docs.example.org
    environment: prod
    # Optional; served only if set
    createdAt: "2026-10-20T00:00:00Z"
    updatedAt: "2026-10-20T00:00:00Z"

service is the service info itself: id, name, type, organization and version are required, the other fields of the GA4GH Service schema are optional and only served if set (including createdAt and updatedAt, which must be RFC 3339 date-times), and any other fields (e.g., x-logo) are served as they are.

Serving the service info

Route the GET /service-info operation of your API specification to FOCA's controller, foca.api.service_info.getServiceInfo:

api/openapi.yaml
paths:
  /service-info:
    get:
      operationId: getServiceInfo
      x-openapi-router-controller: foca.api.service_info
      security: []
      responses:
        '200':
          description: Service info
          content:
            application/json:
              schema:
                # Or the GA4GH `Service` schema
                type: object

The controller set on the operation takes precedence over one added to all operations via add_operation_fields. Without such a field, a full operationId: foca.api.service_info.getServiceInfo works as well. GA4GH API specifications usually define the operation already, with operationId: GetServiceInfo (e.g., WES and TES) or getServiceInfo (e.g., the service-info specification itself). FOCA's controller is available under both names, so it is enough to add x-openapi-router-controller, e.g., in a merged file. security: [] makes the service info public; leave it out if your specification requires authentication for it.

If an operation is routed to getServiceInfo, but service_info is not configured, the app refuses to start (Foca.create_app() raises a foca.api.service_info.InvalidServiceInfo naming the routes).

Requests for the service info and their responses are logged (cf. log_traffic); set log_traffic: false to not log them, e.g., if health checks or monitoring poll the service info:

service_info:
  log_traffic: false
  service: ...

Do not wrap FOCA's controller with your own log_traffic (e.g., in a controller of your own calling it); use service_info.log_traffic instead, as requests are otherwise logged twice.

Version

version is the version of the deployed app. Set package to the name of your app's distribution package (as installed, e.g., with pip install, and as in the name of its pyproject.toml) to serve its version, unless service.version is set. The package must then be installed; otherwise the app refuses to start. version: null (e.g., in a config overlay, or returned by the runtime_fields function) counts as not set, so the version is then taken from the next source (the function, then package).

Fields computed at runtime

For fields that are only known at runtime (e.g., from the environment, or from other services), set runtime_fields to the dotted path of a function that returns them as a dictionary:

my_app/service_info.py
import os


def runtime_fields() -> dict:
    return {"environment": os.environ.get("DEPLOYMENT", "dev")}

The function is called without arguments, in an app context (e.g., with access to get_config()), on startup and for each request; keep it fast. FOCA does not time it out, so if it calls other services, set timeouts on those calls (or cache their results), so that a slow service neither delays startup nor ties up workers. Fields are taken, in order of precedence, from service, the function and the package version. Fields and list items set to null (e.g., in a config overlay) are removed, also if the function or the package set them (except for version, cf. above). Exceptions raised by the function are raised as foca.api.service_info.InvalidServiceInfo (with the original exception as its cause).

Locked fields

Fields in service take precedence over those of the function, so that a config overlay can override them. That isn't what you want for fields that the app computes, e.g., from its configuration, as they would then be wrong. List these in locked_fields:

service_info:
  runtime_fields: my_app.service_info.runtime_fields
  locked_fields:
    - registration_rules

The app then refuses to start if service sets one of them (also to null), or if runtime_fields is not set, and the service info fails if the function doesn't return them (or returns null). Fields are top-level fields only. By default, no fields are locked.

Validation

The service info is validated against the Service schema of the GA4GH service-info specification, version 1.0.0, which is bundled with FOCA:

  • When the configuration is validated, the configured fields (and the package version) raise a pydantic.ValidationError naming the first invalid field, e.g., Invalid service info in `service_info.service.organization.url`: 'example.org' is not a 'uri'. Required fields may be missing if runtime_fields is set.
  • When the app is created (Foca.create_app()), the complete service info, including the fields computed at runtime, raises a foca.api.service_info.InvalidServiceInfo (a ValueError) if invalid, so the app refuses to start.
  • On each request, service info that has become invalid (via the function), or a failing function, is not served; the request fails with a generic 500 Internal Server Error (also if your app maps ValueError to other problem details; unless it maps foca.errors.InternalServerError itself), and the error is logged.

The service info must also be serializable as JSON (e.g., no dates as values: quote date-times in YAML, and return them as strings from the function).

Use foca.api.service_info.get_service_info() to get the service info of the current app in your own code.

Placeholders

Templates (such as FOCA's templates/config.yaml) describe services with reserved example domains (RFC 2606), which deployments replace. When the app is created, FOCA logs a warning naming the fields of the service info (including fields computed at runtime) that still have such values:

  • id, if it is in such a domain in reverse domain name notation, i.e., starts with com.example, net.example, org.example or example. (e.g., org.example.my-service);
  • organization.url, contactUrl and documentationUrl, if their host (for mailto: URLs, the domain of the address) is example.com, example.net, example.org or a subdomain of one, or in the top-level domain example (e.g., https://docs.example.org, mailto:support@example.org).

FOCA also logs a warning if the service info reports the placeholder version 0.0.0.dev0, as clients then can't tell which version is deployed.

The app still starts. Set these fields to describe the deployment, e.g., in a config overlay.

Migrating an app

Upgrading an app that used service_info as a section of its own? See Migrating to 0.15.0.

Apps that implemented the service info themselves, e.g., with POST /service-info storing it in a database, can serve it from the configuration instead:

  1. Move the service info into service_info.service of the configuration (e.g., from a custom section or the database). Set package instead of service.version to serve the app's version, and move code computing fields into a runtime_fields function.
  2. Route GET /service-info to foca.api.service_info.getServiceInfo (cf. above), and remove the POST /service-info operation from your API specification.
  3. Remove your controllers for GET and POST /service-info, any code checking or storing the service info, and its database collection from db (drop the collection from existing databases if you like; stored service info is no longer served).
  4. Start the app: invalid service info now fails startup, naming the invalid field. To change the service info, change the configuration and restart the app.

ServiceInfoConfig

Bases: FOCABaseConfig

Model for the GA4GH service info of an app.

The service info is served by :py:func:foca.api.service_info.getServiceInfo (GET /service-info), built from, in order of precedence, service, the fields returned by runtime_fields, and the version of package. Fields and list items set to None (e.g., in config overlays) are removed, also if set at a lower precedence, except for version, which is then taken from the next source. The service info must be valid as per the Service schema of the GA4GH service-info specification, version 1.0.0.

Parameters:

Name Type Description Default
service

Service info, as per the GA4GH Service schema, e.g., with id, name, type, organization and version (required) and description, contactUrl, documentationUrl, environment, createdAt and updatedAt (optional, served only if set). Other fields are served as they are.

required
package

Name of the app's distribution package (as installed, e.g., with pip install), whose version is served as version, unless service sets version (to a value other than None). The package must then be installed.

required
runtime_fields

Path to a function returning a dictionary of fields that are computed at runtime, as a dot-separated path to the module, followed by the name of the function, e.g., my_app.service_info.runtime_fields (must be importable). It is called without arguments, in an app context, on startup and for each request. Required fields that it returns may be missing from service.

required
log_traffic

Whether requests for the service info and their responses are logged (cf. :py:func:foca.utils.logging.log_traffic).

required
locked_fields

Names of top-level fields that only runtime_fields may set, e.g., as they are computed from the config, so that service can't override them. The function must return them.

required

Attributes:

Name Type Description
service dict[str, Any]

Service info, as per the GA4GH Service schema.

package str | None

Name of the app's distribution package.

runtime_fields str | None

Path to a function returning fields that are computed at runtime.

log_traffic bool

Whether requests for the service info and their responses are logged.

locked_fields list[str]

Names of top-level fields that only runtime_fields may set.

package_version str | None

Version of package, if used for version (set on validation).

runtime_function Callable[[], Mapping[str, Any]] | None

Function imported from runtime_fields, if set (set on validation).

Raises:

Type Description
ValidationError

The class was instantiated with an illegal data type, package is not installed although needed, the function cannot be imported, or the service info is invalid (when runtime_fields is set, required fields are only checked on startup).

Examples:

>>> service_info = ServiceInfoConfig(
...     service={
...         "id": "org.example.my-service",
...         "name": "My service",
...         "type": {
...             "group": "org.example",
...             "artifact": "my-api",
...             "version": "1.0.0",
...         },
...         "organization": {
...             "name": "Example",
...             "url": "https://example.org",
...         },
...         "version": "1.0.0",
...     },
... )
>>> service_info.service["version"]
'1.0.0'
>>> service_info.package is None
True