Skip to main content

Python SDK for Threadify — Service-delivery intelligence. Track every customer request from start to finish across every system, team, and partner. Visit: https://threadify.dev

Project description

Threadify Python SDK

Python SDK for Threadify — Service-delivery intelligence that tracks every customer request from start to finish across every system, team, and partner.

Installation

pip install threadify-sdk

For local development:

pip install -e ".[dev]"

Quick Start

import asyncio
import logging
from threadify import Threadify


async def main():
    try:
        conn = await Threadify.connect(
            "your-api-key",
            service_name="orders-service",
        )
    except Exception as e:
        logging.error(f"Failed to connect: {e}")
        return

    try:
        thread = await conn.start(
            contract_name="order_processing",
            role="customer",
            refs={"order_id": "ORD-123"},
            tags=["priority"],
        )

        await thread.add_refs({"crm_id": "CRM-456"})
        
        # Easy chaining!
        await (
            thread.step("order_received")
            .add_context({"orderId": "ORD-123"})
            .success("Order accepted")
        )
    except Exception as e:
        logging.error(f"Error in thread: {e}")
    finally:
        await conn.close()


if __name__ == "__main__":
    asyncio.run(main())

ws_url defaults to wss://eng.threadify.dev/threads. Override it if you are using a self-hosted or regional endpoint.

Configuration

Connect options

Use keyword arguments with Threadify.connect(...):

  • service_name
  • ws_url (optional, defaults to production)
  • graphql_url
  • debug
  • max_in_flight
  • connect_timeout

Example:

from threadify import Threadify

conn = await Threadify.connect(
    "your-api-key",
    service_name="inventory-service",
    debug=True,
)

Join options

Use Connection.join(...) with keyword arguments:

  • token=...
  • thread_id=... and role=...

Example:

thread = await conn.join(token="jwt-token")

Or:

thread = await conn.join(
    thread_id="thread-123",
    role="supplier",
)

Start options

Connection.start(...) supports named options for contract, role, refs, and tags, while preserving the older positional forms:

thread = await conn.start(
    contract_name="order_processing",
    role="customer",
    refs={"customer_id": "123"},
    tags=["priority"],
)
thread = await conn.start("Order-123", "customer")
thread = await conn.start({"customer_id": "123"}, "customer")
thread = await conn.start("Order-123")  # contract is optional

Subscriptions

Preferred API:

  • subscribe(event, step_name, handler)
  • unsubscribe(event, step_name)

Supported event patterns:

  • step.success
  • step.failed
  • step.*
  • rule.passed
  • rule.violated
  • rule.*
  • *

Example:

def handle_notification(notification):
    if notification.is_violated:
        print(notification.message)



conn.subscribe("rule.violated", "payment_step", handle_notification)

Versioning & Releases

This SDK follows Semantic Versioning and Conventional Commits. Releases are automated via GitHub Actions.

  • fix: ... -> Patch bump
  • feat: ... -> Minor bump
  • feat!: ... or BREAKING CHANGE: ... -> Major bump

OpenTelemetry Integration

The Python SDK includes the OpenTelemetry SpanExporter in the core package.

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from threadify import Threadify

conn = await Threadify.connect("api-key", service_name="checkout-service")

# Create exporter
exporter = conn.create_span_exporter(options={"refs": ["order.id", "customer.id"]})

# Filter spans by name — exact match or prefix wildcard with *
exporter = conn.create_span_exporter(options={
    "refs": ["order.id", "customer.id"],
    "filters": ["invoke_llm", "adk.before*", "llm.*"],
})

provider = TracerProvider()
provider.add_span_processor(BatchSpanProcessor(exporter))
trace.set_tracer_provider(provider)

Filter patterns:

  • "invoke_llm" — exact match
  • "adk.before*" — prefix wildcard, drops any span starting with adk.before
  • "llm.*" — prefix wildcard, drops any span starting with llm.

Testing

To run the SDK tests, execute:

make test

Alternatively, use pytest:

python3 -m pytest

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

threadify_sdk-0.2.10.tar.gz (35.3 kB view details)

Uploaded Source

Built Distribution

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

threadify_sdk-0.2.10-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file threadify_sdk-0.2.10.tar.gz.

File metadata

  • Download URL: threadify_sdk-0.2.10.tar.gz
  • Upload date:
  • Size: 35.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for threadify_sdk-0.2.10.tar.gz
Algorithm Hash digest
SHA256 180b28d341e76ffa2ae84f65ee720e969481f7645fd73c43d5f3d18b5be38ee8
MD5 5ac50e62638db59626652f00d54d10ae
BLAKE2b-256 888e21baf4f0eab0ccc6feb3a8d570223cff3ed6b8b43c60b19ce7f28a5f6a74

See more details on using hashes here.

File details

Details for the file threadify_sdk-0.2.10-py3-none-any.whl.

File metadata

  • Download URL: threadify_sdk-0.2.10-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for threadify_sdk-0.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 0146ca14e24332d08fa9200e851371aec20751674b08702e7bc6596a9f56905e
MD5 ae7443840b9c9fe38eb694f572d5b11a
BLAKE2b-256 7781079544799fd0ae63d170385ca07fb4e8dad886070948642e3ccfa37fb627

See more details on using hashes here.

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