skip to navigation
skip to content

python-digitalocean 1.13.2 API to manage Droplets and Images

This library provides easy access to Digital Ocean APIs to deploy droplets, images and more.

How to install

You can install python-digitalocean using pip

pip install -U python-digitalocean

or via sources:

python install


python-digitalocean support all the features provided via APIs, such as:

  • Get user’s Droplets
  • Get user’s Images (Snapshot and Backups)
  • Get public Images
  • Get Droplet’s event status
  • Create and Remove a Droplet
  • Resize a Droplet
  • Shutdown, restart and boot a Droplet
  • Power off, power on and “power cycle” a Droplet
  • Perform Snapshot
  • Enable/Disable automatic Backups
  • Restore root password of a Droplet


Listing the droplets

This example shows how to list all the active droplets:

import digitalocean
manager = digitalocean.Manager(token="secretspecialuniquesnowflake")

Shutdown all droplets

This example shows how to shutdown all the active droplets:

import digitalocean
manager = digitalocean.Manager(token="secretspecialuniquesnowflake")
my_droplets = manager.get_all_droplets()
for droplet in my_droplets:

Creating a Droplet and checking its status

This example shows how to create a droplet and how to check its status

import digitalocean
droplet = digitalocean.Droplet(token="secretspecialuniquesnowflake",
                               region='nyc2', # New York 2
                               image='ubuntu-14-04-x64', # Ubuntu 14.04 x64
                               size_slug='512mb',  # 512MB

Checking the status of the droplet

actions = droplet.get_actions()
for action in actions:
    # Once it shows complete, droplet is up and running
    print action.status

Add SSHKey into DigitalOcean Account

from digitalocean import SSHKey

user_ssh_key = open('/home/<$USER>/.ssh/').read()
key = SSHKey(token='secretspecialuniquesnowflake',

Creating a new droplet with all your SSH keys

manager = digitalocean.Manager(token="secretspecialuniquesnowflake")
keys = manager.get_all_sshkeys()

droplet = digitalocean.Droplet(token="secretspecialuniquesnowflake",
                               region='ams3', # Amster
                               image='ubuntu-14-04-x64', # Ubuntu 14.04 x64
                               size_slug='512mb',  # 512MB
                               ssh_keys=keys, #Automatic conversion


Test using Docker

To test this python-digitalocean you can use docker to have a clean environment automatically. First you have to build the container by running in your shell on the repository directory:

docker build -t "pdo-tests" .

Then you can run all the tests (for both python 2 and python 3)

docker run pdo-tests

Note: This will use Ubuntu 14.04 as base and use your repository to run tests. So every time you edit some files, please run these commands to perform tests on your changes.

Testing using pytest manually

Use pytest to perform testing. It is recommended to use a dedicated virtualenv to perform tests, using these commands:

$ virtualenv /tmp/digitalocean_env
$ source /tmp/digitalocean_env/bin/activate
$ pip install -r requirements.txt

To run all the tests manually use py.test command:

$ python -m pytest
File Type Py Version Uploaded on Size
python-digitalocean-1.13.2.macosx-10.13-x86_64.tar.gz (md5)
built for Darwin-17.3.0
"dumb" binary any 2017-12-17 46KB
python-digitalocean-1.13.2.tar.gz (md5) Source 2017-12-17 22KB