π Context
π Context API
Context separates configuration from code β inject parameters into steps without hard-coding values.
ποΈ Parameters π Environments π Overrides
context() Function
from flowyml import context
ctx = context(
dataset_path="data/train.csv",
epochs=50,
learning_rate=0.001,
)
| Parameter | Type | Default | Description |
|---|---|---|---|
**kwargs |
Any |
β | Arbitrary key-value pairs. Keys matching step parameter names are injected automatically. |
Immutable by Design
Once created, a context object is immutable. Use ctx.override() to create a new context with updated values.
Context Methods & Properties
| Method / Property | Signature | Description |
|---|---|---|
override |
override(**kwargs) β Context |
Return a new context with specified keys replaced. Original is unchanged. |
merge |
merge(other: Context) β Context |
Combine two contexts. Values from other take precedence on conflict. |
to_dict |
to_dict() β dict |
Serialize all parameters to a plain dictionary. |
get |
get(key, default=None) |
Retrieve a single parameter value with an optional default. |
pipeline_name |
str (property) |
Name of the pipeline this context is bound to (set at runtime). |
run_id |
str (property) |
Unique identifier for the current pipeline run. |
environment |
str (property) |
Current environment name (e.g., dev, staging, prod). |
Usage Examples
Basic Context
Environment-Specific Configs
Runtime Override via CLI
Override Precedence
Values are resolved in this order (highest priority first):
- CLI
--contextflags β always win pipeline.run(**overrides)β programmatic overridescontext()constructor β base configuration- Step parameter defaults β fallback values
Accessing Context Inside Steps
Autodoc
Pipeline context with automatic parameter injection.
Example
ctx = Context(learning_rate=0.001, epochs=10, batch_size=32, device="cuda")
Source code in flowyml/core/context.py
Functions
__getattr__(name: str) -> Any
Allow dot notation access to parameters.
Source code in flowyml/core/context.py
__getitem__(key: str) -> Any
Allow dict-style access to parameters.
Source code in flowyml/core/context.py
get(key: str, default: Any = None) -> Any
inherit(**overrides) -> Context
inject_params(func: callable) -> dict[str, Any]
Automatically inject parameters based on function signature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
Function to analyze and inject parameters for |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of parameters to inject |
Source code in flowyml/core/context.py
items() -> list[tuple]
keys() -> set[str]
to_dict() -> dict[str, Any]
update(data: dict[str, Any]) -> None
Update context with new data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Dictionary of key-value pairs to add to context |
required |
validate_for_step(step_func: callable, exclude: list[str] = None) -> list[str]
Validate that all required parameters are available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_func
|
callable
|
Step function to validate |
required |
exclude
|
list[str]
|
List of parameter names to exclude from validation (e.g. inputs) |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of missing required parameters |