The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
guide: flask
Kiran K88f02a0ca2c9
diff --git a/apps/docs/quickstart/flask.mdx b/apps/docs/quickstart/flask.mdxindex b07fe8a9ce..04c2c47e4b 100644--- a/apps/docs/quickstart/flask.mdx+++ b/apps/docs/quickstart/flask.mdx@@ -15,22 +15,153 @@ To install the Dub Python SDK, run the following command:pip install dub```+initialize the Dub Python SDK by creating a new instance of the `Dub` class.++```python+import os+import dub+from dub.models import operations++d = dub.Dub(+ token=os.environ['DUB_API_KEY'],+ workspace_id='ws_clugls3...',+)+```+## 3. Create link+Let's create a short link using the Dub Python SDK.++```python app.py[email protected]('/create-link')+def hello():+ res = None++ try:+ res = d.links.create(request=operations.CreateLinkRequestBody(+ url='https://google.com',+ ))+ except Exception as e:+ return str(e)++ if res.link_schema is not None:+ return res.link_schema.short_link+```++<Accordion title="Full list of available attributes for the Link model">+ <LinkArguments />+</Accordion>++## 3a. Create link with `externalId`++Optionally, you can also pass an `externalId` field which is a unique identifier for the link in your own database to associate it with the link in Dub's system.++```python app.py[email protected]('/create-link')+def hello():+ res = None++ try:+ res = d.links.create(request=operations.CreateLinkRequestBody(+ url='https://google.com',+ external_id='12345',+ ))+ except Exception as e:+ return str(e)++ if res.link_schema is not None:+ return res.link_schema.short_link+```+## 4. Upsert link+Dub Python SDK provides a method to create or update a link so you don't have to worry about checking if the link already exists.++```python app.py[email protected]('/upsert-link')+def upsert():+ res = None++ try:+ res = d.links.upsert(request=operations.UpsertLinkRequestBody(+ url='https://google.com',+ ))+ except Exception as e:+ return str(e)++ if res.link_schema is not None:+ return res.link_schema.short_link+```+## 5. Update link+Let's update an existing link using the Dub Node.js SDK.++You can do that in two ways:++- Using the link's `linkId` in Dub's system.+- Using the link's `externalId` in your own database (prefixed with `ext_`).++```python app.py+# Update a link by its linkId[email protected]('/update-link')+def update():+ res = None++ try:+ res = d.links.update(link_id="clx1gvi9o0005hf5momm6f7hj", request_body=operations.UpdateLinkRequestBody(+ url='https://google.uk',+ ))+ except Exception as e:+ return str(e)++ if res.link_schema is not None:+ return res.link_schema.short_link+```+## 6. Retrieve analytics for link+Dub allows you to retrieve analytics for a link using the Dub Python SDK.++```python app.py[email protected]('/analytics')+def analytics():+ res = None++ try:+ # Retrieve the timeseries analytics for the last 7 days for a link+ res = d.analytics.retrieve(request=operations.RetrieveAnalyticsRequest(+ link_id="clx1gvi9o0005hf5momm6f7hj",+ interval="7d",+ group_by="timeseries",+ ))+ except Exception as e:+ return str(e)++ if res.one_of is not None:+ return res.one_of+```++Simliarly, you can retrieve analytics for a link using the `externalId` field.++```python app.py+# Retrieve the timeseries analytics for the last 7 days for a link+result = d.analytics.retrieve(request=operations.RetrieveAnalyticsRequest(+ external_id: 'ext_12345',+ interval="7d",+ group_by="timeseries",+))+```+## 7. Examples<CardGroup cols={2}><Card- title="Flask Example"+ title="Python Example"icon="arrow-up-right-from-square"- href="https://github.com/dubinc/examples"+ href="https://github.com/dubinc/examples/tree/main/python/flask">See the full example on GitHub.</Card></CardGroup>+```diff --git a/apps/docs/quickstart/python.mdx b/apps/docs/quickstart/python.mdxindex 1e1a1bbd2b..20a6db1c19 100644--- a/apps/docs/quickstart/python.mdx+++ b/apps/docs/quickstart/python.mdx@@ -15,7 +15,7 @@ To install the Dub Python SDK, run the following command:pip install dub```-Initialise the Dub Python SDK by creating a new instance of the `Dub` class.+initialize the Dub Python SDK by creating a new instance of the `Dub` class.```pythonimport os@@ -97,6 +97,7 @@ print(result.link_schema.short_link)Dub allows you to retrieve analytics for a link using the Dub Python SDK.```python index.py+# Retrieve the timeseries analytics for the last 7 days for a linkresult = d.analytics.retrieve(request=operations.RetrieveAnalyticsRequest(link_id="clx1gvi9o0005hf5momm6f7hj",interval="7d",@@ -109,13 +110,12 @@ print(result)Simliarly, you can retrieve analytics for a link using the `externalId` field.```python index.py+# Retrieve the timeseries analytics for the last 7 days for a linkresult = d.analytics.retrieve(request=operations.RetrieveAnalyticsRequest(external_id: 'ext_12345',interval="7d",group_by="timeseries",))--print(result)```## 7. Examples