DigitalOcean Python SDK¶
A small, typed Python client for the DigitalOcean Domains and DNS API. It works in sync and async code, waits and retries when DigitalOcean rate limits you, and gives you plain dataclasses instead of raw JSON.
from digitalocean_sdk import DigitalOcean
with DigitalOcean("DIGITALOCEAN_TOKEN") as do:
do.dns.point("example.com", "shop", "203.0.113.10")
That call makes shop.example.com resolve to 203.0.113.10. If the record exists it is updated, if it is missing it is created, and extra A records with the same name are removed.
The package is on PyPI as digitalocean-python-sdk and is imported as digitalocean_sdk, so it can live next to the older python-digitalocean package. It needs Python 3.10 or newer.
Where to start¶
Set up a virtual environment, install the package with pip, uv or Poetry, and check that it imports.
Create a personal access token with the right scopes, and reuse the one doctl already has.
Write your first script: create a zone, read it and point a subdomain at a Droplet.
Pass settings in code, through DIGITALOCEAN_* environment variables or from a TOML, YAML or JSON file.
Create, list, read and delete the zones DigitalOcean DNS serves.
Records by id, create, update, delete, replace whole sets, and the shortcuts.
Complete scripts: a subdomain per customer, dynamic DNS, Let’s Encrypt DNS-01, Django and FastAPI.
Every public class, method and exception with its signature.
What the SDK covers¶
Domains: create, list, iterate, read (including the zone file), check and delete zones.
DNS: list and iterate records with server side filters, read by id, create, update, delete by id or by name, and make a whole set match a list of values.
DNS shortcuts:
point,unpoint,aliasandset_txt.Account: check the token with
account().Any other DigitalOcean endpoint (Droplets, volumes and more) through
request(), with the same authentication, retries and errors.Typed errors with DigitalOcean’s error code and request id.
Automatic retries for rate limits, server errors and dropped connections, only where a retry is safe.
Settings through goodconf: code, environment variables or a config file.
DIGITALOCEAN_TOKENis the same variabledoctland Terraform use.Every message the SDK prints lives in a YAML file you can translate.
It has three siblings with the same shape: the GoDaddy, Namecheap and Hostinger SDKs. dns.point("example.com", "shop", ip) does the same thing in all four.