Python SDK for the Trace security platform
Project description
Trace Python SDK
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b04ebc5ebb8492dd15c22af753844b14af54b5180f0320fead681329d7b87062
|
|
| MD5 |
1006a635e7754a50ee3484a835183f7d
|
|
| BLAKE2b-256 |
db7281ffbd053df8c08c7a969cda346f06b72bd62bf8942eb2bc115f550638cc
|
Provenance
The following attestation bundles were made for securewithtrace-0.3.1.tar.gz:
Publisher:
release.yml on securewithtrace/trace-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
securewithtrace-0.3.1.tar.gz -
Subject digest:
b04ebc5ebb8492dd15c22af753844b14af54b5180f0320fead681329d7b87062 - Sigstore transparency entry: 1318422616
- Sigstore integration time:
-
Permalink:
securewithtrace/trace-python@24c7e505c044f557722729b5a4a2273f9d4491d1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/securewithtrace
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@24c7e505c044f557722729b5a4a2273f9d4491d1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file securewithtrace-0.3.1-py3-none-any.whl.
File metadata
- Download URL: securewithtrace-0.3.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1133766d8933bd6a80666569f7035feef614ccaa23e89f432be3d8ea3197438b
|
|
| MD5 |
134f58a4bdd4a080ef374838c78192d8
|
|
| BLAKE2b-256 |
64f4e1d218cbed8435cdd6285a143d095dbbe1887af11481f151fadd46f76870
|
Provenance
The following attestation bundles were made for securewithtrace-0.3.1-py3-none-any.whl:
Publisher:
release.yml on securewithtrace/trace-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
securewithtrace-0.3.1-py3-none-any.whl -
Subject digest:
1133766d8933bd6a80666569f7035feef614ccaa23e89f432be3d8ea3197438b - Sigstore transparency entry: 1318422742
- Sigstore integration time:
-
Permalink:
securewithtrace/trace-python@24c7e505c044f557722729b5a4a2273f9d4491d1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/securewithtrace
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@24c7e505c044f557722729b5a4a2273f9d4491d1 -
Trigger Event:
push
-
Statement type: