Skip to content

Spec operations

uptimely.spec.api provides functions to load a Spec or convert Python declarations.

from_python accepts a sequence of Python profile declarations.

For loading and compilation examples, see Work with Spec documents.

api

Build and load validated spec through explicit application operations.

load_spec

load_spec(path: str | Path, *, validate: bool = True, log_structure: bool = True) -> model.Spec

Load a spec JSON file or directory, optionally validating its semantics.

Parameters:

Name Type Description Default
path str | Path

A JSON document or a directory containing spec.json.

required
validate bool

Run semantic checks. Structural parsing is always required.

True
log_structure bool

Emit structural validation debug messages.

True

Returns:

Type Description
Spec

A structurally parsed spec document with reusable cached views.

Raises:

Type Description
OSError

The JSON document cannot be read.

ValueError

The document or its spec declarations are invalid.

load_python_spec

load_python_spec(source: Entrypoint, *, validate: bool = True) -> model.Spec

Resolve a Python declaration and convert it to a spec document.

Parameters:

Name Type Description Default
source Entrypoint

Entrypoint addressing a Python Spec declaration.

required
validate bool

Run semantic checks. Structural conversion always runs.

True

Returns:

Type Description
Spec

A structurally parsed spec document with reusable cached views.

Raises:

Type Description
TypeError

The entrypoint does not resolve to a Python Spec declaration.

from_python

from_python(profiles: Sequence[Profile] | None = None, functions: Functions | None = None, name: str | None = None, *, validate: bool = True) -> model.Spec

Convert Python declarations, optionally validating the model's semantics.

Parameters:

Name Type Description Default
profiles Sequence[Profile] | None

A sequence of Python profile declarations with globally unique IDs.

None
functions Functions | None

Explicit catalog, or infer it from Python declarations.

None
name str | None

Optional spec name.

None
validate bool

Run semantic checks. Declaration and structural checks always run.

True

Returns:

Type Description
Spec

A structurally parsed spec document with reusable cached views.

Raises:

Type Description
TypeError

Declarations have unsupported types.

ValueError

Declarations conflict or spec semantics are invalid.