Registry / http-networking / python-digitalocean

python-digitalocean

JSON →
library1.17.0pypypi✓ verified 87d ago

python-digitalocean is a community-maintained Python library for interacting with the DigitalOcean API, allowing management of resources like Droplets, Images, and more. It is currently at version 1.17.0 and receives releases for new API features and bug fixes. While widely used, DigitalOcean also provides an official client, `pydo`.

pip install python-digitalocean
INSTALL
IMPORT
SIG · PYTHON-DIGITALOCEA
P
python-digitalocean
http-networkingpythonv1.17.0
Install
2.2s avg
Import
639ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.17.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.671s · 21.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.2s · import 0.607s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Manager
from digitalocean import Manager
import digitalocean; manager = digitalocean.manager.Manager(...)
The common pattern is to import Manager directly or access it via the top-level 'digitalocean' package after 'import digitalocean'.
Droplet
from digitalocean import Droplet
SSHKey
from digitalocean import SSHKey

Initializes the DigitalOcean Manager with an API token from an environment variable and lists all active Droplets in your account. Requires a DigitalOcean API token with read access configured as DIGITALOCEAN_ACCESS_TOKEN.

import os import digitalocean # It's recommended to store your DigitalOcean API token as an environment variable # export DIGITALOCEAN_ACCESS_TOKEN='YOUR_API_TOKEN' api_token = os.environ.get('DIGITALOCEAN_ACCESS_TOKEN', '') if not api_token: print("Error: DIGITALOCEAN_ACCESS_TOKEN environment variable not set.") print("Please set it with your DigitalOcean API token.") else: try: manager = digitalocean.Manager(token=api_token) my_droplets = manager.get_all_droplets() if my_droplets: print("Your Droplets:") for droplet in my_droplets: print(f" - {droplet.name} (ID: {droplet.id}, Region: {droplet.region['slug']}, Status: {droplet.status})") else: print("No Droplets found in your account.") except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
gotchaThis library (`python-digitalocean`) is a community-maintained client. DigitalOcean also provides an *official* Python client library called `pydo`. Ensure you are using the client that best fits your project's needs and support expectations.
fix
Review the GitHub repositories (koalalorenzo/python-digitalocean vs. digitalocean/pydo) and documentation to choose the appropriate client. If switching to `pydo`, consult its separate documentation and import paths.
affects: All versions
breakingHardcoding DigitalOcean API tokens directly into your code is a significant security risk. Tokens provide full access to your account's resources.
fix
Always use environment variables (e.g., `DIGITALOCEAN_ACCESS_TOKEN`) or a secure configuration management system to store and retrieve API tokens. Ensure your tokens have the minimum necessary scopes/permissions.
affects: All versions
gotchaBe aware of API rate limits when making many requests. Repeatedly hitting rate limits can result in temporary blocking of your API access.
fix
Implement proper error handling for rate limit responses, introduce delays between API calls, or utilize caching mechanisms where appropriate.
affects: All versions
gotchaSome versions of `python-digitalocean` (e.g., 1.16.0-3 in Debian testing) have been reported to introduce bugs or be blocked from migration due to issues. This suggests potential instability depending on your environment or specific version.
fix
Always test new versions thoroughly in development environments before deploying to production. Check the project's GitHub issues for reported bugs related to your version and environment.
affects: Specific versions (e.g., 1.16.0-3)
Errors
Common errors & fixes
digitalocean.baseapi.TokenError: Unauthorized. Could not authenticate your request.
The DigitalOcean API token provided is missing, incorrect, expired, or does not have the necessary permissions.
fix
Ensure the `DIGITALOCEAN_ACCESS_TOKEN` environment variable is correctly set with a valid, active API token. Verify the token's scopes in your DigitalOcean account settings. Generate a new token if necessary.
AttributeError: module 'digitalocean' has no attribute 'Manager'
The `Manager` class was not imported correctly, or `digitalocean` was imported in a way that doesn't expose `Manager` at the top level, or there's a typo.
fix
Use `from digitalocean import Manager` or ensure `import digitalocean` is used, and then access it as `digitalocean.Manager(...)`. Check for typos in the class name.
digitalocean.baseapi.DataReadError: Cannot create a Droplet. The following errors occurred: Image is not available in the selected region.
Attempting to create a DigitalOcean resource (e.g., Droplet, Image) with invalid or incompatible parameters, such as an image slug not available in the specified region, or an incorrect size slug.
fix
Consult the DigitalOcean API documentation or the library's methods (e.g., `manager.get_all_images()`, `manager.get_all_regions()`, `manager.get_all_sizes()`) to retrieve valid and compatible parameters before attempting resource creation.
Upgrade
Version history
1.17.0latest on PyPI · released Oct 2, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
python-digitalocean — pip install python-digitalocean · libregistry