Liliya Angelova
10/13/2025, 2:49 PMMarvin
10/13/2025, 2:49 PMNate
10/13/2025, 2:54 PMMarvin
10/13/2025, 2:55 PMserver.api.auth_string
- Env var: PREFECT_API_AUTH_STRING (e.g., user:pass)
- Use that same user:pass in your client calls.
- Docs: Security settings
Step 2) Create an Automation to run your deployment on event
- In the Prefect UI:
- Go to Automations → Create
- Trigger: Event
- Condition: Event name equals (for example) acme.order.created
- Action: Run Deployment (choose the deployment you want to start)
- You can add filters on resources if you want to target specific IDs/tags.
Step 3) Send a custom event
Option A: From Python using Prefect’s emitter
- This uses your PREFECT_API_URL (e.g., http://<your-host>:4200/api) and PREFECT_API_AUTH_STRING if set.
import os
from prefect.events import emit_event
# Point at your self-hosted Server
os.environ["PREFECT_API_URL"] = "http://<your-host>:4200/api"
# Only if you enabled auth on the server:
os.environ["PREFECT_API_AUTH_STRING"] = "user:pass"
emit_event(
event="acme.order.created",
resource={
"prefect.resource.id": "acme/order/12345",
"order_id": "12345" # optional extra labels
},
payload={
"amount": 42.50,
"currency": "USD"
},
)
- Python API reference: emit_event
Option B: Direct HTTP POST (curl)
- Endpoint: POST /api/events
- Auth: Basic auth if enabled (same user:pass as PREFECT_API_AUTH_STRING)
- Body: An array of event objects
Minimal example:
curl -X POST "http://<your-host>:4200/api/events" \
-u "user:pass" \
-H "Content-Type: application/json" \
-d '[
{
"event": "acme.order.created",
"resource": {
"prefect.resource.id": "acme/order/12345",
"order_id": "12345"
},
"payload": {
"amount": 42.50,
"currency": "USD"
}
}
]'
- API reference: Create events
Event payload schema (what the server accepts)
- The endpoint accepts a list of events. Each event supports:
- event (string): your event name, e.g., acme.order.created
- resource (object): a string-to-string map; include at least prefect.resource.id
- related (array of objects): optional; same shape as resource items
- occurred (ISO timestamp): optional; if omitted, server will use receive time
- payload (object): optional; any extra JSON you want to attach
- id, `follows`: optional advanced fields
Useful tools while testing
- Stream events live to confirm your custom event is received:
prefect events stream --format text
Notes and differences from Prefect 2.x
- There is no CLI command like prefect events send in Prefect 3.x (the CLI supports streaming, not sending).
- In 3.x, the event system and automations are first-class in self-hosted Server as well as Cloud.
Would you like me to sketch the exact automation trigger and action config for your deployment name and parameters? If you share your Server URL pattern and whether you’ve enabled auth, I can tailor the code/curl snippets precisely.