Skip to main content

Python SDK for Stepflow components and workflows.

Project description

StepFlow Python SDK

Python SDK for building StepFlow components and workflows.

Installation

# Install from source
uv add stepflow-py

Usage

Creating a Component Server

from stepflow_py import StepflowStdioServer, StepflowContext
import msgspec

# Define input/output types
class MyInput(msgspec.Struct):
    message: str
    count: int

class MyOutput(msgspec.Struct):
    result: str

# Create server
server = StepflowStdioServer()

# Register a component
@server.component
def my_component(input: MyInput) -> MyOutput:
    return MyOutput(result=f"Processed: {input.message} x{input.count}")

# Component with context (for blob operations)
@server.component
async def component_with_context(input: MyInput, context: StepflowContext) -> MyOutput:
    # Store data as a blob
    blob_id = await context.put_blob({"processed": input.message})
    return MyOutput(result=f"Stored blob: {blob_id}")

# Run the server
if __name__ == "__main__":
    server.run()

Using the Context API

The StepflowContext provides bidirectional communication with the StepFlow runtime:

# Store JSON data as a blob
blob_id = await context.put_blob({"key": "value"})

# Retrieve blob data
data = await context.get_blob(blob_id)

# Logging
context.log("Debug message")

Development

Running Tests

uv run pytest

Type Checking

uv run mypy src/

Protocol Generation

This SDK uses auto-generated protocol types from the JSON schema. To regenerate the protocol types when the schema changes:

uv run python generate.py

The generation script automatically handles the generation and applies necessary fixes for msgspec compatibility.

Project Structure

  • src/stepflow_py/ - Main SDK code
    • generated_protocol.py - Auto-generated protocol types from JSON schema
    • protocol.py - Hybrid protocol layer with envelope patterns for efficient deserialization
    • server.py - Component server implementation
    • context.py - Runtime context API
    • exceptions.py - SDK-specific exceptions
  • tests/ - Test suite

Architecture

The SDK uses a hybrid approach for protocol handling:

  1. Generated Types (generated_protocol.py) - Auto-generated from the StepFlow JSON schema using datamodel-code-generator
  2. Protocol Layer (protocol.py) - Combines generated types with manual envelope patterns for two-stage deserialization using msgspec.Raw
  3. Server Implementation - Uses the protocol layer for efficient JSON-RPC message handling

This design provides:

  • Type Safety - All protocol messages use properly typed structs
  • Schema Consistency - Generated types match the Rust protocol exactly
  • Performance - Two-stage deserialization with msgspec.Raw for optimal speed
  • Maintainability - Protocol changes can be regenerated automatically

License

Licensed under the Apache License, Version 2.0.

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

stepflow_py-0.2.2.tar.gz (99.1 kB view details)

Uploaded Source

Built Distribution

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

stepflow_py-0.2.2-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

File details

Details for the file stepflow_py-0.2.2.tar.gz.

File metadata

  • Download URL: stepflow_py-0.2.2.tar.gz
  • Upload date:
  • Size: 99.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for stepflow_py-0.2.2.tar.gz
Algorithm Hash digest
SHA256 aab9dc19970ca9b0b64acded1c60bd13891f6fca9cd3a7c6c6e307c84ec073a8
MD5 71b64351952b4d716e479b0002a190be
BLAKE2b-256 d4cd91a50c9b576c6f1c7133de0e266af04290d1f22ae0d68a7c48b8fd146b39

See more details on using hashes here.

Provenance

The following attestation bundles were made for stepflow_py-0.2.2.tar.gz:

Publisher: release_python.yml on riptano/stepflow

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

File details

Details for the file stepflow_py-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: stepflow_py-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 35.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for stepflow_py-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7cd7c5862f6b57bfa21fceb464fb3adc2af6ab453a0006240d9e3b289c2fff27
MD5 f124f7e0c44e56e894357492293f1042
BLAKE2b-256 e84bcf5f2e820b25ac00f3584b5f2645c9057c8272c9be81d3c9851e01ef3e83

See more details on using hashes here.

Provenance

The following attestation bundles were made for stepflow_py-0.2.2-py3-none-any.whl:

Publisher: release_python.yml on riptano/stepflow

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