Introduction
lerix is the server-side Lerix SDK for Python. After one call to
lerix.init(), every unhandled exception in your service is reported to the
dashboard with its stack trace, host, release and request context, and your
code gets a typed client for the push notifications REST API. Drop-in hooks
are included for FastAPI, Flask and Django.
Create a project with the Python framework in the dashboard
and copy its API key and project id from Project Settings.
Requirements
The package has no runtime dependencies. The framework hooks import FastAPI,
Flask or Django only when you use them.
1. Install the package
2. Initialise the SDK
Calllerix.init() once, as early as possible in your program:
main.py
init() reads LERIX_API_KEY, LERIX_PROJECT_ID and
LERIX_ENVIRONMENT from the environment:
init() registers the service in the background
and installs sys.excepthook and threading.excepthook, so uncaught
exceptions are reported from now on and flushed before the interpreter exits.
See Error Tracking for what gets captured
and how to report errors yourself.
Add the hook for your framework
Web frameworks catch exceptions themselves to return a500, so they never
reach sys.excepthook. Add the matching hook to report them:
- FastAPI / Starlette
- Flask
- Django
main.py
3. Verify the integration
Add a route that raises and call it once:500 response and the error
appears in your dashboard within seconds. Remove the
route afterwards.
Options
Every option is a keyword argument oflerix.init() (and of LerixClient).
How your service appears in the dashboard
The SDK registers your service as aserver app. The app id defaults to the
name in pyproject.toml’s [project] table and the release to its
version, so reports are grouped per service and per release. Override them
with the app option when you deploy several instances of the same code base
or want a git SHA as the build number:
.lerix/state.json under the working directory, so restarts reuse it. Add
that folder to .gitignore, or mount it in containers. Pass
state_path=False to skip persistence, or user_id to control the id
yourself.
Next steps
Error Tracking
What the hooks report, how to change the policy, and manual reporting.
Push Notifications
Send, schedule, update and unsend notifications from your backend.