python-doctl¶
A Python wrapper for the excellent doctl command-line utility, from Digital Ocean.
This documentation exists to guide you through the usage of the doctl Python library — a Pythonic wrapper around the doctl command–line utility, for managing your DigitalOcean infrastructure.
Please enjoy!
Installation¶
Fist, ensure you have doctl installed on your system, then you can add python-doctl to your project with Pipenv:
$ pipenv install doctl
Introduction¶
The DIGITALOCEAN_ACCESS_TOKEN environment variable will automatically be honored.
$ export DIGITALOCEAN_ACCESS_TOKEN=xxxx
>>> import doctl>>> for droplet in doctl.compute.droplet.list(): ... print(droplet['name']) pypi.kennethreitz.org code.kennethreitz.org build.kennethreitz.org …>>> for key in doctl.compute.ssh_key.list(): ... print(key['name']) Blink (iPad) thoth macbook
Alternatively, you can pass a token in explicitly:
>>> from doctl import DigitalOcean
>>> doctl = DigitalOcean(token="xxxxx")
Things to Know¶
- All reasonable
doctlcommands are available as methods on within thedoctlmodule. Sub–commands are referenced with another method call (e.g.doctl.compute.ssh_key.list(). - All methods return Python data structures, includinging timezone–aware Datetime objects.
Notes¶
Use of the DIGITALOCEAN_ACCESS_TOKEN environment variable is recommended.
Available Namespaces¶
The entire API surface of doctl is covered by this library, so the following
namespaces are available for your use and enjoyment:
compute.accountcompute.actioncompute.certificatecompute.domaincompute.domain_recordscompute.dropletcompute.firewallcompute.floating_ipcompute.imagecompute.image_actioncompute.load_balancercompute.plugincompute.region_listcompute.size_listcompute.snapshotcompute.ssh_keycompute.tagcompute.volumecompute.volume_action
API Documentation¶
Main Interfaces¶
The Compute class is the main interface to doctl. A built in instance, doctl.compute is available at the module–level.
This is also an Account class, for viewing your authentication information, as well as your rate–limiting. A built in instance, doctl.account is available at the module–level.