Skip to main content

Fractal Processes

Fractal Processes is a small workflow engine: processes assembled from actions and run against a shared context, so a workflow is data rather than code.

PyPI Version Build Status

Installation

pip install fractal-processes

Background

A Process is an ordered list of Actions, run against a ProcessContext that carries state from one to the next. Actions cover the ordinary things a workflow does — set a value, fetch or store an entity, dispatch a command, publish an event — and control flow is itself made of actions, so branching, loops and sub-processes live inside the process rather than in Python around it.

That is the whole point. A workflow assembled from data can be stored, inspected, and changed without a deploy; a workflow written as a function cannot. The cost is that you give up Python's syntax for the parts that become actions, which is why this is worth reaching for when a workflow is configuration and not worth it when it is just code.

Self-contained by design: this package imports no other Fractal library except fractal-specifications, which it uses to express conditions.

Usage

from fractal_processes import (
    IfElseAction,
    Process,
    ProcessContext,
    SetContextVariableAction,
    SetValueAction,
    field_gt,
)

process = Process([
    SetContextVariableAction(discount=0),
    IfElseAction(
        field_gt("order.total", 100),
        [SetValueAction("discount", 10)],
        [SetValueAction("discount", 0)],
    ),
])

ctx = ProcessContext({"order": {"total": 250}})
process.run(ctx)

ctx["discount"]      # 10
ctx.order.total      # 250 — attribute access works too

ProcessContext supports dotted keys ("order.total") and attribute access, and merges nested dicts rather than replacing them.

Actions

State — SetContextVariableAction, SetValueAction, GetValueAction, ApplyToValueAction, IncreaseValueAction

Entities — AddEntityAction, UpdateEntityAction, FetchEntityAction, FindEntitiesAction, DeleteEntityAction

Messaging — CommandAction, QueryAction, PublishEventAction

Control flow — IfElseAction, WhileAction, ForEachAction, TryExceptAction, SubProcessAction, ParallelAction

Diagnostics — PrintAction, PrintValueAction, RaiseExceptionAction, CreateSpecificationAction

Conditions

Conditions are specifications, built with helpers that read the context:

from fractal_processes import field_equals, field_gt, field_in, has_field, on_field

field_equals("user.role", "admin")
field_gt("order.total", 100)
field_in("status", ["draft", "review"])
has_field("user.email")
on_field("order.lines", lambda lines: len(lines) > 3)

CallableSpecification wraps any callable, for the cases the helpers do not cover.

Async

AsyncProcess and AsyncAction are the awaitable equivalents. Both provide a synchronous wrapper, so an async process can be run from sync code.

Development

make dev-install
make test
make lint
make format

Metadata

Release files for fractal-processes 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fractal-processes 1.1.0
File Size Uploaded Provenance
fractal_processes-1.1.0.tar.gz 48.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fractal-processes 1.1.0
File Interpreter ABI Platform
fractal_processes-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 68.0 kB

Release files / fractal_processes-1.1.0.tar.gz

Download URL fractal_processes-1.1.0.tar.gz
Size 48.2 kB
Tags Source
SHA-256 checksum
How to use checksums
357bc6d5df62bca5a5df1a17137237a300487c0fca627d81e31541bb366b658f
BLAKE2b-256 checksum
How to use checksums
b66e1d8c76ee72e58289eaa413d31a4d0e4fd065861814fba55559029e7b604e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.34.2

Release files / fractal_processes-1.1.0-py3-none-any.whl

Download URL fractal_processes-1.1.0-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b1b21660ec829757ce288a1bac1473eea329a92800eec287f84f402800006da
BLAKE2b-256 checksum
How to use checksums
b0ff840332c2a73b9aa1ef36a58e47883e99b0c3befa6141e8264d15526143f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.34.2

Security for fractal-processes 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page