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

Uploaded Python 3

File details

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

File metadata

  • Download URL: stepflow_py-0.2.1.tar.gz
  • Upload date:
  • Size: 98.5 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.1.tar.gz
Algorithm Hash digest
SHA256 f462c6cccad113886934e0aa9a0d4c67938a92a737751b2d62856c00d4af4171
MD5 5a20207c12392ac683acecb28a6638a1
BLAKE2b-256 918a9e12b0d917a2244d8dbdffd10d9522872daeb2d04d90553feeca34d43e16

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: stepflow_py-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 34.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 43b81398d4388721a6a4628ac2a1aa4090e556a079c1442fb4f686b48fb1e1fd
MD5 15cb1db0b32a43dec9fc12a1bdc33a5f
BLAKE2b-256 97ad467186adef6ef5ef907df642e9b753971f113a95692cf60007e08d178675

See more details on using hashes here.

Provenance

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