Skip to main content

Official Tripwire Python server SDK

Project description

Tripwire Python Library

Preview Python 3.10+ License: MIT

The Tripwire Python library provides convenient access to the Tripwire API from applications written in Python. It includes a synchronous client for Sessions, Fingerprints, Teams, Team API key management, sealed token verification, Gate, and Gate delivery/webhook helpers.

The library also provides:

  • a fast configuration path using TRIPWIRE_SECRET_KEY
  • iterator helpers for cursor-based pagination
  • structured API errors and built-in sealed token verification
  • public, bearer-token, and secret-key auth modes for Gate flows
  • Gate delivery/webhook helpers

Documentation

See the Tripwire docs and API reference.

Installation

You don't need this source code unless you want to modify the package. If you just want to use the package, run:

pip install tripwire-server

Requirements

  • Python 3.10+

Usage

Use TRIPWIRE_SECRET_KEY or secret_key=... for core detect APIs. For public or bearer-auth Gate flows, the client can also be created without a secret key:

from tripwire_server import Tripwire

client = Tripwire(secret_key="sk_live_...")

page = client.sessions.list(verdict="bot", limit=25)
session = client.sessions.get("sid_123")

Sealed token verification

from tripwire_server import safe_verify_tripwire_token

result = safe_verify_tripwire_token(
    sealed_token,
    "sk_live_...",
)

if result.ok:
    print(result.data.verdict, result.data.score)
else:
    print(result.error)

Pagination

for session in client.sessions.iter(search="signup"):
    print(session.id, session.latest_decision.verdict)

Fingerprints

page = client.fingerprints.list(sort="seen_count")
fingerprint = client.fingerprints.get("vid_123")

Teams

team = client.teams.get("team_123")
updated = client.teams.update("team_123", name="New Name")

Team API keys

created = client.teams.api_keys.create(
    "team_123",
    name="Production",
    allowed_origins=["https://example.com"],
)

client.teams.api_keys.revoke("team_123", created.id)

Gate APIs

from tripwire_server import Tripwire, create_delivery_key_pair

client = Tripwire()
services = client.gate.registry.list()
session = client.gate.sessions.create(
    service_id="tripwire",
    account_name="my-project",
    delivery=create_delivery_key_pair().delivery,
)

print(services[0].id, session.consent_url)

Gate delivery and webhook helpers

from tripwire_server import (
    create_delivery_key_pair,
    create_gate_approved_webhook_response,
    decrypt_gate_delivery_envelope,
    verify_gate_webhook_signature,
)

key_pair = create_delivery_key_pair()
response = create_gate_approved_webhook_response(
    {
        "delivery": key_pair.delivery,
        "outputs": {
            "TRIPWIRE_PUBLISHABLE_KEY": "pk_live_...",
            "TRIPWIRE_SECRET_KEY": "sk_live_...",
        },
    }
)
payload = decrypt_gate_delivery_envelope(key_pair.private_key, response.encrypted_delivery)
print(payload.outputs["TRIPWIRE_SECRET_KEY"])
print(
    verify_gate_webhook_signature(
        secret="whsec_test",
        timestamp="1735776000",
        raw_body='{"event":"gate.session.approved"}',
        signature="…",
    )
)

Error handling

from tripwire_server import TripwireApiError

try:
    client.sessions.list(limit=999)
except TripwireApiError as error:
    print(error.status, error.code, error.message)

Support

If you need help integrating Tripwire, start with tripwirejs.com/docs.

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

tripwire_server-0.2.0.tar.gz (47.1 kB view details)

Uploaded Source

Built Distribution

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

tripwire_server-0.2.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file tripwire_server-0.2.0.tar.gz.

File metadata

  • Download URL: tripwire_server-0.2.0.tar.gz
  • Upload date:
  • Size: 47.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tripwire_server-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c3eba9d3ed98ad9949e3e582fcc8c8ee0f4c47a42ab89e5c3f1ef0caa88177ee
MD5 425c4d34f3f28f6b74f6f6b06c9c1cbd
BLAKE2b-256 9a43b119f0e10e002fa6ccb68587d2a6c3e8ff967afbc8a828705cb801e3747e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tripwire_server-0.2.0.tar.gz:

Publisher: release.yml on abxy-labs/tripwire-server-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 tripwire_server-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tripwire_server-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00cc9836b951d4b7cef7735c94e69cb2148cdd76f5f79d70fd4cd7d8a4a8fb61
MD5 5a2bd0612f3b0dee73a04643681b5af0
BLAKE2b-256 b2dc198b46dca5670fb8a7af84e8ab281e8c05a4406f25da7ab005d72aa71f27

See more details on using hashes here.

Provenance

The following attestation bundles were made for tripwire_server-0.2.0-py3-none-any.whl:

Publisher: release.yml on abxy-labs/tripwire-server-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