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

StateSetContextVariableAction, SetValueAction, GetValueAction, ApplyToValueAction, IncreaseValueAction

EntitiesAddEntityAction, UpdateEntityAction, FetchEntityAction, FindEntitiesAction, DeleteEntityAction

MessagingCommandAction, QueryAction, PublishEventAction

Control flowIfElseAction, WhileAction, ForEachAction, TryExceptAction, SubProcessAction, ParallelAction

DiagnosticsPrintAction, 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fractal_processes-1.0.0.tar.gz (47.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fractal_processes-1.0.0-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file fractal_processes-1.0.0.tar.gz.

File metadata

  • Download URL: fractal_processes-1.0.0.tar.gz
  • Upload date:
  • Size: 47.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.34.2

File hashes

Hashes for fractal_processes-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6bbb3a86a1d694bd24b1783eaa484e1991de352cf9ec42b8e6cc40fc99a6a00a
MD5 d781882047035e6cfd28db8c866400dd
BLAKE2b-256 230f0fb7e52bf3dd925d852b0a47ffae174e5c67a299ec403ba87d1fd45099c9

See more details on using hashes here.

File details

Details for the file fractal_processes-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fractal_processes-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eef6715437fb30da25200fa1c8ec8f1df8b7f4cc2eb1f53b4bc7e0f30cee662c
MD5 9a3e8f54c893cd0125b9ade564b6d671
BLAKE2b-256 a657e4c258add700db91d47e5571d91767b4f793f87b59760ef98d3dd82f0726

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.0

2 files

This release

1.0.0 This release

2 files

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