Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

SegmentLite Python SDK ⚡

Lightweight, unbundled event routing and webhook fan-out SDK. Route analytics events and identity traits to your databases, webhooks, Slack, and third-party tools with sub-15ms latency—without paying Twilio Segment's $120–$1,000+/mo MTU tax.

  • Zero Price Cliff: Predictable, high-volume event ingestion.
  • Sub-15ms Edge Latency: Direct asynchronous routing.
  • Drop-in Concept: Familiar track() and identify() API signatures.
  • Both Sync & Async: First-class async/await support with httpx.

Installation

pip install segmentlite

(Or via uv / poetry / pipenv):

uv add segmentlite

Quickstart

1. Synchronous Tracking

from segmentlite import SegmentLite

client = SegmentLite(base_url="https://segmentlite-api-dfru.fly.dev")

# Send an event
response = client.track(
    event="Signed Up",
    user_id="usr_1029",
    properties={
        "plan": "Pro",
        "billing_cycle": "annual",
        "mrr": 49.0
    }
)
print(response)
# {'success': True, 'event_id': 'evt_7f1c93a4bc12', 'destinations_queued': 2, 'message': "..."}

# Identify user traits
client.identify(
    user_id="usr_1029",
    traits={
        "name": "Jane Doe",
        "email": "jane@example.com",
        "company": "Acme Inc."
    }
)

2. High-Throughput Asynchronous Tracking (FastAPI / Celery / AsyncIO)

import asyncio
from segmentlite import AsyncSegmentLite

async def main():
    async with AsyncSegmentLite(base_url="https://segmentlite-api-dfru.fly.dev") as client:
        res = await client.track(
            event="Feature Used",
            user_id="usr_1029",
            properties={"feature_name": "ai_copilot", "tokens_spent": 420}
        )
        print("Dispatched:", res)

asyncio.run(main())

RapidAPI Gateway Usage

If you consume SegmentLite via the RapidAPI Hub marketplace subscription:

from segmentlite import SegmentLite

client = SegmentLite(
    base_url="https://segmentlite-api.p.rapidapi.com",
    rapidapi_key="YOUR_RAPIDAPI_KEY",
    rapidapi_host="segmentlite-api.p.rapidapi.com"
)

client.track(event="Order Created", user_id="cust_55", properties={"amount": 129.00})

Routing Destinations Management

Configure where your ingested events get forwarded in real time:

# Add a webhook destination with optional event filtering
client.add_destination(
    name="Internal Analytics Relay",
    url="https://api.myapp.com/webhooks/segmentlite",
    events_filter=["Signed Up", "Checkout Completed"]  # Forward only critical conversion events
)

# List configured destinations
destinations = client.list_destinations()

# Delete a destination
client.delete_destination("dest_12345")

Documentation & Spec

About

Unbundled, sub-15ms event router SDK for Python. The lightweight alternative to Twilio Segment.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages