Skip to main content

u2l

Official Python client for the U2L AI URL shortener API.

Zero dependencies (standard library only). Python 3.9+.

pip install u2l

Quick start

from u2l import U2L

client = U2L(api_key="u2l_live_...")  # free at u2l.ai -> Settings -> API

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

Usage

Field names match the API exactly (camelCase) — full schema at u2l.ai/developers/openapi.json.

# Create with options
client.links.create(
    url="https://mysite.com/launch",
    alias="launch24",
    title="Launch day",
    domain="auto",          # or one of your domains
    tags=["campaign"],
    expiresAt="2027-01-01T00:00:00Z",
)

# QR code
client.links.create(url="https://mysite.com", type="QR")

# Get / update / delete (addressed by domain + slug)
client.links.get("u2l.ai", "launch24")
client.links.update("u2l.ai", "launch24", title="Launch day (updated)")
client.links.delete("u2l.ai", "launch24")

# List with filters and pagination
page = client.links.list(search="launch", sort="clicks", order="desc", page=1, limit=25)
for link in page["links"]:
    print(link["shortLink"], link.get("clicks", 0))

# Domains available to your account
client.domains.list()

# Per-link analytics (Advanced+ plans)
client.analytics.get("u2l.ai", "launch24")

# Account info and usage stats
client.account.get()
client.account.stats()

Error handling

Every non-2xx response raises U2LApiError with the API's status, error code, and (on 429s) how long to wait:

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)       # e.g. 409
    print(error.code)         # e.g. "alias_taken"
    print(error)              # human-readable message
    if error.status == 429:
        print(error.retry_after)  # seconds to wait

Rate limits

After any request, client.rate_limit holds the latest X-RateLimit-* header values:

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

Links

MIT

Metadata

Release files for u2l 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for u2l 0.1.0
File Size Uploaded
u2l-0.1.0.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for u2l 0.1.0
File Interpreter ABI Platform
u2l-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.8 kB

Release files / u2l-0.1.0.tar.gz

Download URL u2l-0.1.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
98a4e1b13b2e4d1389fb1f279e15ef1433cf48a6d15b78755703e2010dad68a9
BLAKE2b-256 checksum
How to use checksums
6bce3983e87b6e0f9459975ae35bc13dd3d4a0118a44a69ddf12288a52f06ba5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release files / u2l-0.1.0-py3-none-any.whl

Download URL u2l-0.1.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
85b0ebdc039291bead475d8615ae3ffd5ff39b4a80cea3287125007afd8b1d42
BLAKE2b-256 checksum
How to use checksums
3ed5e79de6d3ea573b0e13a2f9a8f6d4439fe7fed2975c365a27a9c9c17978ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page