Skip to main content

A type-safe, async-first flow-based programming framework for Python

Project description

Flokkit Flow

A type-safe, async-first flow-based programming (FBP) framework for Python with zero dependencies.

Features

  • 🔒 Type-safe - Full type safety across the entire flow graph
  • Async-first - Built on asyncio with automatic sync function adaptation
  • 🚦 Backpressure - Bounded queues with configurable strategies
  • 🔄 DAG Safety - Automatic cycle detection prevents deadlocks
  • 📦 Zero Dependencies - Pure Python, no external packages required
  • 🔌 Lifecycle Hooks - Proper resource management with init/cleanup
  • 🏭 Flexible Patterns - Support for both pipeline and server patterns
  • 🎯 Middleware System - Extensible processing pipeline with logging, metrics, throttling, and retry support

Installation

pip install flokkit-flow

Documentation

Full documentation is available at: https://flokkit.gitlab.io/flow/

Quick Install

# Using uv (replace {project_id} with actual ID)
# From source
uv pip install git+https://gitlab.com/flokkit/flow.git

For Development

# Clone and install in editable mode
git clone https://gitlab.com/flokkit/flow.git
cd flow
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"

Quick Start

from flow import flow

# Build a simple pipeline
async def main():
    builder = flow("My Pipeline")
    
    def generate_numbers():
        return 42
    
    def double(x):
        return x * 2
    
    def print_result(x):
        print(f"Result: {x}")
    
    # Connect the nodes
    (builder
        .source(generate_numbers, int)
        .transform(double, int)
        .to(print_result))
    
    # Run the pipeline
    await builder.execute(duration=1.0)

# Run it
import asyncio
asyncio.run(main())

Using Middleware

from flow import flow, LoggingMiddleware, MetricsMiddleware

async def main():
    # Create middleware instances
    logger = LoggingMiddleware()
    metrics = MetricsMiddleware()
    
    # Build pipeline with middleware
    builder = flow("Monitored Pipeline")
    
    results = []
    await (
        builder
        .with_middleware(logger, metrics)  # Add middleware to all nodes
        .source(lambda: [1, 2, 3, 4, 5], int)
        .filter(lambda x: x % 2 == 0)
        .transform(lambda x: x ** 2, int)
        .to(results.append)
        .execute(duration=1.0)
    )
    
    print(f"Results: {results}")
    print(f"Metrics: {metrics.get_metrics()}")

asyncio.run(main())

Examples

See the examples/ directory for comprehensive examples:

  • Basic flows and transformations
  • Backpressure and queue strategies
  • Split/merge patterns
  • Async I/O and blocking operations
  • Pipeline vs server patterns
  • Lifecycle management

Development

This project uses just for development commands and uv for fast dependency management.

# Install tools
curl -LsSf https://astral.sh/uv/install.sh | sh  # Install uv
brew install just                                 # Install just (macOS)

# Set up development environment
uv venv                    # Create virtual environment
source .venv/bin/activate  # Activate it
just install-dev          # Install all dev dependencies

# Development commands
just                      # List all commands
just test                 # Run tests
just typecheck           # Run type checker
just check               # Run all checks
just example 1           # Run specific example

Common Commands

# Development workflow
just dev          # Run checks and watch for changes
just test         # Run tests (auto-detects pytest)
just typecheck    # Run basedpyright
just check        # Run all checks

# Examples
just example      # List examples
just example 5    # Run example 5
just examples     # Run all examples

# Utilities
just clean        # Clean generated files
just stats        # Show project statistics

Documentation

Building Documentation Locally

Flokkit Flow uses Sphinx for documentation with the modern Python documentation toolchain:

# Install documentation dependencies
just install-docs

# Build documentation
just docs-build

# Serve with auto-reload for development
just docs-serve

# Open in browser
just docs-open

Documentation Structure

  • Getting Started: Installation, quickstart, and core concepts
  • User Guide: In-depth guides for common use cases
  • API Reference: Complete API documentation with examples
  • Examples: Practical examples with explanations

Online Documentation

Documentation is automatically built and hosted on Read the Docs (when published).

License

MIT

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

flokkit_flow-0.2.1.tar.gz (38.8 kB view details)

Uploaded Source

Built Distribution

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

flokkit_flow-0.2.1-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

Details for the file flokkit_flow-0.2.1.tar.gz.

File metadata

  • Download URL: flokkit_flow-0.2.1.tar.gz
  • Upload date:
  • Size: 38.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for flokkit_flow-0.2.1.tar.gz
Algorithm Hash digest
SHA256 eb4810279b1d3cc41f3458c00d3710556610ab31acbdcfd0f9990ca144ce2695
MD5 2dfa82f12bfa4017361bb3af9e761f52
BLAKE2b-256 94600f86f026d6bee4569349c5e594fa1d7d0414c90ffaf2e72aaa4affcf4e85

See more details on using hashes here.

File details

Details for the file flokkit_flow-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: flokkit_flow-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for flokkit_flow-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 71e57df14f9de1f6ffb8f93773d9bde78416b402a12ed102ea792e01c4043aed
MD5 b74d1608a61d28377b11beca3caf4e56
BLAKE2b-256 ac23343cfb55a70bc2c5fc6cee5e1915a5f379ff9124c196deaaab915babb0e4

See more details on using hashes here.

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