Examples
Each example is self-contained and runnable. Required env vars are listed in the example's README.
| # | Example | Demonstrates |
|---|---|---|
| 01 | minimum | Bare minimum that runs (one action, one derived NATS ingress) |
| 02 | required_vs_optional | service-first Service("name", ...), canonical HTTP ingress, and narrow TriggersSettings(...) override examples |
| 03 | multiple_actions | Multiple actions with distinct retry configs |
| 04 | multi_source | NATS + Kafka + HTTP ingress together, using the default canonical HTTP path and optional public-base override |
| 05 | error_handling | PermanentError, SkipForward, retry exhaustion |
| 06 | with_dedup_redis | Redis-backed app-level dedup via enable_dedup() |
| 07 | with_rate_limit_redis | Redis-backed rate limit via enable_rate_limit() |
| 08 | observability | structlog + Prom /metrics + OTel tracing |
| 09 | testing_with_harness | pytest + Harness end-to-end |
| 10 | production_shape | Production-typical metadata with runtime wiring coming straight from TRIGGERS_* env |
| 11 | flow_lab | Local E2E dummy with result_event, condition/mapping/rate-limit support, and service-first wiring |
Running examples
Examples are documentation, not installable packages. They expect the SDK to be installed in the active environment (e.g. pip install -e ../.. from the repo root, or make install from triggers-sdk-python/).
Most examples require a local NATS at nats://127.0.0.1:4222. Start one via:
docker run -p 4222:4222 nats:2.10-alpine -js
Examples that need Kafka, Redis, or an HTTP listener call that out explicitly in their own README.
Example 11_flow_lab demonstrates result_event catalog metadata for Studio action→action chaining. See its README for local stack usage; the Go twin lives at triggers-sdk-go/examples/flow_lab/.
Smoke check
Each service.py is verified by an import-only smoke check (no runtime broker needed):
cd examples/<N>_<name>
python -c "import service; print(service.svc.name)"
The examples are also covered by examples/test_examples_surface.py, which checks the approved public API surface, canonical derived ingress names, and example-specific manifest details.
The runtime behavior is exercised by the SDK's own unit + harness + interop tests; the examples exist to teach the public API surface.