Python SDK for Exemplar monitoring and heartbeat APIs
Project description
exemplar-python-sdk
Python SDK for Exemplar. This package is designed to support multiple Exemplar features over time; currently it includes heartbeat monitor support. The client is a singleton: initialize once with your API key, then send heartbeats from sync or async code.
Install
From PyPI (import name is still exemplar):
pip install exemplar-python-sdk
From a local checkout, poetry install installs this project into Poetry’s virtualenv (no separate pip step needed):
poetry install
To smoke-test the built wheel inside that same env (after poetry build):
poetry run pip install dist/exemplar_python_sdk-*.whl
Using plain pip install dist/... uses whatever pip is first on your PATH (often system Python) and can fail with permission errors on macOS.
Requires Python 3.9+.
Usage
Current supported capability:
- Heartbeat monitors (sync and async)
1. Initialize once (API key)
Call init at application startup (before any heartbeat). A second init raises RuntimeError.
import exemplar
exemplar.init(api_key="<personal_access_token>")
# optional: exemplar.init(api_key="...", base_url="https://production-api.exemplar.dev")
2a. Simple heartbeat (sync)
Use from a cron job, Celery task, Flask/Django view, or any synchronous code:
import exemplar
exemplar.init(api_key=os.environ["EXEMPLAR_API_KEY"])
exemplar.send_heartbeat(
"69c3a0754e257b7d18094f9a",
metadata={"hostname": "worker-01"},
)
This sends POST /api/monitoring/heartbeat with Content-Type: application/json and header X-API-Key: <token>, matching:
curl -sS -X POST 'https://production-api.exemplar.dev/api/monitoring/heartbeat' \
-H 'Content-Type: application/json' \
-H 'X-API-Key: <personal_access_token>' \
-d '{"monitor_id":"69c3a0754e257b7d18094f9a","metadata":{"hostname":"worker-01"}}'
2b. Background loop (async)
For FastAPI, Starlette, asyncio services, or any framework that runs an async event loop: start a task that heartbeats on an interval (like a cron in the background):
import asyncio
import exemplar
async def main():
exemplar.init(api_key="...")
asyncio.create_task(
exemplar.heartbeat_background_loop(
"69c3a0754e257b7d18094f9a",
interval_seconds=60.0,
metadata={"hostname": "worker-01"},
)
)
...
Cancel the task when shutting down. Pass a shared httpx.AsyncClient if you want connection reuse with other HTTP calls.
Development
poetry install
poetry run pytest
API summary
| Function | Role |
|---|---|
exemplar.init(api_key=..., base_url=...) |
Create singleton (call once) |
exemplar.get_client() |
Access the client after init |
exemplar.send_heartbeat(monitor_id, metadata=...) |
One synchronous POST |
exemplar.heartbeat_background_loop(...) |
Async infinite loop with interval_seconds |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file exemplar_python_sdk-0.1.3.tar.gz.
File metadata
- Download URL: exemplar_python_sdk-0.1.3.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.4 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
848fec006be2b21d1848a4a03109fa7d19194ce0b8a7e8b0343971b5dd6e1ebb
|
|
| MD5 |
9c0909d13c41be675574af5104c77478
|
|
| BLAKE2b-256 |
b577893707870378534ddd9887545372335eaf19c7db7cf218497e3f36c98e3c
|
File details
Details for the file exemplar_python_sdk-0.1.3-py3-none-any.whl.
File metadata
- Download URL: exemplar_python_sdk-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.4 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
381fa14acd8482a4a29937456f0652cef3923eb208644a63ba7c33bf0da0dab5
|
|
| MD5 |
f580ce8a10680761f0a0e609afc93b30
|
|
| BLAKE2b-256 |
530c74f02b19f3065ffe6a9bd66e74d688daf7943f8bced2269f1cb9d1797f43
|