Get started with the Hyrex Python SDK
pip install hyrex
hyrex init
.env
hyrex_app.py
tasks.py
requirements.txt
Dockerfile
export HYREX_DATABASE_URL="postgresql://user:password@localhost/dbname" hyrex init-db
your-project/ ├── .env # Environment configuration ├── hyrex_app.py # Hyrex app configuration ├── tasks.py # Task definitions ├── requirements.txt # Python dependencies └── Dockerfile # Container configuration
from hyrex import HyrexRegistry from pydantic import BaseModel hy = HyrexRegistry() class EmailContext(BaseModel): to: str subject: str body: str @hy.task def send_email(context: EmailContext): print(f"Sending email to {context.to}") # Your email logic here return {"sent": True}
# Send a task to the default queue task = send_email.send(EmailContext( to="user@example.com", subject="Welcome!", body="Thanks for signing up" )) print(f"Task queued with ID: {task.id}") # Send with custom configuration task = send_email.with_config( queue="high-priority", max_retries=3, timeout_seconds=30 ).send(EmailContext( to="user@example.com", subject="Urgent!", body="Important message" ))
hyrex run-worker hyrex_app:app
Was this page helpful?