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 codegenerated_protocol.py- Auto-generated protocol types from JSON schemaprotocol.py- Hybrid protocol layer with envelope patterns for efficient deserializationserver.py- Component server implementationcontext.py- Runtime context APIexceptions.py- SDK-specific exceptions
tests/- Test suite
Architecture
The SDK uses a hybrid approach for protocol handling:
- Generated Types (
generated_protocol.py) - Auto-generated from the Stepflow JSON schema usingdatamodel-code-generator - Protocol Layer (
protocol.py) - Combines generated types with manual envelope patterns for two-stage deserialization usingmsgspec.Raw - 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.Rawfor optimal speed - Maintainability - Protocol changes can be regenerated automatically
License
Licensed under the Apache License, Version 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stepflow_py-0.3.0.tar.gz.
File metadata
- Download URL: stepflow_py-0.3.0.tar.gz
- Upload date:
- Size: 133.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51463cc8b142b0af1b0c6950d1ea70d79ce006d91a5d844f0da7736982ed1bb2
|
|
| MD5 |
18ac11faf3c58d9264ccd94b9aa44105
|
|
| BLAKE2b-256 |
e461efbfada026a04f65e254753abff7d5eca82f8b03555f84d77563942a61fb
|
Provenance
The following attestation bundles were made for stepflow_py-0.3.0.tar.gz:
Publisher:
release_python.yml on stepflow-ai/stepflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stepflow_py-0.3.0.tar.gz -
Subject digest:
51463cc8b142b0af1b0c6950d1ea70d79ce006d91a5d844f0da7736982ed1bb2 - Sigstore transparency entry: 431857071
- Sigstore integration time:
-
Permalink:
stepflow-ai/stepflow@34da123fae53d80af9e6ef778a110935d9265b34 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/stepflow-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release_python.yml@34da123fae53d80af9e6ef778a110935d9265b34 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file stepflow_py-0.3.0-py3-none-any.whl.
File metadata
- Download URL: stepflow_py-0.3.0-py3-none-any.whl
- Upload date:
- Size: 47.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
302595e0b4c1dd46e76e642e558f10666e19f18fee241eb78a9ba92f0ee8a82e
|
|
| MD5 |
08fdd3444d3ce8c26dd34b2beab29cc7
|
|
| BLAKE2b-256 |
88cc771e01a00237997e4c09d9f1bb396e23839163f5e972bc775535d8f97f7c
|
Provenance
The following attestation bundles were made for stepflow_py-0.3.0-py3-none-any.whl:
Publisher:
release_python.yml on stepflow-ai/stepflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stepflow_py-0.3.0-py3-none-any.whl -
Subject digest:
302595e0b4c1dd46e76e642e558f10666e19f18fee241eb78a9ba92f0ee8a82e - Sigstore transparency entry: 431857093
- Sigstore integration time:
-
Permalink:
stepflow-ai/stepflow@34da123fae53d80af9e6ef778a110935d9265b34 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/stepflow-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release_python.yml@34da123fae53d80af9e6ef778a110935d9265b34 -
Trigger Event:
workflow_dispatch
-
Statement type: