Skip to main content

Python SDK for the Trace security platform

Project description

Trace Python SDK

pypi

The Trace Python SDK provides convenient access to webhook event parsing and signature verification for the Trace security platform.

Installation

# pip
pip install securewithtrace

# uv
uv add securewithtrace

# poetry
poetry add securewithtrace

Requirements

Python 3.12+

Usage

Webhook Verification

Verify and parse incoming webhook events from Trace. The SDK validates HMAC-SHA256 signatures and parses the payload into strongly-typed dataclasses.

from securewithtrace import WebhookHandler, WebhookVerificationError, WebhookParseError

handler = WebhookHandler(secret="whsec_your_webhook_secret")

# In your webhook endpoint handler:
def handle_webhook(request):
    try:
        event = handler.verify_and_parse(
            payload=request.body,
            signature=request.headers["X-Trace-Signature"],
            event_type=request.headers["X-Trace-Event"],
        )
    except WebhookVerificationError:
        return Response(status=401)  # Invalid signature
    except WebhookParseError:
        return Response(status=400)  # Malformed payload

    match event.type:
        case "vulnerability.detected":
            print(f"New vulnerability: {event.data.title} ({event.data.severity.value})")
        case "vulnerability.fixed":
            print(f"Fixed: {event.data.title}")
        case "vulnerability.reopened":
            print(f"Reopened: {event.data.title}")
        case "vulnerability.status_updated":
            print(f"Status changed: {event.data.old_status.value} -> {event.data.new_status.value}")
        case "vulnerability.severity_changed":
            print(f"Severity changed: {event.data.old_severity.value} -> {event.data.new_severity.value}")

    return Response(status=200)

Signature Verification Only

If you need to verify the signature without parsing:

handler = WebhookHandler(secret="whsec_your_webhook_secret")

is_valid = handler.verify_signature(
    payload=request.body,
    signature=request.headers["X-Trace-Signature"],
)

Event Types

The SDK provides typed dataclasses for all webhook event types:

Event Type Class
vulnerability.detected VulnerabilityDetectedEvent
vulnerability.fixed VulnerabilityFixedEvent
vulnerability.reopened VulnerabilityReopenedEvent
vulnerability.status_updated VulnerabilityStatusUpdatedEvent
vulnerability.severity_changed VulnerabilitySeverityChangedEvent

Exception Handling

from securewithtrace import WebhookVerificationError, WebhookParseError

try:
    event = handler.verify_and_parse(payload, signature, event_type)
except WebhookVerificationError:
    # Signature mismatch — reject the request
    ...
except WebhookParseError:
    # Payload could not be parsed — unknown event type, missing fields, etc.
    ...

Contributing

We welcome contributions! Please see CONTRIBUTING.md for development setup and guidelines.

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

securewithtrace-0.3.4.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

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

securewithtrace-0.3.4-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file securewithtrace-0.3.4.tar.gz.

File metadata

  • Download URL: securewithtrace-0.3.4.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for securewithtrace-0.3.4.tar.gz
Algorithm Hash digest
SHA256 32ed6ccadd507237acd32fc6c3a26c99e8419da62c645edac5ecfa55f8e2ee90
MD5 b318a5ed64bf7c319cb75f51e8549e60
BLAKE2b-256 395df7e1a85a137a4001fd76118b72ee0741727800da53dac54d5d5bcf2b0c11

See more details on using hashes here.

Provenance

The following attestation bundles were made for securewithtrace-0.3.4.tar.gz:

Publisher: release.yml on securewithtrace/trace-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file securewithtrace-0.3.4-py3-none-any.whl.

File metadata

File hashes

Hashes for securewithtrace-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 93c7921b28b0d4748b84da529496a315bbc5b2e8bfc0b4dfb3de92f500dfb412
MD5 16a10b80910e09e53c2002f126279472
BLAKE2b-256 40aef04afe0ef6e0a2a7db19d173ceeb050a9ba423d5c69986c47e04517bae6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for securewithtrace-0.3.4-py3-none-any.whl:

Publisher: release.yml on securewithtrace/trace-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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