ExeWatch Python SDK
The official Python SDK for ExeWatch, a monitoring service for applications that run on your users' machines and on your servers. Your application uses this package to send ExeWatch its logs, errors with their stack trace, timings and metrics. You read them in the ExeWatch dashboard, grouped by customer and by device, and you can get alerts on them.
The package does nothing on its own: it needs an ExeWatch account and an API key. Zero external dependencies: it uses only the Python 3.7+ standard library.
Before you start: account and API key
- Create a free account at exewatch.com. The free Hobby plan is enough to start; see the plans.
- Create an application in the dashboard, choosing the platform it runs on.
- Copy its API key from the application's API Keys page. The key starts with the
platform you chose:
ew_win_for Windows,ew_lin_for Linux, and so on.
You pass that key to initialize_exewatch, together with an id of your choice for the
customer the installation belongs to ("acme-corp" in the examples below).
Installation
pip install exewatch-sdk
Python 3.7 or later. In a project with a virtual environment, activate it first. To update: pip install --upgrade exewatch-sdk. The package is on PyPI and you import it as exewatch:
from exewatch import initialize_exewatch, ew, finalize_exewatch
Quick Start
from exewatch import initialize_exewatch, ew, finalize_exewatch
# Initialize (once at startup)
initialize_exewatch("ew_win_YOUR_API_KEY", "your-customer-id", app_version="1.0.0")
# Log
ew.info("Application started", "startup")
ew.warning("Disk space low", "system")
# Shutdown (at exit; also registered via atexit)
finalize_exewatch()
What's new in 0.5
on_before_send, a new option of initialize_exewatch. Your function sees every event
before it is queued and decides what it becomes: discard it, change its level, its message
or its tag, or remove keys from its data. A typical use is reporting the input errors your
users already saw on screen as warnings, so they stop counting as errors. The section
Deciding what an event becomes: on_before_send below explains it.
Upgrading from 0.4.x
No code changes are needed. Without on_before_send the SDK sends the same events, with the
same content, as 0.4.1. Behavior changes only for an application that sets it:
- Its decisions come before the minimum level and sampling. An error turned into a warning is sampled like any warning and no longer counts as an error in alerts and health. A warning turned into an error gets the breadcrumbs and the stack trace that errors get.
- If your function raises, the event is sent as it came in, and the SDK reports the fault
once per process, as a warning tagged
exewatch.
0.5.0.post1 only updates this page; the code is the same as 0.5.0, and both report
themselves to ExeWatch as 0.5.0.
Features
Logging (5 levels)
ew.debug("verbose details", "module")
ew.info("normal operation", "module")
ew.warning("something unusual", "module")
ew.error("something failed", "module") # includes breadcrumbs + stack trace
ew.fatal("critical failure", "module") # includes breadcrumbs + stack trace
Extra data via keyword arguments:
ew.info("Order placed", "orders", order_id="12345", total=99.99)
Exception Capture
try:
risky_operation()
except Exception as e:
ew.error_with_exception(e, "module", "Context message")
Unhandled exceptions
Once initialized, the SDK reports an exception that nothing catches (in the main thread or, on Python 3.8+, in another thread) as a fatal log tagged exception, with the stack trace, and sends it before the process ends. The previous sys.excepthook still runs, so the traceback is printed as usual. KeyboardInterrupt (Ctrl+C) is not reported.
At startup
initialize_exewatch logs Application started (tag exewatch) and sends the hardware info of the device (memory, CPU, disks, monitors, network, locale), like the Delphi SDK.
Timing / Profiling
ew.start_timing("db_query", "database")
result = db.execute("SELECT ...")
elapsed = ew.end_timing("db_query") # returns ms, logs automatically
# Stack-based (LIFO)
ew.start_timing("outer")
ew.start_timing("inner")
ew.end_timing() # ends "inner"
ew.end_timing() # ends "outer"
# With success/failure
elapsed = ew.end_timing("op", success=False)
# Cancel without logging
ew.cancel_timing("op")
Breadcrumbs
Automatically attached to ERROR/FATAL logs.
from exewatch import BreadcrumbType
ew.add_breadcrumb(BreadcrumbType.NAVIGATION, "nav", "Opened settings")
ew.add_breadcrumb(BreadcrumbType.CLICK, "ui", "Clicked Save")
ew.add_breadcrumb(BreadcrumbType.QUERY, "db", "SELECT * FROM users")
# Next error() or fatal() will include these breadcrumbs
Metrics
# Counters (cumulative)
ew.increment_counter("orders.placed", 1.0, "shop")
ew.increment_counter("revenue", 49.99, "billing")
# Gauges (instantaneous)
ew.record_gauge("memory_mb", 256.0, "system")
ew.record_gauge("queue_size", 42.0, "worker")
# Periodic gauge (sampled automatically in background)
def get_memory():
import resource
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024.0
ew.register_periodic_gauge("memory_mb", get_memory, "system")
User Identity
ew.set_user("user-42", "jane@example.com", "Jane Doe")
# All subsequent logs include user info
ew.info("User action")
ew.clear_user()
Global Tags
ew.set_tag("environment", "production")
ew.set_tag("feature_flag", "new_checkout")
# All subsequent logs include tag_environment, tag_feature_flag
ew.remove_tag("feature_flag")
ew.clear_tags()
Device Info
# Send hardware info (CPU, memory, disks, OS, etc.)
ew.send_device_info()
# Custom device metadata
ew.set_custom_device_info("license_type", "enterprise")
ew.set_custom_device_info("deployment", "on-premise")
ew.send_custom_device_info()
Runtime Configuration
# Change customer ID at runtime
ew.set_customer_id("new-customer")
# Enable/disable
ew.enabled = False # suspend all logging
ew.enabled = True # resume
Deciding what an event becomes: on_before_send
Pass a function to on_before_send and it sees every event before it is queued. Return
False to discard the event; any other return value, None included, keeps it. Change
event.level, event.message or event.tag to send it differently.
from exewatch import LogLevel, initialize_exewatch
class ValidationError(Exception):
pass
def before_send(event):
# Input errors the user already saw on screen: keep them, as warnings.
if isinstance(event.exception, ValidationError):
event.level = LogLevel.WARNING
# A key the app should never have logged.
event.extra_data.pop("card_number", None)
initialize_exewatch(api_key="ew_lin_...", customer_id="acme-corp", on_before_send=before_send)
What the event holds:
| Attribute | Can change | What it is |
|---|---|---|
level |
yes | a LogLevel, or a value LogLevel() accepts; anything else is ignored |
message |
yes | the text; a new one is cleaned of the user's folders like the rest |
tag |
yes | "" and "exewatch" are ignored, the event keeps its tag |
kind |
no | "log", or "timing" for the event end_timing writes |
exception |
no | the exception from error_with_exception or an unhandled one; None for a manual log and for a timing |
extra_data |
the dict, not the attribute | the event's own dict: remove or change keys there |
- The function runs on the thread that logs, before the minimum level and sampling. A warning turned into an error gets the breadcrumbs and the stack trace that errors get; an error turned into a warning is sampled like any warning and no longer counts as an error in alerts and health.
- Keep it quick: no I/O, no UI.
- The user, the global tags and the breadcrumbs are added after it and are not in
extra_data: useset_user,set_tagandclear_breadcrumbsfor those. Removingstack_tracefrom an error does not hide the trace: the SDK takes the caller's stack instead. - If it raises an
Exception, the event is sent with the level, message and tag it came in with, and the SDK reports the fault once, as a warning taggedexewatch. Keys already removed fromextra_datastay removed. - A log written inside the function is sent without passing through it again. The SDK's own
events (tag
exewatch) never reach it. - It is read once, at initialization.
Configuration Options
initialize_exewatch(
api_key="ew_win_...", # Required: your API key
customer_id="acme-corp", # Required: customer identifier
app_version="1.0.0", # Optional: application version
endpoint="https://exewatch.com", # API endpoint
storage_path="", # Custom storage path (default: platform-specific)
buffer_size=100, # Events before auto-persist
flush_interval_ms=5000, # Persist interval (ms)
retry_interval_ms=30000, # Retry interval on failure (ms)
sample_rate=1.0, # 0.0-1.0 (errors/fatals always sent)
gauge_sampling_interval_sec=30, # Periodic gauge interval
max_pending_age_days=7, # Auto-cleanup old files
anonymize_device_id=True, # default: user and computer name sent as short codes, user folder in paths replaced by [HOME] etc. False = send them as they are
on_before_send=None, # called for every event before it is queued, see below
)
Architecture
- Single file (
exewatch.py): no package installation needed - File queue: logs persisted to disk before sending (crash-safe)
- Background shipper thread: sends queued files to server
- Background sampler thread: samples registered periodic gauges
- Thread-safe: all shared state protected with locks
- Thread-local breadcrumbs: each thread has its own trail
Platform Support
| Feature | Windows | Linux |
|---|---|---|
| Logging | Yes | Yes |
| CPU info | Registry | /proc/cpuinfo |
| Memory info | GlobalMemoryStatusEx | /proc/meminfo |
| Disk info | Win32 API | /proc/mounts + statvfs |
| Monitor info | EnumDisplayMonitors | N/A |
| Boot time | GetTickCount64 | /proc/stat btime |
Requirements
- Python 3.7+
- No external dependencies
Running Tests
pip install pytest
cd SDK/Python
pytest tests/ -v
Metadata
Release files for exewatch-sdk 0.5.0.post1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| exewatch_sdk-0.5.0.post1.tar.gz | 57.3 kB | Without provenance | Details for exewatch_sdk-0.5.0.post1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| exewatch_sdk-0.5.0.post1-py3-none-any.whl | Python 3 | none | any | Details for exewatch_sdk-0.5.0.post1-py3-none-any.whl |
Total release size: 87.3 kB
Release files / exewatch_sdk-0.5.0.post1.tar.gz
| Download URL | exewatch_sdk-0.5.0.post1.tar.gz |
|---|---|
| Size | 57.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd103d7242461e14f5b15a14940abb22feb4a4a0aceeba0a97758fd58ab0c70f
|
|
BLAKE2b-256 checksum How to use checksums |
34b7fcdb6e2d23e4e3bee71c37a6be504a75d9a58913d0d19faf06f978fb78e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.6
|
Release files / exewatch_sdk-0.5.0.post1-py3-none-any.whl
| Download URL | exewatch_sdk-0.5.0.post1-py3-none-any.whl |
|---|---|
| Size | 30.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
56c6fdd1798cd1373e5de0f996b8eb40ca8316fd8f189b06e5e38b82d76b6026
|
|
BLAKE2b-256 checksum How to use checksums |
1bde36b6b15b176161156b8f097ecf305b0ea7d71cdeb243d5cef2fa6f70b280
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.6
|
Security for exewatch-sdk 0.5.0.post1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.