Python SDK for Highway Workflow Engine - build durable workflows with simple decorators
Project description
Python SDK for Highway Workflow Engine. Build durable workflows with simple decorators.
Installation
pip install highway
Quick Start
from highway import Driver
driver = Driver() # Uses HIGHWAY_API_KEY env var
@driver.task(shell=True)
def backup_db():
return "pg_dump mydb > backup.sql"
@driver.task(py=True, depends=["backup_db"])
def verify():
import os
return {"exists": os.path.exists("backup.sql")}
result = driver.run()
print(result.status) # "completed"
Configuration
Set environment variables:
export HIGHWAY_API_KEY="hw_k1_..." export HIGHWAY_API_ENDPOINT="https://highway.solutions"
Or pass directly:
driver = Driver(
api_key="hw_k1_...",
endpoint="https://highway.solutions"
)
Task Types
Shell Tasks
Execute shell commands:
@driver.task(shell=True)
def list_files():
return "ls -la /tmp"
Python Tasks
Execute Python code in Highway’s sandboxed environment:
@driver.task(py=True)
def compute():
import math
return {"factorial": math.factorial(10)}
HTTP Tasks
Make HTTP requests:
@driver.task(http=True)
def call_api():
return {
"url": "https://api.example.com/webhook",
"method": "POST",
"json": {"status": "done"},
}
Generic Tool Tasks
Call any Highway tool directly:
@driver.task(tool="tools.llm.call")
def summarize():
return {
"prompt": "Summarize: {{backup_result.stdout}}",
"model": "claude-3-haiku-20240307"
}
@driver.task(tool="tools.database.query")
def query_users():
return {
"connection_string": "vault:db/postgres",
"query": "SELECT * FROM users"
}
Workflow Execution
Execute other workflows:
@driver.task(workflow="daily_report")
def run_report():
return {"inputs": {"date": "2024-01-01"}}
@driver.task(workflow_id="uuid-here")
def run_specific_version():
return {"inputs": {"mode": "production"}}
Dependencies
Tasks can depend on other tasks:
@driver.task(shell=True)
def step_1():
return "echo 'Step 1'"
@driver.task(shell=True, depends=["step_1"])
def step_2():
return "echo 'Step 2'"
@driver.task(shell=True, depends=["step_2"])
def step_3():
return "echo 'Step 3'"
Workflow Inputs
Pass variables to workflows:
result = driver.run(
inputs={"email": "user@example.com", "env": "prod"},
timeout=300
)
Access inputs in tasks via {{inputs.key}} syntax.
Retry Configuration
Configure automatic retries with exponential backoff:
@driver.task(http=True, retries=3, retry_delay=2.0, backoff=2.0)
def call_flaky_api():
return {"url": "https://api.example.com/endpoint"}
Durable Delays
Use Highway’s native WaitOperator for delays that consume zero worker resources:
from datetime import timedelta
@driver.task(shell=True, delay=timedelta(hours=2))
def delayed_task():
return "echo 'Runs after 2 hour delay'"
Scheduling
Schedule recurring workflows:
@driver.task(shell=True, schedule="0 * * * *") # Every hour
def hourly_backup():
return "pg_dump mydb > backup.sql"
@driver.task(shell=True, schedule=timedelta(minutes=30))
def interval_check():
return "curl https://api.example.com/health"
Observability
Track running workflows:
# Non-blocking submit
result = driver.run(wait=False)
run_id = result.run_id
# Check status
status = driver.status(run_id)
print(status.state)
# Cancel
driver.cancel(run_id)
Idempotency
Use workflow IDs for idempotent execution:
result1 = driver.run(workflow_id="order-12345")
result2 = driver.run(workflow_id="order-12345") # Returns cached result
Requirements
Python 3.11+
Highway API key
License
Apache 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
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 highway-0.1.1.tar.gz.
File metadata
- Download URL: highway-0.1.1.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b551b13cbe818512917425f5eab351c588736bae29c269ef62031ec445678592
|
|
| MD5 |
d8e94d3bafca84d17fa35108e382e8f0
|
|
| BLAKE2b-256 |
76f8d20aa8e39a45a62ddeaf450ac4e746bda358f0699cfe8d2bd5f44ce30aba
|
File details
Details for the file highway-0.1.1-py3-none-any.whl.
File metadata
- Download URL: highway-0.1.1-py3-none-any.whl
- Upload date:
- Size: 24.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b531d15bfa5c7b32235e1ea579bc963ed936a006407d20d871ef1e90b1563774
|
|
| MD5 |
6f1d8421c8de9b64494378723a1c0cd9
|
|
| BLAKE2b-256 |
fb34b73829bf6e1f3d1eccb1cdb3eec0febd45fe9dbfad6e21e573956e307937
|