Python authoring¶
uptimely.spec.python provides declarations that convert to the
spec document model. The sections below follow the
authoring modules in the source tree.
For a runnable example, see the analytics project structure.
spec¶
uptimely.spec.python.spec groups declarations into a
PythonSpec definition.
Python-friendly spec declarations.
PythonSpec
dataclass
¶
Build a spec document from Python authoring declarations.
entities
class-attribute
instance-attribute
¶
entities: list[Entity] = dataclasses.field(default_factory=list)
dimensions
class-attribute
instance-attribute
¶
dimensions: list[Dimension] | dict[str, Dimension] | None = None
iter_datasets
¶
iter_datasets() -> list[dataset_module.Dataset]
Yield all dataset declarations owned by this spec model.
function_catalog
¶
function_catalog() -> spec_model.FunctionCatalog
Collect and merge the function catalog across all entities.
to_model
¶
to_model() -> spec_model.Spec
Return the spec document model without resolving entrypoints.
entity¶
uptimely.spec.python.entity groups related datasets.
Python-friendly entity declaration.
Entity
dataclass
¶
A named entity containing datasets and their dimensions.
dataset¶
uptimely.spec.python.dataset declares datasets and their features.
Python-friendly dataset declaration.
RowScope
dataclass
¶
The conceptual row subset represented by a dataset.
Order
dataclass
¶
Declare a logical ordering key, not a required physical sort.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension
|
Reference | str
|
A dimension reference created by |
required |
direction
|
Literal['asc', 'desc']
|
Ascending ( |
required |
Dataset
dataclass
¶
A Python declaration of one dataset, its features, and mappings.
features
class-attribute
instance-attribute
¶
features: list[Feature] = dataclasses.field(default_factory=list)
mappings
class-attribute
instance-attribute
¶
mappings: list[Mapping] = dataclasses.field(default_factory=list)
row_scope
class-attribute
instance-attribute
¶
row_scope: RowScope = dataclasses.field(default_factory=RowScope)
order
class-attribute
instance-attribute
¶
order: list[Order] = dataclasses.field(default_factory=list)
to_model
¶
to_model() -> spec_model.Dataset
Convert this declaration to the Pydantic dataset document model.
function_catalog
¶
function_catalog() -> spec_model.FunctionCatalog
Build the function templates required by this dataset declaration.
dimension¶
uptimely.spec.python.dimension declares shared dimensions.
Python-friendly dimension declaration.
Dimension
dataclass
¶
A reusable dataset-grain identifier.
feature¶
uptimely.spec.python.feature declares dataset features and calculations.
Python-friendly dataset feature declarations.
Feature
dataclass
¶
Metadata for a dataset feature, independent of how it is produced.
mappings¶
uptimely.spec.python.mappings declares relationships between datasets.
It is also exposed as uptimely.spec.mapping.
Python-friendly dataset mapping declarations.
Mapping
dataclass
¶
A function binding that produces one or more declared dataset features.
inputs
class-attribute
instance-attribute
¶
inputs: list[Reference | str] = dataclasses.field(default_factory=list)
outputs
class-attribute
instance-attribute
¶
outputs: list[Feature | Reference | str] = dataclasses.field(default_factory=list)
row_context
class-attribute
instance-attribute
¶
row_context: RowContext | RowContextBinding[Any] | None = None
operation
property
¶
operation: FunctionOperation
Return the operation declared by this mapping's function reference.
bind¶
uptimely.spec.python.bind binds function arguments to declared values.
Python-friendly function bindings.
Bind
dataclass
¶
bind
¶
bind(function: FunctionReference, /, function_id: str | None = None, **args: Any) -> Bind
Bind named arguments to a function reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
FunctionReference
|
A reference created with |
required |
function_id
|
str | None
|
Optional catalog identifier. |
None
|
**args
|
Any
|
Actual function arguments, optionally annotated with row context. |
{}
|
Returns:
| Type | Description |
|---|---|
Bind
|
A declaration preserving primitive arguments and separate metadata. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If function is not a reference created with |
ref¶
uptimely.spec.python.ref builds references to functions and spec
objects.
Function references accept validate_signature, defaulting to True.
Conversion preserves it in the function catalog and exported JSON. When
False, compilation and documentation do not import the implementation or
inspect its signature. Spec-level contracts and declared feature dependencies
are still validated, and execution still requires a loadable implementation.
Use an entrypoint string when the implementation must not be imported while loading the Python spec:
ref.function(
"other_project.functions:calculate",
operation="vectorize",
validate_signature=False,
)
Python spec declarations execute during source loading. Do not import an unavailable analytical implementation from the declaration module itself; pass its entrypoint as a string instead.
Python-friendly structural references and reference factories.
FunctionReference
dataclass
¶
A function location normalized without importing or executing its module.
Reference
dataclass
¶
A Python declaration reference resolved to a structural binding value.
function
¶
function(function: Callable[..., object] | str, *, operation: FunctionOperation | None = None, validate_signature: bool = True) -> FunctionReference
Reference a callable or a module:function entrypoint string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
Callable[..., object] | str
|
A named Python callable such as |
required |
operation
|
FunctionOperation | None
|
Optional operation metadata for generic mapping declarations. |
None
|
validate_signature
|
bool
|
Whether compilation and documentation should inspect the Python signature and validate implementation contracts. |
True
|
Returns:
| Type | Description |
|---|---|
FunctionReference
|
A reference containing the module location and function name. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the argument is neither callable nor a string, or validate_signature is not a boolean. |
ValueError
|
If the entrypoint is invalid or the callable has no valid module and function name, or if operation is unsupported. |
source
¶
source(name: str, attribute: str = 'path') -> str
Reference a runtime-configured source attribute by name.
sink
¶
sink(name: str, attribute: str = 'path') -> str
Reference a runtime-configured sink attribute by name.
row_context¶
uptimely.spec.python.row_context declares row windows for functions.
The runtime value is documented under row context.
Annotate bound values with observation requirements, not function types.
RowContextBinding
dataclass
¶
time
¶
time(value: T, *, dimension: Reference | str, before: str = '0s', after: str = '0s') -> RowContextBinding[T]
Bind a value with preceding/following fixed-time requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
The original argument, without conversion to a duration. |
required |
dimension
|
Reference | str
|
Datetime dimension along which the window is measured. |
required |
before
|
str
|
Required preceding duration, or |
'0s'
|
after
|
str
|
Required following duration, or |
'0s'
|
Returns:
| Type | Description |
|---|---|
RowContextBinding[T]
|
A binding annotation that is unwrapped during Spec conversion. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an extent is not a supported fixed duration. |
steps
¶
steps(value: T, *, dimension: Reference | str, before: CountExtent = 0, after: CountExtent = 0) -> RowContextBinding[T]
Bind a value with integer-coordinate distances, not observation counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
The unchanged function argument. |
required |
dimension
|
Reference | str
|
Integer dimension along which distance is measured. |
required |
before
|
CountExtent
|
Preceding coordinate distance, or |
0
|
after
|
CountExtent
|
Following coordinate distance, or |
0
|
Returns:
| Type | Description |
|---|---|
RowContextBinding[T]
|
The argument annotated with its context requirements. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a bound is not a nonnegative integer or |
rows
¶
rows(value: T, *, before: CountExtent = 0, after: CountExtent = 0) -> RowContextBinding[T]
Bind a value with ordered observation-count requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
The unchanged function argument. |
required |
before
|
CountExtent
|
Preceding observation count, or |
0
|
after
|
CountExtent
|
Following observation count, or |
0
|
Returns:
| Type | Description |
|---|---|
RowContextBinding[T]
|
The argument annotated with its context requirements. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a bound is not a nonnegative integer or |
current
¶
current() -> row_context.RowContext
Declare that only the current observation is required.
conversion¶
uptimely.spec.python.conversion converts declarations to document model
objects. Use api.from_python
to convert and semantically validate in one operation.
Convert Python declarations to the spec document format.
to_dict
¶
to_dict(datasets: Datasets | None = None, functions: Functions | None = None, name: str | None = None, dimensions: Dimensions | None = None, *, entities: Entities | None = None) -> dict[str, typing.Any]
Encode Python declarations using the same codec as JSON file exports.
to_model
¶
to_model(datasets: Datasets | None = None, functions: Functions | None = None, name: str | None = None, dimensions: Dimensions | None = None, *, entities: Entities | None = None) -> spec_model.Spec
Build structural spec without importing function entrypoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasets
|
Datasets | None
|
Datasets wrapped in a single entity named after |
None
|
functions
|
Functions | None
|
Explicit function catalog, or infer it from declarations. |
None
|
name
|
str | None
|
Optional spec display name. |
None
|
dimensions
|
Dimensions | None
|
Global dimension declarations. |
None
|
entities
|
Entities | None
|
Explicit entities, mutually exclusive with |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
No declarations were supplied or function definitions conflict. |
TypeError
|
A resource is not a supported declaration or document model. |