Skip to main content

Python SDK for the Trace security platform

Project description

Trace Python SDK

pypi CI

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.1.tar.gz (29.0 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.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: securewithtrace-0.3.1.tar.gz
  • Upload date:
  • Size: 29.0 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.1.tar.gz
Algorithm Hash digest
SHA256 b04ebc5ebb8492dd15c22af753844b14af54b5180f0320fead681329d7b87062
MD5 1006a635e7754a50ee3484a835183f7d
BLAKE2b-256 db7281ffbd053df8c08c7a969cda346f06b72bd62bf8942eb2bc115f550638cc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for securewithtrace-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1133766d8933bd6a80666569f7035feef614ccaa23e89f432be3d8ea3197438b
MD5 134f58a4bdd4a080ef374838c78192d8
BLAKE2b-256 64f4e1d218cbed8435cdd6285a143d095dbbe1887af11481f151fadd46f76870

See more details on using hashes here.

Provenance

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