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.3.tar.gz (99.3 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.3-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stepflow_py-0.2.3.tar.gz
  • Upload date:
  • Size: 99.3 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.3.tar.gz
Algorithm Hash digest
SHA256 e1d2acb8af7c50777f4c94c90eeb4f8e06347a0bf1f64c2cfe7d630422ef36a8
MD5 75756f49908db8da866f8d99aed75581
BLAKE2b-256 1f1625afb9f5261c09360b29103045489726731d154ec531c6005d66670250c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for stepflow_py-0.2.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: stepflow_py-0.2.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 58a927120da71b915d37a1377daee0ea110d2e56bc9b9faa48f8a9b0770b2839
MD5 2c3ae31f2334e28d682146f9a714d8e7
BLAKE2b-256 09bcdbe689b7d8add9eefcf86d6e598fc1c52d9d1cdf01d09a55fa85011c91b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for stepflow_py-0.2.3-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