API reference¶
Everything exported from the top-level masoora package. Generated from the
source, so it always matches the installed version.
Building¶
masoora.PipelineBuilder
¶
Bases: Generic[ContextT]
Chain read/transform/write steps, then build() a validated Pipeline.
Steps may be declared in any order; build() resolves dependencies (DAG topo-sort) and fails fast on unknown inputs, duplicate outputs, or cycles.
Source code in src/masoora/builder.py
with_read_step
¶
with_read_step(
fn: Callable[[ContextT], Any],
*,
output: str,
validate: Validator | None = None,
) -> Self
fn(context) -> dataset, stored at catalog[output].
Source code in src/masoora/builder.py
with_seed
¶
with_seed(
key: str, *, validate: Validator | None = None
) -> Self
Declare a catalog key that will be pre-populated before run().
with_transform_step
¶
with_transform_step(
fn: Callable[..., Any],
*,
inputs: Sequence[str],
output: str,
validate: Validator | None = None,
) -> Self
fn(context, *inputs) -> dataset, stored at catalog[output].
Source code in src/masoora/builder.py
with_write_step
¶
masoora.PipelineContext
¶
Bases: BaseModel
Holds all variables/configuration a pipeline needs.
Users subclass this and declare their own fields:
class MyContext(PipelineContext):
source_url: str
batch_size: int = 100
Running¶
masoora.Pipeline
¶
Pipeline(
steps: Sequence[Step[ContextT]],
validators: Mapping[str, Validator] | None = None,
)
Bases: Generic[ContextT]
A topo-sorted sequence of steps. Built via PipelineBuilder.
Source code in src/masoora/pipeline.py
validators
property
¶
validators: Mapping[str, Validator]
Catalog key -> validator, as declared on the builder.
run
¶
run(
context: ContextT,
catalog: DataCatalog | None = None,
target: str | None = None,
parallel: ParallelMode = False,
executor: Executor | None = None,
) -> DataCatalog
Execute all steps (or only those needed for target) in topo order.
parallel: False (default) runs sequentially; True uses a thread pool
with os.cpu_count() workers; an int sets the worker count. Steps run
concurrently, each starting the instant its own dependencies finish
(dependency-driven scheduling, no level barrier).
executor: caller-provided Executor; wins over parallel and is NOT
shut down by the pipeline.
Source code in src/masoora/pipeline.py
to_mermaid
¶
Render the pipeline as a Mermaid flowchart definition.
Steps are nodes and catalog keys are edge labels; seeded inputs and unconsumed outputs get their own nodes. Paste the result into a ```mermaid fence -- GitHub, MkDocs Material and Jupyter all render it.
target: diagram only the steps needed to produce that key. direction: any Mermaid flowchart direction (TD, LR, ...).
Source code in src/masoora/pipeline.py
to_testable
¶
to_testable(
reads: Mapping[str, Any] | None = None,
*,
mock_writes: bool = True,
target: str | None = None,
) -> TestablePipeline[ContextT]
Return a copy with read steps replaced by fixture data and, optionally, write steps captured instead of executed.
Source code in src/masoora/pipeline.py
masoora.DataCatalog
¶
DataCatalog(
initial: Mapping[str, Any] | None = None,
validators: Mapping[str, Validator] | None = None,
)
Bases: MutableMapping[str, Any]
Holds datasets produced and consumed by pipeline steps.
Values are unconstrained: polars/pandas/spark dataframes, dicts, models, etc.
A key may carry a validator. Values are checked when written and when read, so data that never passed through a step -- seeded keys, fixtures supplied by to_testable() -- is checked too. Each value is checked once: a read after a validated write does not repeat the work.
Source code in src/masoora/catalog.py
Validation¶
Steps¶
masoora.ReadStep
dataclass
¶
Bases: Generic[ContextT]
fn(context) -> dataset, stored at catalog[output].
masoora.TransformStep
dataclass
¶
Bases: Generic[ContextT]
fn(context, *inputs) -> dataset, stored at catalog[output].
Source code in src/masoora/steps.py
masoora.WriteStep
dataclass
¶
Testing¶
masoora.TestablePipeline
¶
TestablePipeline(
steps: Sequence[Step[ContextT]],
*,
mock_writes: bool,
validators: Mapping[str, Validator] | None = None,
)
Bases: Generic[ContextT]
A pipeline with mocked reads/writes; run() returns a TestRunResult.
Source code in src/masoora/pipeline.py
masoora.TestRunResult
dataclass
¶
TestRunResult(
catalog: DataCatalog, written: dict[str, Any] = dict()
)
Bases: Generic[ContextT]
Result of running a TestablePipeline.
catalog: full data catalog after the run (assert on any key). written: input key -> dataset for every mocked write step.
masoora.make_pipeline_fixture
¶
make_pipeline_fixture(
pipeline: Pipeline[ContextT],
context: ContextT | Callable[[], ContextT],
reads: Mapping[str, Any] | None = None,
*,
mock_writes: bool = True,
target: str | None = None,
) -> Callable[[], TestRunResult[ContextT]]
Create a pytest fixture that runs the pipeline with mocked IO.
Usage
run_pipeline = make_pipeline_fixture( my_pipeline, MyContext(url="test"), reads={"raw": fake_df} )
def test_output(run_pipeline: TestRunResult[MyContext]) -> None: assert "clean" in run_pipeline.catalog
Source code in src/masoora/testing.py
Errors¶
masoora.PipelineError
¶
Bases: Exception
Base class for all masoora errors.
masoora.PipelineValidationError
¶
Bases: PipelineError
Raised at build time when the pipeline definition is invalid.
masoora.PipelineCycleError
¶
Bases: PipelineValidationError
Raised at build time when steps form a dependency cycle.
Source code in src/masoora/errors.py
masoora.DataValidationError
¶
Bases: PipelineError
Raised when a catalog value fails the validator declared for its key.