Skip to main content

Compose type-safe flows for emergent AI

Reason this release was yanked:

Version reset to 0.x for alpha phase

Project description

ClearFlow

Coverage Status PyPI PyPI Downloads Python License llms.txt

Compose type-safe flows for emergent AI. 100% test coverage, zero dependencies.

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
  • AI-Ready Documentation – llms.txt for optimal coding assistant integration

Quick Start

pip install clearflow

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

AI Assistant Integration

ClearFlow provides comprehensive documentation in llms.txt format for optimal AI assistant support.

Claude Code Setup

Add ClearFlow documentation to Claude Code with one command:

claude mcp add-json clearflow-docs '{
    "type":"stdio",
    "command":"uvx",
    "args":["--from", "mcpdoc", "mcpdoc", "--urls", "ClearFlow:https://raw.githubusercontent.com/artificial-sapience/clearflow/main/llms.txt"]
}'

For IDEs (Cursor, Windsurf), see the mcpdoc documentation.

Direct URL Access

Use these URLs directly in any AI tool that supports llms.txt:

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

curl -LsSf https://astral.sh/uv/install.sh | sh

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.1.tar.gz (55.0 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.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clearflow-1.0.1.tar.gz
  • Upload date:
  • Size: 55.0 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.1.tar.gz
Algorithm Hash digest
SHA256 fb9b960c21e90032701bde828950b6d5dc04a71578a97057875cf9eb7c0ee24a
MD5 523fb536e839e15d97a61c9bbdc186ee
BLAKE2b-256 4ebe099bb68ef32ae59b990f1c46fac6bbfc55177586973fe4acdabde5edc983

See more details on using hashes here.

Provenance

The following attestation bundles were made for clearflow-1.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: clearflow-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d74143671efb3c2e1b4174603a5f6b73c198fa75e33edbb38add9c1c8fda87c1
MD5 278e7ca616e181db044838da41e1f0aa
BLAKE2b-256 a85c17d50cedf7d6d037880fe503dc8a1f3d099cbf8096e67b19e143dbd7ec26

See more details on using hashes here.

Provenance

The following attestation bundles were made for clearflow-1.0.1-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