
My First Hyrex Task
Step 1. Install Hyrex in your project:deliver_email is a hyrex task
Documentation Index
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
Deploy a Hyrex App in 5 minutes

pip install hyrex
hyrex init --database_url="ADD_URL_HERE"
from settings import hy
from pydantic import BaseModel, Field
hy = Hyrex(
app_id="kindex-worker",
conn=settings.hy_database_url,
error_callback=task_error_callback,
)
class DeliverEmailContext(BaseModel):
email: str
subject: str
body: str
@hy.task
def deliver_email(context: DeliverEmailContext):
url = "EMAIL_PROVIDER_API"
r = requests.post(url, body=context.model_dump())
if r.status_code == 200:
print("Success!")
else:
print("Something went wrong...")
deliver_email is a hyrex task
from tasks import deliver_email, DeliverEmailContext
email_args = SendEmailContext(
email="bart@hyrex.io"
subject="Breakfast is ready!"
body="like I said... breakfast is ready!"
)
# Call the function synchronously.
# Behaves just like a normal Python function.
deliver_email(email_args)
# Use .send(...) to call the function asynchronously.
# Submits the task to the Hyrex task queue.
task = deliver_email.send(email_args)
Was this page helpful?