Django SDK

subdomainto-django v0.1 supports Python 3.9+ and Django 4.2+. It wraps the core subdomainto package.

Installation

BASH
pip install subdomainto-django

Configuration

PYTHON
# settings.py
import os

SUBDOMAINTO_API_KEY = os.environ["SUBDOMAINTO_API_KEY"]
SUBDOMAINTO_BASE_URL = "https://api.subdomain.to/v1"
SUBDOMAINTO_WEBHOOK_SECRET = os.environ["SUBDOMAINTO_WEBHOOK_SECRET"]
SUBDOMAINTO_WEBHOOK_TOLERANCE = 300

Only SUBDOMAINTO_API_KEY is required for API calls. Keep every secret in server settings.

Use the cached client

PYTHON
from subdomainto_django import get_client

client = get_client()
domain = client.domains.create("portal.customer.com", "customer-42-domain")

Verify a webhook view

PYTHON
from django.http import HttpResponse
from subdomainto_django import verify_subdomainto_webhook

@verify_subdomainto_webhook
def subdomainto_webhook(request):
    event = request.subdomainto_event
    return HttpResponse(status=204)

The decorator verifies the raw request.body and SubdomainTo-Signature, then places the event on request.subdomainto_event. Invalid deliveries receive 400 before the view runs.