Dub Python SDK
raw JSON → 0.35.7 verified Mon Apr 27 auth: no python
Python client SDK for the Dub API (link management, analytics, etc.), generated by Speakeasy. Current version 0.35.7, requires Python >=3.10. Released frequently.
pip install dub Common errors
error AttributeError: module 'dub' has no attribute 'Dub' ↓
cause Outdated SDK version (<0.30.0) missing the top-level Dub class, or incorrect import.
fix
Upgrade to the latest version: pip install --upgrade dub
error dub.core.ApiError: 401 Unauthorized ↓
cause Invalid or missing API key (DUB_API_KEY environment variable not set or incorrect).
fix
Set DUB_API_KEY with a valid API token from the Dub dashboard.
Warnings
breaking Import path changed from 'from dub.client import Dub' to 'from dub import Dub' in v0.30+. ↓
fix Use the top-level import: from dub import Dub
deprecated The 'workspace_id' parameter is deprecated; use 'project_slug' instead. ↓
fix Replace 'workspace_id' with 'project_slug' in SDK initialization.
gotcha All SDK methods are async; run in async context or use asyncio.run(). ↓
fix Wrap synchronous calls in asyncio.run(): asyncio.run(client.links.create(...))
Imports
- Dub wrong
from dub.client import Dubcorrectfrom dub import Dub
Quickstart
from dub import Dub
client = Dub(
token=os.environ.get('DUB_API_KEY', ''),
)
# Create a short link
link = client.links.create(
url='https://example.com',
external_id='my-link',
tag_ids=[],
)
print(link.id)