SDKs overview
DigitalOcean provides Software Development Kits (SDKs) and client libraries to simplify interactions with its RESTful API. These libraries encapsulate the underlying HTTP requests and responses, allowing developers to manage DigitalOcean resources directly from their preferred programming environments. By using an SDK, developers can provision Droplets, configure load balancers, manage Kubernetes clusters, and interact with other DigitalOcean services using native language constructs rather than direct HTTP calls. The availability of SDKs for popular languages like Go, Python, Ruby, PHP, and JavaScript facilitates integration into various development workflows and application architectures.
The SDKs are designed to offer a consistent and intuitive interface across different languages, mirroring the structure and capabilities of the DigitalOcean API reference documentation. This approach aims to reduce the learning curve for developers already familiar with the DigitalOcean platform. Beyond official offerings, a vibrant community contributes additional libraries and tools, extending functionality and supporting niche use cases or alternative programming paradigms.
Official SDKs by language
DigitalOcean maintains official SDKs for several programming languages, which are actively developed and supported to ensure compatibility with the latest API versions and features. These SDKs provide methods for authenticating, making requests, handling responses, and managing errors, abstracting the complexities of direct API interaction.
| Language | Package/Module | Installation Command | Maturity |
|---|---|---|---|
| Go | github.com/digitalocean/godo |
go get github.com/digitalocean/godo |
Stable, Actively Maintained |
| Ruby | digitalocean_api (Gem) |
gem install digitalocean_api |
Stable, Actively Maintained |
| Python | python-digitalocean (PyPI) |
pip install python-digitalocean |
Stable, Actively Maintained |
| PHP | digitalocean/api-php (Composer) |
composer require digitalocean/api-php |
Stable, Actively Maintained |
| JavaScript | digitalocean-api-js (npm) |
npm install digitalocean-api-js |
Stable, Actively Maintained |
Installation
Installing a DigitalOcean SDK typically follows the standard package management practices for each respective language. The process generally involves using a command-line tool to add the SDK package to your project's dependencies.
Go
For Go projects, use the go get command to retrieve the godo package:
go get github.com/digitalocean/godo
After installation, you can import the package into your Go source files:
import (
"github.com/digitalocean/godo"
"golang.org/x/oauth2"
)
Ruby
Ruby developers typically use Bundler or RubyGems. To install the digitalocean_api gem:
gem install digitalocean_api
If you're using Bundler, add the following to your Gemfile and then run bundle install:
gem 'digitalocean_api'
Python
Python's package installer, pip, is used to install python-digitalocean:
pip install python-digitalocean
Once installed, you can import the library into your Python scripts:
import digitalocean
PHP
For PHP projects, Composer is the standard dependency manager. Add the DigitalOcean API client to your project:
composer require digitalocean/api-php
Composer will generate an autoloader that you can include in your application:
require 'vendor/autoload.php';
use DigitalOceanV2\Client;
JavaScript
Node.js projects or front-end applications can install the JavaScript SDK via npm or yarn:
npm install digitalocean-api-js
Or with yarn:
yarn add digitalocean-api-js
Then, import it into your JavaScript files:
import DigitalOcean from 'digitalocean-api-js';
Quickstart example
This quickstart example demonstrates how to list Droplets using the DigitalOcean API Python SDK. You will need a DigitalOcean API personal access token with read access to your account.
import digitalocean
import os
# Ensure your API token is set as an environment variable or replace 'YOUR_API_TOKEN' directly.
# For production, using environment variables for sensitive data like API tokens is recommended.
# For example: export DIGITALOCEAN_TOKEN="your_actual_token_here"
TOKEN = os.getenv("DIGITALOCEAN_TOKEN")
if not TOKEN:
print("Error: DIGITALOCEAN_TOKEN environment variable not set.")
print("Please set it using: export DIGITALOCEAN_TOKEN='your_api_token'")
exit(1)
# Initialize the DigitalOcean Manager with your API token
manager = digitalocean.Manager(token=TOKEN)
print("Fetching DigitalOcean Droplets...")
try:
# Retrieve a list of all Droplets
my_droplets = manager.get_all_droplets()
if my_droplets:
print(f"Found {len(my_droplets)} Droplets:")
for droplet in my_droplets:
print(f" Name: {droplet.name}, ID: {droplet.id}, IP: {droplet.ip_address}, Region: {droplet.region.slug}, Status: {droplet.status}")
else:
print("No Droplets found in your account.")
except Exception as e:
print(f"An error occurred while fetching Droplets: {e}")
To run this example:
- Install the Python SDK:
pip install python-digitalocean - Set your DigitalOcean API token as an environment variable:
export DIGITALOCEAN_TOKEN="YOUR_API_TOKEN"(replaceYOUR_API_TOKENwith your actual token). - Save the code as a
.pyfile (e.g.,list_droplets.py). - Execute the script:
python list_droplets.py
This script will connect to the DigitalOcean API using your token and print details for all Droplets associated with your account. For further details on managing tokens and API security, consult the Google APIs Client Library for Python authentication guide, which covers general best practices for API token handling, relevant for any API integration.
Community libraries
Beyond the officially supported SDKs, the DigitalOcean developer community has created numerous third-party libraries and tools, offering alternative language bindings, command-line interfaces (CLIs), and specialized utilities. These contributions often fill gaps for less commonly supported languages or provide different paradigms for interaction, such as declarative infrastructure-as-code tools or integrations with specific frameworks.
While official SDKs are maintained by DigitalOcean, community libraries often rely on volunteers. Developers should assess the maturity, active maintenance, and community support for any third-party library before incorporating it into production systems. Resources like GitHub and public package repositories are good starting points for discovering and evaluating these community-driven projects. For example, a search on GitHub for DigitalOcean API client repositories reveals a range of projects in various languages and for different purposes. Always verify the license, open issues, and contribution activity when considering community-developed tools to ensure they align with project requirements and security standards.
These community efforts expand the reach and flexibility of the DigitalOcean API, allowing a broader range of developers and system administrators to automate and manage their cloud infrastructure with greater customization and specialized tooling than might be directly available through official channels. The active ecosystem reflects the developer-centric focus of DigitalOcean, fostering innovation and extending the platform's utility.