TrimLynk Official Python SDK & CLI
The official Python client library and CLI for the TrimLynk Developer API v1.
TrimLynk is a modern, privacy-first URL shortening, link intelligence, and attribution platform. This SDK provides complete programmatic access to link creation, analytics telemetry, conversion funnel tracking, marketing campaigns, real-time webhook management, and zero-config local webhook tunneling.
Official Platform & Documentation Links
| Resource | Official URL | Purpose |
|---|---|---|
| 🌐 TrimLynk Platform | https://trimlynk.com | Main dashboard, branded domains, and analytics |
| 📚 SDK Documentation | https://trimlynk.com/developers/sdks | In-depth Python SDK & client library guides |
| 🚀 Developers Hub | https://trimlynk.com/developers | API keys, telemetry, rate limits, and quickstarts |
| ⚡ Webhooks & Events | https://trimlynk.com/developers/webhooks | HMAC-SHA256 signature verification & event schema |
| 📖 OpenAPI 3.1 Reference | https://trimlynk.com/api-docs | Interactive endpoint explorer & JSON spec |
| 📦 PyPI Registry | https://pypi.org/project/trimlynk/ | Official package release & installation |
| 🛡️ Terms & Privacy | Terms of Service · Privacy Policy | Data protection & compliance policies |
Highlights
- Zero Mandatory Dependencies: Implemented using the Python standard library. No bloated dependency trees or supply-chain vulnerabilities.
- Native Async Support (
AsyncTrimLynk): Nativeasync/awaitclient andAsyncAutoPagingIteratorfor FastAPI, asyncio bots, and async microservices. - CLI with Local Webhook Tunneling (
trimlynk webhooks listen): Auto-detects local tunnels (ngrok) and streams/forwards events in real-time, just likestripe listen. - QR Code Exporter (
link.save_qr()): Decode and save Base64 PNG/SVG/binary QR codes directly to disk with a single call. - Pandas / Data Science Export (
analytics.to_dataframe()): Export analytics breakdowns (devices,countries,referrers) directly into Pandas DataFrames (pip install trimlynk[data]). - Stripe-Style Webhooks (
construct_event): 1-line HMAC-SHA256 signature verification with typedWebhookEventmodels (event.is_click,event.revenue,event.url_id). - Concurrent Batch Creation (
links.create_many()): High-throughput multi-threaded and asynchronous batch creation. - Built-in UTM Campaign Engine: Build query parameters automatically with
auto_decorate_utm=True. - Forgiving Parameter Aliases: Accepts
slugforcustom_slug,link_idforurl_id,revenueforevent_value, and native Pythondate/datetimeobjects. - Production-Grade Idempotency: Safe mutations with
idempotency_keyon link, campaign, and webhook operations.
Installation
# Standard zero-dependency installation
pip install trimlynk
# With optional Pandas data science export support
pip install trimlynk[data]
# With secure system credential keychain storage for the CLI
pip install trimlynk[keyring]
Installing the package automatically exposes both the Python SDK and the trimlynk CLI executable.
Quickstart
1. Synchronous Client
from trimlynk import TrimLynk
# 1. Initialize client (reads TRIMLYNK_API_KEY environment variable if omitted)
client = TrimLynk(api_key="tl_live_your_api_key_here")
# 2. Create a shortened link with UTM parameters
link = client.links.create(
original_url="https://example.com/summer-promo",
slug="summer-deal",
title="Summer Promo 2026",
tags=["summer", "promo"],
utm_source="newsletter",
utm_medium="email",
utm_campaign="summer_launch",
auto_decorate_utm=True,
)
print(f"Short URL: {link.short_url}")
print(f"QR Code URL: {link.qr_code}")
# 3. Export QR code image to disk
link.save_qr("assets/qr_code.png")
2. Asynchronous Client (AsyncTrimLynk)
Designed specifically for FastAPI, Aiohttp, Discord/Telegram bots, and asynchronous background tasks:
import asyncio
from trimlynk import AsyncTrimLynk
async def main():
async with AsyncTrimLynk(api_key="tl_live_xxx") as client:
# Create a link asynchronously
link = await client.links.create(
original_url="https://example.com/product",
slug="fast-deal",
)
print("Created:", link.short_url)
# Batch create concurrently with bounded concurrency
links = await client.links.create_many([
{"original_url": "https://example.com/1", "slug": "item-1"},
{"original_url": "https://example.com/2", "slug": "item-2"},
], concurrency=5)
# Asynchronously stream through all links
async for item in client.links.iter(limit=50):
print(item.short_code, item.clicks)
asyncio.run(main())
Features & Resources
1. QR Code Exporter
Save decoded Base64 PNG, SVG markup, or remote images directly to a local file:
# Direct from Link object:
link = client.links.get("url_abc123")
path = link.save_qr("images/deal_qr.png")
# Or fetch and save in one step:
client.links.download_qr("url_abc123", "images/deal_qr.png")
# Async version:
await async_client.links.download_qr("url_abc123", "images/deal_qr.png")
2. Pandas / Data Science Export
Export telemetry breakdowns into Pandas DataFrames for Jupyter notebooks and BI pipelines:
summary = client.analytics.get()
# Export specific breakdown
devices_df = summary.to_dataframe("devices") # columns: ['device', 'clicks']
countries_df = summary.to_dataframe("countries") # columns: ['country', 'clicks']
referrers_df = summary.to_dataframe("referrers") # columns: ['referrer', 'clicks']
# Or export all tables into a dictionary:
dataframes = summary.to_dataframe("all")
print(dataframes["devices"].head())
# Export a paginated list of links directly:
links_df = client.links.list().to_dataframe()
3. Stripe-Style Webhook Ingestion & Verification
Verify HMAC-SHA256 signatures and deserialize events into typed WebhookEvent models:
from fastapi import FastAPI, Request, HTTPException
from trimlynk import TrimLynk, SignatureVerificationError
app = FastAPI()
client = TrimLynk()
@app.post("/api/webhooks")
async def handle_webhook(request: Request):
raw_payload = await request.body()
signature_header = request.headers.get("x-trimlynk-signature")
try:
# 1-step verification and typed parsing
event = client.webhooks.construct_event(
raw_payload=raw_payload,
signature_header=signature_header,
secret="whsec_your_signing_secret",
tolerance_seconds=300,
)
except SignatureVerificationError as e:
raise HTTPException(status_code=400, detail=str(e))
# Inspect event using convenient property helpers
if event.is_click:
print(f"Click on {event.short_url} from {event.channel}")
elif event.is_conversion:
print(f"Conversion {event.event_name} recorded! Revenue: ${event.revenue}")
return {"status": "success"}
4. Conversions & Attribution Tracking
# Record a customer conversion (supports revenue or event_value alias)
conv = client.conversions.create(
link_id="url_abc123",
event_name="checkout_completed",
revenue=129.50,
customer_email="buyer@example.com",
order_id="ord_9981",
)
# Conversion funnel analytics (Click -> Lead -> Sale)
funnel = client.analytics.conversions(link_id="url_abc123")
print("Attributed Revenue:", funnel.revenue)
5. Automatic Pagination
Iterate seamlessly across thousands of records without manual cursor handling:
# Sync iteration
for link in client.links.iter(limit=100, tag="promo"):
print(link.short_url, link.clicks)
# Async iteration
async for webhook in async_client.webhooks.iter():
print(webhook.url)
Command Line Interface (CLI)
The trimlynk CLI is automatically installed with the package.
Local Webhook Tunneling (trimlynk webhooks listen)
Stream incoming live webhooks to your local machine and forward to your local app (auto-discovers local ngrok):
# 1. Listen and forward live events to your local server
trimlynk webhooks listen --forward-to http://localhost:8000/api/webhooks
# 2. Filter for specific event types
trimlynk webhooks listen --event click.created --event conversion.created
# 3. Explicit tunnel override
trimlynk webhooks listen --tunnel-url https://my-domain.ngrok-free.dev
General CLI Commands
# Authentication & Status
trimlynk auth login
trimlynk auth status
# Links Management
trimlynk links create https://example.com --slug deal26 --tag promo
trimlynk links list --limit 20
trimlynk links get deal26
trimlynk links update deal26 --title "Spring Sale"
trimlynk links delete deal26 --yes
# Analytics
trimlynk analytics summary
trimlynk analytics link deal26
# Webhooks CRUD
trimlynk webhooks list
trimlynk webhooks test <webhook_id>
trimlynk webhooks deliveries <webhook_id>
Error Handling
The SDK maps all HTTP and network errors into a typed exception hierarchy:
TrimLynkError
├── APIError
│ ├── InvalidRequestError (HTTP 400)
│ ├── AuthenticationError (HTTP 401)
│ ├── PermissionError (HTTP 403)
│ ├── NotFoundError (HTTP 404)
│ ├── ConflictError (HTTP 409)
│ │ └── IdempotencyConflictError
│ ├── RateLimitError (HTTP 429)
│ └── InternalServerError (HTTP 500)
├── SignatureVerificationError
│ ├── SignatureExpiredError
│ ├── SignatureMismatchError
│ └── InvalidSignatureHeaderError
├── NetworkError
└── TimeoutError
Documentation & Community Resources
- Documentation Portal: https://trimlynk.com/developers/sdks
- Webhooks Guide: https://trimlynk.com/developers/webhooks
- API Reference: https://trimlynk.com/api-docs
- Source Repository: https://github.com/Anky9972/urlshortner
- Issue Tracker: https://github.com/Anky9972/urlshortner/issues
- Customer Support: support@trimlynk.com or https://trimlynk.com/contact
License
Proprietary License (All Rights Reserved). Licensed under the TrimLynk Software License Agreement. For complete terms of service and acceptable use policies, please visit TrimLynk Terms of Service and Privacy Policy.
Metadata
Release files for trimlynk 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| trimlynk-1.1.0.tar.gz | 68.2 kB | Without provenance | Details for trimlynk-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| trimlynk-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for trimlynk-1.1.0-py3-none-any.whl |
Total release size: 127.9 kB
Release files / trimlynk-1.1.0.tar.gz
| Download URL | trimlynk-1.1.0.tar.gz |
|---|---|
| Size | 68.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92cbed9f1d87a821663c2d377264e755654fd3203bf1a429bc0bcbd9a9d4fd1c
|
|
BLAKE2b-256 checksum How to use checksums |
0a2aa6c19a1458d32072503e37494bf6281354abc1047ab399363aace793bc31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / trimlynk-1.1.0-py3-none-any.whl
| Download URL | trimlynk-1.1.0-py3-none-any.whl |
|---|---|
| Size | 59.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8627e305c2169253e6527b8a1003b4ed9ddfcc003905aca515ea2ce8f651da01
|
|
BLAKE2b-256 checksum How to use checksums |
012fb51c8759157c8c13cdfe48a02d3d725273750e3426758eddc92c6ed9d1dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for trimlynk 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.