Skip to main content

Official Python client for the U2L AI API — create and manage short links, QR codes, and analytics (u2l.ai)

Project description

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

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

u2l-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

u2l-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file u2l-0.1.0.tar.gz.

File metadata

  • Download URL: u2l-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for u2l-0.1.0.tar.gz
Algorithm Hash digest
SHA256 98a4e1b13b2e4d1389fb1f279e15ef1433cf48a6d15b78755703e2010dad68a9
MD5 3c1da1d05262055fef0df565d28e76ac
BLAKE2b-256 6bce3983e87b6e0f9459975ae35bc13dd3d4a0118a44a69ddf12288a52f06ba5

See more details on using hashes here.

File details

Details for the file u2l-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: u2l-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for u2l-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85b0ebdc039291bead475d8615ae3ffd5ff39b4a80cea3287125007afd8b1d42
MD5 0e7b6bc8e05b6e0ceec3de0d0b65cdf8
BLAKE2b-256 3ed5e79de6d3ea573b0e13a2f9a8f6d4439fe7fed2975c365a27a9c9c17978ef

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