Using the python-digitalocean Library to Manage Digital Ocean Droplets

Overview

Digital Ocean is a fantastic hosting provider for simple SSD cloud servers built with developers in mind. Since I develop pretty much everything in Python these days, I like to keep as much of my automation and other tasks in python as well. Recently, I found a nice little python wrapper for the Digital Ocean API that makes communicating with your droplets super easy.

The documentation is lacking, although it seems to follow the syntax of the official Digital Ocean API quite well. You can do many, many different things through the API such as creating/destroying droplets, re-sizing droplets, surveying images, etc. The task I use it for most often is automating snapshots. A snapshot can be used as a backup, or for spinning up an identical server elsewhere. For information on the difference between backups and snapshots, check out this article.

Automate Snapshots through the Digital Ocean API

Install the python-digitalocean library

pip install -U python-digitalocean

Get API and Client Keys

This can be found in the developer section of your Digital Ocean settings. Simply click Generate New Key

Get Droplet ID

I am really not sure of the easiest way to find the droplet ID; however, I usually grab it through the API as you will see below