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.2.tar.gz (29.1 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.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: securewithtrace-0.3.2.tar.gz
  • Upload date:
  • Size: 29.1 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.2.tar.gz
Algorithm Hash digest
SHA256 aa1d8a29c782a48de6fd99380839399e09b31b8c83407e9252c0b0f44e9b5ed6
MD5 37eb9c87a0b16de38a61ed1513133f89
BLAKE2b-256 f8853b8f366412f2bd2338d5991ba834086a3278b2bf93494a86b17f83ac223a

See more details on using hashes here.

Provenance

The following attestation bundles were made for securewithtrace-0.3.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for securewithtrace-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fef7684eb76c524cd0943e606507362d1affb94b66a967c5145289e29d3c981e
MD5 9fe2af860f63c482f05e8232aa745b71
BLAKE2b-256 1c63e305e0184d1c8b93414e70dd594e7183b57f3e7c86a371c4b09ebc8a9031

See more details on using hashes here.

Provenance

The following attestation bundles were made for securewithtrace-0.3.2-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