Skip to main content

Watchup SDK for Python - Error and event tracking

Project description

Watchup Python SDK

Official Python SDK for Watchup incident tracking.

Installation

pip install watchup

Quick Start

import watchup

# Initialize the client
watchup.init(
    api_key="your-api-key",
    project_id="your-project-id",
    environment="production"
)

# Capture an error
try:
    risky_operation()
except Exception as e:
    watchup.capture_error(e)

# Capture a message
watchup.capture_message("User completed checkout", level="info")

# Set user context
watchup.set_user({
    "id": "user-123",
    "email": "user@example.com",
    "username": "john_doe"
})

# Add breadcrumbs
watchup.add_breadcrumb({
    "message": "User clicked checkout button",
    "category": "user-action",
    "level": "info"
})

# Set tags
watchup.set_tag("version", "1.2.3")
watchup.set_tags({
    "browser": "chrome",
    "os": "windows"
})

# Flush events before exit
watchup.flush()

Configuration

watchup.init(
    api_key="your-api-key",              # Required
    project_id="your-project-id",        # Required
    endpoint="https://api.watchup.com/api/v1/events",  # Optional
    environment="production",             # Optional
    release="1.2.3",                     # Optional
    server_name="web-server-01",         # Optional
    batch_interval=5000,                 # Optional (ms)
    max_batch_size=10,                   # Optional
    max_queue_size=100,                  # Optional
    max_retries=3,                       # Optional
    retry_backoff=1000,                  # Optional (ms)
    enabled=True,                        # Optional
    debug=False,                         # Optional
    sample_rate=1.0,                     # Optional (0.0-1.0)
    before_send=lambda event: event,     # Optional
    before_breadcrumb=lambda bc: bc      # Optional
)

Decorator Usage

@watchup.capture_errors
def risky_function():
    # Errors will be automatically captured
    raise ValueError("Something went wrong")

Context Manager

with watchup.configure_scope() as scope:
    scope.set_user({"id": "123"})
    scope.set_tag("version", "1.0")
    scope.capture_message("Custom message")

Framework Integration

Flask

from flask import Flask
import watchup

app = Flask(__name__)

watchup.init(
    api_key="your-api-key",
    project_id="your-project-id"
)

@app.errorhandler(Exception)
def handle_exception(e):
    watchup.capture_error(e)
    return "Internal Server Error", 500

Django

# settings.py
import watchup

watchup.init(
    api_key="your-api-key",
    project_id="your-project-id"
)

# middleware.py
class WatchupMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response
    
    def __call__(self, request):
        return self.get_response(request)
    
    def process_exception(self, request, exception):
        watchup.capture_error(exception)
        return None

# settings.py
MIDDLEWARE = [
    'yourapp.middleware.WatchupMiddleware',
    # ... other middleware
]

API Reference

init(api_key, project_id, **options)

Initialize the Watchup client.

capture_error(error, context=None)

Capture an exception. Returns event ID or None.

capture_message(message, level="info", context=None)

Capture a message. Returns event ID or None.

set_user(user)

Set user context. Pass None to clear.

add_breadcrumb(breadcrumb)

Add a breadcrumb to the timeline.

set_tag(key, value)

Set a single tag.

set_tags(tags)

Set multiple tags.

set_extra(key, value)

Set extra context data.

set_extras(extras)

Set multiple extra context data.

flush(timeout=5.0)

Flush all queued events. Returns True if successful.

close(timeout=5.0)

Close the client and cleanup resources.

License

MIT License

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

watchup-1.0.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

watchup-1.0.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file watchup-1.0.0.tar.gz.

File metadata

  • Download URL: watchup-1.0.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for watchup-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8ec2128fffd9564922e36c30194dbf04e79b01801923ba2d9f488f33181465c0
MD5 d48a17c425af1c987c619c343959b0ba
BLAKE2b-256 e4f64547666e2547fb2064389bb627aa633d497fe406df227a2b6aba451b64ce

See more details on using hashes here.

File details

Details for the file watchup-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: watchup-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for watchup-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1adae80ea5a4e3b4b53bdf50be0d7a2ce321959d25820984687124ddeb92d7a7
MD5 fe1fd40649e1e7c70ac0927b91103741
BLAKE2b-256 64168d9c275eae7d90d93874de83b8b421c2f6554eb5d55d6eb1913151826348

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page