Skip to main content

Compose type-safe flows for emergent AI

Project description

ClearFlow

Coverage Status PyPI PyPI Downloads Python License llms.txt

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

Version Policy

Alpha Phase (0.x.y): ClearFlow is in active development. Breaking changes may occur in any release. Pin exact versions in production:

pip install clearflow==0.1.0  # Pin to exact version

After 1.0.0, we'll follow strict Semantic Versioning.

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-0.1.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-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clearflow-0.1.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-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2a45d2f1e334f2765b092f18f5788a80e44a119beb5b25a6bd4d4676c445d5fe
MD5 148fee2cca5e0254e1b527b7d263fdfe
BLAKE2b-256 4001cba7dcfa5092d850bfaa5806e2cddbffb259631e3ef45fd55e949f82cc2d

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for clearflow-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c489c5a4b5032ce8e4896f72685437c640f1d159f57744c0be4c82171a2a9884
MD5 6a660769e9cb1ce944d48869839ba859
BLAKE2b-256 0fce49be5bdb6e2e119c6f964e7584d224b10b7e5d761de167357f5326ec7ee1

See more details on using hashes here.

Provenance

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