Official Python SDK with typed dataclasses. Works with Django, FastAPI, asyncio, and plain scripts.
lyng-sdk1.0.0Python 3.10+MITInstall from PyPI using pip. The only dependency is httpx, which handles both sync and async requests.
pip install lyng-sdkCreate a client with your API key. Store the key in an environment variable rather than hardcoding it.
import os
from lyng import Lyng
lyng = Lyng(api_key=os.environ["LYNG_API_KEY"])Pass url and optionally a slug (Premium only). Returns a CreatedLink with short_url and slug.
link = lyng.links.create(url="https://example.com")
print(link.short_url) # https://lyng.my.id/abc123
print(link.slug) # abc123
# Custom slug (Premium only)
link = lyng.links.create(
url="https://example.com",
slug="my-link",
)Returns your 100 most recently created links, newest first. Each item is a typed Link dataclass.
links = lyng.links.list()
for link in links:
print(link.short_url, link.clicks)Use AsyncLyng for async/await code. Identical interface to the sync client — just add await.
import asyncio
from lyng import AsyncLyng
async def main():
async with AsyncLyng(api_key="lk_your_key") as lyng:
link = await lyng.links.create(url="https://example.com")
print(link.short_url)
asyncio.run(main())All API errors raise LyngError with a status code and a message.
from lyng import Lyng, LyngError
lyng = Lyng(api_key="lk_your_key")
try:
link = lyng.links.create(url="https://example.com")
except LyngError as e:
print(e.status) # 429
print(str(e)) # "Link limit reached."