FastAPI SDK
subdomainto-fastapi v0.1 supports Python 3.9+ and FastAPI 0.110+. It wraps the core subdomainto package.
Installation
pip install subdomainto-fastapi
Set SUBDOMAINTO_API_KEY, optional SUBDOMAINTO_BASE_URL, and SUBDOMAINTO_WEBHOOK_SECRET in the server environment.
Inject the client
from typing import Annotated
from fastapi import Depends, FastAPI
from subdomainto import SubdomainTo
from subdomainto_fastapi import SubdomainToClient
app = FastAPI()
@app.post("/customers/{customer_id}/domain")
def connect_domain(
customer_id: str,
client: Annotated[SubdomainTo, Depends(SubdomainToClient())],
):
return client.domains.create("portal.customer.com", f"{customer_id}-domain")
The dependency caches the default client. Creation still requires an explicit stable idempotency key.
Verify a webhook
from typing import Annotated
from fastapi import Depends
from subdomainto import WebhookEvent
from subdomainto_fastapi import SubdomainToWebhook
@app.post("/webhooks/subdomainto", status_code=204)
async def webhook(
event: Annotated[WebhookEvent, Depends(SubdomainToWebhook())],
):
return None
The asynchronous dependency reads the raw request body and SubdomainTo-Signature, using SUBDOMAINTO_WEBHOOK_SECRET by default. You may pass a secret and tolerance to its constructor. Invalid deliveries receive HTTP 400.