Integrations

Python SDK

Official Python SDK for the U2L API: create short links and QR codes, list and search, and read click analytics from Python.

The official Python client for the U2L REST API. Zero dependencies — standard library only — so it installs instantly and runs anywhere Python 3.9+ runs.

Install

pip install u2l

Quick start

from u2l import U2L

client = U2L(api_key="u2l_live_...")

link = client.links.create(url="https://example.com/some/long/page")
print(link["shortLink"])  # https://u2l.ai/abc1234

Create an API key at Settings → API — every plan includes API access. Keep the key server-side; never commit it to source control.

Responses are plain dicts and field names match the API exactly (camelCase) — the full schema is at /developers/openapi.json.

# Create — all fields optional except url
client.links.create(
    url="https://mysite.com/launch",
    alias="launch24",       # custom slug
    title="Launch day",
    domain="auto",          # or one of your domains from client.domains.list()
    type="SL",              # "QR" creates a QR code
    tags=["campaign", "q3"],
)

# Read one
link = client.links.get("u2l.ai", "launch24")

# List and search (paginated)
page = client.links.list(search="launch", limit=25, page=1)
for l in page["links"]:
    print(l["slug"], l.get("clicks", 0))

# Update
client.links.update("u2l.ai", "launch24", title="Renamed", tags=["archive"])

# Delete (permanent)
client.links.delete("u2l.ai", "launch24")

Analytics, domains, account

# Per-link analytics (Advanced plan and above)
stats = client.analytics.get("u2l.ai", "launch24", timeRange=30)

# Domains available to your account
domains = client.domains.list()["domains"]

# Account totals and limits
account = client.account.stats()
print(account["totalClicks"], account["limits"]["apiRequestsPerDay"])

Error handling

Every non-2xx response raises U2LApiError with the API’s status and error code:

from u2l import U2L, U2LApiError

client = U2L(api_key="u2l_live_...")

try:
    client.links.create(url="https://example.com", alias="taken")
except U2LApiError as error:
    print(error.status, error.code, error)
    if error.status == 429:
        print(f"retry in {error.retry_after}s")

Error codes match the REST API’s error reference.

Rate limit visibility

After any call, the client exposes the latest rate-limit headers:

client.account.stats()
print(client.rate_limit)
# {"limit": 10, "remaining": 9, "reset": 1753500000,
#  "daily_limit": 500, "daily_remaining": 499}

Package

On PyPI as u2l (MIT), typed (py.typed). Questions or problems: u2l.ai/contact.