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

# Django Quickstart

> Connect your first integration with a Django app using the BundleUp Python SDK.

Get started with BundleUp in a Django application. This guide walks you through connecting to a third-party API (**GitHub**, in this example) and then using the resulting `connection_id` to fetch data through the BundleUp unified API.

By the end of this guide, you'll:

* Redirect a user through an OAuth-style authorization flow
* Receive a `connection_id`
* Use that `connection_id` to make unified API calls via BundleUp

## Prerequisites

Before you begin, make sure you have:

* A [BundleUp account](https://www.bundleup.io)
* A BundleUp **API key** (server-side)
* Your BundleUp **Client ID** (used for authorization redirects)
* An **Integration ID** for the service you want to connect (for example, `github`)
* Python 3.10+ installed

<Info>
  You can find your API key, Client ID, and Integration IDs in the BundleUp dashboard.
</Info>

## Step 1: Create a Django project

If you don't already have a Django project:

```shellscript theme={null}
# create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate

# install Django
pip install Django

# create a new project
django-admin startproject bundleup_django
cd bundleup_django

# create an app
python manage.py startapp core
```

## Step 2: Install the BundleUp Python SDK

Install the official BundleUp SDK from PyPI:

```shellscript theme={null}
pip install bundleup-sdk
```

This package lets your Django server use BundleUp's unified API to fetch data after a user has authorized an integration.

## Step 3: Configure Django settings

Add Django view URLs and your environment configuration:

1. Create a `.env` file in your project root with:

```shellscript .env lines theme={null}
# server-side only
BUNDLEUP_API_KEY=your_api_key_here

# used for redirect
BUNDLEUP_CLIENT_ID=your_client_id_here
BUNDLEUP_INTEGRATION_ID=github
BUNDLEUP_REDIRECT_URI=http://localhost:8000/callback
```

2. Load these environment variables in `settings.py` (you can use [python-dotenv](https://pypi.org/project/python-dotenv/) or your own loader).
3. In `bundleup_django/urls.py`, add routes:

```shellscript bundleup_django/urls.py lines theme={null}
from django.urls import path
from core import views

urlpatterns = [
    path("", views.home, name="home"),
    path("callback", views.callback, name="callback"),
]
```

## Step 4: Create the authorization link

In `core/views.py`, add a view that redirects a user to the BundleUp authorization endpoint:

```python core/views.py lines theme={null}
import os
from django.http import HttpResponseRedirect
from django.shortcuts import render

def home(request):
    client_id = os.getenv("BUNDLEUP_CLIENT_ID")
    integration_id = os.getenv("BUNDLEUP_INTEGRATION_ID")
    redirect_uri = os.getenv("BUNDLEUP_REDIRECT_URI")

    url = (
        f"https://auth.bundleup.io/authorize?"
        f"client_id={client_id}"
        f"&integration_id={integration_id}"
        f"&redirect_uri={redirect_uri}"
    )

    return render(
        request,
        "home.html",
        {"auth_url": url}
    )
```

Create a simple template `core/templates/home.html` with:

```html core/templates/home.html lines theme={null}
<a href="{{ auth_url }}">Connect GitHub</a>
```

Clicking this link sends users to authorize GitHub, and then they're redirected back to `/callback`.

## Step 5: Handle the callback and fetch data

When BundleUp redirects back to `/callback`, it includes a `connection_id` query parameter. Here’s how to read it and make a unified API call with the Python SDK:

```python core/views.py lines theme={null}
import os
from django.shortcuts import render
from bundleup_sdk import BundleUp

def callback(request):
    error = request.GET.get("error")
    if error:
        return render(request, "callback.html", {"error": request.GET.get("error_description")})

    connection_id = request.GET.get("connection_id")
    client = BundleUp(os.getenv("BUNDLEUP_API_KEY"))

    # Example: fetch GitHub repos via unified API
    repos = client.unify(connection_id).git.repos()

    return render(request, "callback.html", {"repos": repos.data})
```

And in `core/templates/callback.html`:

```python core/templates/callback.html lines theme={null}
{% if error %}
<p>Error: {{ error }}</p>
{% else %}
<h2>Your Repositories</h2>
<ul>
  {% for repo in repos %}
    <li>{{ repo.full_name }}</li>
  {% endfor %}
</ul>
{% endif %}
```

**What’s happening here**

* `connection_id` ties a user + integration together
* The Python SDK then makes authenticated calls using that connection
* You can fetch repositories, calendar events, files, contacts, etc., depending on the integration

## Step 6: Run your development server

Start the Django server:

```shellscript theme={null}
python manage.py runserver
```

Visit [http://localhost:8000](http://localhost:8000), click **Connect GitHub**, authorize, and you’ll see a list of repositories.

## What’s next?

* Persist `connection_id` to your database for later use
* Add authenticated views that use the Python SDK to fetch user data
* Support additional integrations with no auth changes
