ExeWatch Python SDK
Lightweight APM / observability SDK for Python applications.
Zero external dependencies — uses only the Python 3.7+ standard library.
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()
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
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.tar.gz | 55.7 kB | Without provenance | Details for exewatch_sdk-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| exewatch_sdk-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for exewatch_sdk-0.5.0-py3-none-any.whl |
Total release size: 84.9 kB
Release files / exewatch_sdk-0.5.0.tar.gz
| Download URL | exewatch_sdk-0.5.0.tar.gz |
|---|---|
| Size | 55.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5cd5a9056571ced28de3062c4564498203482e18c63f4c0e5077c5e117677c68
|
|
BLAKE2b-256 checksum How to use checksums |
f7311ab98963b59b1427d861922c9960624e2e8a48055989bc905774e4d602e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.6
|
Release files / exewatch_sdk-0.5.0-py3-none-any.whl
| Download URL | exewatch_sdk-0.5.0-py3-none-any.whl |
|---|---|
| Size | 29.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
51d3d83f9229c99952f4037cf79d352387c51ba5f0b93b73db1dfe130964b893
|
|
BLAKE2b-256 checksum How to use checksums |
12e81499d68d98ae67445e26646bde1c33b15cd031c10ff8c6002011d94bae28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.6
|
Security for exewatch-sdk 0.5.0
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.