Skip to main content

Type-safe orchestration for unpredictable AI.

Reason this release was yanked:

Version reset to 0.x for alpha phase

Project description

ClearFlow

Coverage Status PyPI PyPI Downloads type: pyright Ruff Python License

Type-safe orchestration for unpredictable AI.

Why ClearFlow?

  • 100% test coverage – Every path proven to work
  • Type-safe transformations – Errors caught at development time, not runtime
  • Immutable state – No hidden mutations
  • Zero dependencies – No hidden failure modes
  • Single exit enforcement – No ambiguous endings

Installation

pip install clearflow

Upgrading from v0.x? See the Migration Guide for breaking changes.

Examples

Name Description
Chat Simple conversational flow with OpenAI
Portfolio Analysis Multi-specialist workflow for financial analysis
RAG Full retrieval-augmented generation with vector search

Core Concepts

Node[TIn, TOut]

A unit that transforms state from TIn to TOut (or Node[T] when types are the same).

  • prep(state: TIn) -> TIn – optional pre-work/validation
  • exec(state: TIn) -> NodeResult[TOut]required; return new state + outcome
  • post(result: NodeResult[TOut]) -> NodeResult[TOut] – optional cleanup/logging

Nodes are frozen dataclasses that execute async transformations without mutating input state.

NodeResult[T]

Holds the new state and an outcome string used for routing.

flow()

A function that creates a flow with explicit routing:

flow("Name", start_node)
  .route(start_node, "outcome1", next_node)
  .route(next_node, "outcome2", final_node)
  .end(final_node, "done")  # exactly one termination

Routing: Routes are (node, outcome) pairs. Each outcome must have exactly one route.
Type inference: The flow infers types from start to end, supporting transformations.
Composability: A flow is itself a Node – compose flows within flows.

ClearFlow vs PocketFlow

Aspect ClearFlow PocketFlow
State Immutable, passed via NodeResult Mutable, passed via shared param
Routing Outcome-based explicit routes Action-based graph edges
Termination Exactly one exit enforced Multiple exits allowed
Type safety Full Python 3.13+ generics Dynamic (no annotations)

ClearFlow emphasizes robust, type-safe orchestration with validation and guardrails. PocketFlow emphasizes brevity and flexibility with minimal overhead.

Development

# Install uv (if not already installed)
pipx install uv

# Clone and set up development environment
git clone https://github.com/artificial-sapience/ClearFlow.git
cd ClearFlow
uv sync --all-extras     # Creates venv and installs deps automatically
./quality-check.sh       # Run all checks

License

MIT

Acknowledgments

Inspired by PocketFlow's Node-Flow-State pattern.

Project details


Download files

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

Source Distribution

clearflow-1.0.0.tar.gz (55.2 kB view details)

Uploaded Source

Built Distribution

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

clearflow-1.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clearflow-1.0.0.tar.gz
  • Upload date:
  • Size: 55.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clearflow-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c70286fd4adb58f0af354a4acfa2fb4b9c92e702eb1e86a6b0ed94ef3a98d107
MD5 472d22986be059a6b4166d09c5bc92d2
BLAKE2b-256 2d9647281e6943ac1b4c5d4cb0837a49effde96a4e5e25f59eb7e41795db9791

See more details on using hashes here.

Provenance

The following attestation bundles were made for clearflow-1.0.0.tar.gz:

Publisher: release.yml on artificial-sapience/ClearFlow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: clearflow-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clearflow-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8074aca09d1fa84ef9350200aef8fbc4aa5613b069ed9406a6f95903888bfded
MD5 47a3318934c06fad5129261b0b09dea0
BLAKE2b-256 c3cfa78145a26e169919a4383366f5d333a1cef9d6058ccd6d031942444c0a5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for clearflow-1.0.0-py3-none-any.whl:

Publisher: release.yml on artificial-sapience/ClearFlow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page