{"id":7625,"library":"python-digitalocean","title":"Python DigitalOcean API Client (Community)","description":"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`.","status":"active","version":"1.17.0","language":"en","source_language":"en","source_url":"https://github.com/koalalorenzo/python-digitalocean","tags":["digitalocean","cloud","api","iaas","droplets","community-maintained"],"install":[{"cmd":"pip install python-digitalocean","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"The common pattern is to import Manager directly or access it via the top-level 'digitalocean' package after 'import digitalocean'.","wrong":"import digitalocean; manager = digitalocean.manager.Manager(...)","symbol":"Manager","correct":"from digitalocean import Manager"},{"symbol":"Droplet","correct":"from digitalocean import Droplet"},{"symbol":"SSHKey","correct":"from digitalocean import SSHKey"}],"quickstart":{"code":"import os\nimport digitalocean\n\n# It's recommended to store your DigitalOcean API token as an environment variable\n# export DIGITALOCEAN_ACCESS_TOKEN='YOUR_API_TOKEN'\napi_token = os.environ.get('DIGITALOCEAN_ACCESS_TOKEN', '')\n\nif not api_token:\n    print(\"Error: DIGITALOCEAN_ACCESS_TOKEN environment variable not set.\")\n    print(\"Please set it with your DigitalOcean API token.\")\nelse:\n    try:\n        manager = digitalocean.Manager(token=api_token)\n        my_droplets = manager.get_all_droplets()\n        if my_droplets:\n            print(\"Your Droplets:\")\n            for droplet in my_droplets:\n                print(f\"  - {droplet.name} (ID: {droplet.id}, Region: {droplet.region['slug']}, Status: {droplet.status})\")\n        else:\n            print(\"No Droplets found in your account.\")\n    except Exception as e:\n        print(f\"An error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"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.","message":"This 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Hardcoding DigitalOcean API tokens directly into your code is a significant security risk. Tokens provide full access to your account's resources.","severity":"breaking","affected_versions":"All versions"},{"fix":"Implement proper error handling for rate limit responses, introduce delays between API calls, or utilize caching mechanisms where appropriate.","message":"Be aware of API rate limits when making many requests. Repeatedly hitting rate limits can result in temporary blocking of your API access.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Some 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.","severity":"gotcha","affected_versions":"Specific versions (e.g., 1.16.0-3)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"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.","cause":"The DigitalOcean API token provided is missing, incorrect, expired, or does not have the necessary permissions.","error":"digitalocean.baseapi.TokenError: Unauthorized. Could not authenticate your request."},{"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.","cause":"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.","error":"AttributeError: module 'digitalocean' has no attribute 'Manager'"},{"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.","cause":"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.","error":"digitalocean.baseapi.DataReadError: Cannot create a Droplet. The following errors occurred: Image is not available in the selected region."}]}