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.3.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.3-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: securewithtrace-0.3.3.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.3.tar.gz
Algorithm Hash digest
SHA256 6330f0c91fbac24908da6a1473060683caa84ad56afe5be70adb693eb7de9d40
MD5 ba6aa477876ef43793fe913f990d66da
BLAKE2b-256 147b3de9b7028211036f4d7ee2595f10da2edaec19b4cc919897ec728fa386a1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for securewithtrace-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6e56789e8a85da43842116baa64666723a7f4133a337cfe503d6d131de55a09b
MD5 f7fcb676d94aa19e50707d44d817d3ff
BLAKE2b-256 5486e31b2c94d325da2b420eb2fb275ae564500ed16f5c2825c5a99b96f755ad

See more details on using hashes here.

Provenance

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