> ## Documentation Index
> Fetch the complete documentation index at: https://pearset/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK

> Learn how to integrate Pearset with Python.

## Installation

```bash theme={null}
pip install pearset
```

## Basic Usage

Here's how you can use the Pearset Python SDK to create a link and retrieve click analytics in timeseries format for it:

```python theme={null}
import os
import pearset
from pearset.models import operations

# Initialize the Pearset SDK with your API key
d = pearset.Pearset(
    token=os.environ['DUB_API_KEY'], # optional, defaults to DUB_API_KEY
)

# Create a new link
res = d.links.create(request={
    "url": "https://google.com",
})

print(res.short_link) # e.g. https://pearset.sh/abc123

# Get analytics for the link
analytics = d.analytics.retrieve(request={
    "link_id": res.id,
    "interval": "30d",
    "group_by": "timeseries",
})

print(analytics) # e.g. [{ "start": "2024-01-01", "clicks": 100 }]
```

For more usage examples:

1. [Organizing links by external ID, tenant ID, tags, etc](/docs/concepts/links/organization)
2. [Bulk link operations (create, update, delete)](/docs/concepts/links/bulk-operations)
3. [Retrieving link analytics](/docs/concepts/analytics)

## Frameworks

You can use the Pearset Python SDK with any Python framework:

1. [Usage with Flask](/docs/sdks/quickstart/flask)
2. [Usage with Django](/docs/sdks/quickstart/django)

If you're using a different Python framework, you can refer to the [Python SDK quickstart](/docs/sdks/quickstart/python) for a basic example.

## Additional Resources

<CardGroup cols={2}>
  <Card title="PyPI Package" icon="python" href="https://d.to/python/sdk">
    Download and install the Pearset Python SDK on PyPI
  </Card>

  <Card title="SDK Reference" icon="book" iconType="solid" href="https://github.com/pearset/pearset-python/blob/main/README.md">
    View the complete SDK reference documentation
  </Card>

  <Card title="Examples" icon="github" href="https://github.com/pearset/examples/tree/main/python">
    Quickstart examples with the Python SDK
  </Card>

  <Card title="Source Code" icon="github" href="https://github.com/pearset/pearset-python">
    View the complete source code for the Pearset Python SDK
  </Card>
</CardGroup>
