Skip to main content

python-digitalocean

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

image0

image1
image2
image3

How to install

You can install python-digitalocean using pip

pip install -U python-digitalocean

or via sources:

python setup.py install

Features

python-digitalocean support all the features provided via digitalocean.com 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

Examples

Listing the droplets

This example shows how to list all the active droplets:

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

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:
    droplet.shutdown()

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",
                               name='Example',
                               region='nyc2', # New York 2
                               image='ubuntu-14-04-x64', # Ubuntu 14.04 x64
                               size_slug='512mb',  # 512MB
                               backups=True)
droplet.create()

Checking the status of the droplet

actions = droplet.get_actions()
for action in actions:
    action.load()
    # 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/id_rsa.pub').read()
key = SSHKey(token='secretspecialuniquesnowflake',
             name='uniquehostname',
             public_key=user_ssh_key)
key.create()

Creating a new droplet with all your SSH keys

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

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

Testing

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

Metadata

Release files for python-digitalocean 1.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-digitalocean 1.17.0
File Size Uploaded
python-digitalocean-1.17.0.tar.gz 33.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-digitalocean 1.17.0
File Interpreter ABI Platform
python_digitalocean-1.17.0-py3-none-any.whl Python 3 none any Details

Total release size: 73.9 kB

Release files / python-digitalocean-1.17.0.tar.gz

Download URL python-digitalocean-1.17.0.tar.gz
Size 33.6 kB
Tags Source
SHA-256 checksum
How to use checksums
107854fde1aafa21774e8053cf253b04173613c94531f75d5a039ad770562b24
BLAKE2b-256 checksum
How to use checksums
f8f743cb73fb393c4c0da36294b6040c7424bc904042d55c1b37c73ecc9e7714
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / python_digitalocean-1.17.0-py3-none-any.whl

Download URL python_digitalocean-1.17.0-py3-none-any.whl
Size 40.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0032168e022e85fca314eb3f8dfaabf82087f2ed40839eb28f1eeeeca5afb1fa
BLAKE2b-256 checksum
How to use checksums
e44f87c17d4e23a62273c192656300e92a26bf6d5d8b2908cf2fc4a5a96da4b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release history Release notifications | RSS feed

This release

1.17.0 This release

2 release files

1.16.0

2 release files

1.15.0

1 release file

1.14.0

1 release file

1.13.2

2 release files

1.13.1

2 release files

1.12

2 release files

1.11

1 release file

1.10.1

1 release file

1.10.0

1 release file

1.9.0

1 release file

1.9

1 release file

1.8.1

1 release file

1.8

1 release file

1.7

2 release files

1.6

1 release file

1.5

1 release file

1.4.2

1 release file

1.4.1

1 release file

1.4

1 release file

1.3

1 release file

1.2

1 release file

1.1

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0

2 release files

0.7.1

1 release file

0.7

1 release file

0.6

1 release file

0.5.1

1 release file

0.5

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4

1 release file

0.3

1 release file

0.2.9

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page