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.4.0.tar.gz (135.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.4.0-py3-none-any.whl (48.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for stepflow_py-0.4.0.tar.gz
Algorithm Hash digest
SHA256 0ec636c544ae7058e983369aa7888660bce375adf4660f9152c589bf84291ad6
MD5 d77c8251ffd6ba2a3e1218df1d7e94c2
BLAKE2b-256 6554e2c656cc82006de7524188c23868e725adea537d90b73635bc66eaf29bd1

See more details on using hashes here.

Provenance

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

Publisher: release_python.yml on stepflow-ai/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.4.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for stepflow_py-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0807dc821a63bf97aeca6ff37cdc3289002040a90514b8f0ad009b0b69cbfa4f
MD5 0f84147e3f75fda753a5ab3768c0990b
BLAKE2b-256 4e8dbfd59a7651324c26055f233e8f0b7dc0c3459a3f109d00da7abd6e05a52e

See more details on using hashes here.

Provenance

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

Publisher: release_python.yml on stepflow-ai/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