{"id":10093,"library":"pydo","title":"DigitalOcean Python Client","description":"pydo is the official Python client library for interacting with the DigitalOcean API. It provides a programmatic interface to manage DigitalOcean resources such as Droplets, Kubernetes clusters, databases, and more. Currently at version 0.30.0, the library is frequently updated (often monthly minor releases) to reflect changes and additions to the DigitalOcean OpenAPI specification.","status":"active","version":"0.30.0","language":"en","source_language":"en","source_url":"https://github.com/digitalocean/pydo","tags":["cloud","digitalocean","api-client","infrastructure","devops"],"install":[{"cmd":"pip install pydo","lang":"bash","label":"Install pydo"}],"dependencies":[],"imports":[{"symbol":"Client","correct":"from pydo import Client"},{"note":"Import specific models like `models.Droplet` for type hinting or creating resources.","symbol":"models","correct":"from pydo import models"}],"quickstart":{"code":"import os\nfrom pydo import Client\nfrom pydo.models import Account\n\n# Initialize a client with your DigitalOcean API token.\n# It's highly recommended to set DIGITALOCEAN_TOKEN as an environment variable.\n# Example: export DIGITALOCEAN_TOKEN=\"YOUR_DO_TOKEN\"\n# For local testing without setting env var:\nDO_TOKEN = os.environ.get(\"DIGITALOCEAN_TOKEN\", \"YOUR_DO_TOKEN\") \n\nif DO_TOKEN == \"YOUR_DO_TOKEN\":\n    print(\"WARNING: Please set the DIGITALOCEAN_TOKEN environment variable for authentication.\")\n    print(\"Using a placeholder token for demonstration purposes. API calls will likely fail.\")\n\nclient = Client(token=DO_TOKEN)\n\ntry:\n    # Fetch current account information\n    account: Account = client.account.get_account()\n    print(f\"Account Email: {account.email}\")\n    print(f\"Droplet Limit: {account.droplet_limit}\")\n    print(f\"Email Verified: {account.email_verified}\")\n\n    # Example: List up to 5 Droplets (adjust for pagination on large accounts)\n    # droplets = client.droplets.list_droplets(per_page=5)\n    # if droplets:\n    #     print(f\"First Droplet Name: {droplets[0].name}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    if \"Unauthorized\" in str(e):\n        print(\"Please ensure your DigitalOcean API token is valid and correctly set.\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the DigitalOcean client using an API token (preferably from an environment variable) and then fetch basic account information. It also includes commented-out examples for listing resources like Droplets, highlighting the common pattern for interacting with different services."},"warnings":[{"fix":"Use `os.environ.get('DIGITALOCEAN_TOKEN')` to retrieve the token.","message":"Always store your DigitalOcean API token securely, preferably using environment variables (e.g., `DIGITALOCEAN_TOKEN`) rather than hardcoding it directly in your code. Hardcoded tokens pose a significant security risk.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the `pydo` documentation for specific list methods. For very large datasets, consider filtering requests or processing items in batches if direct iteration becomes inefficient.","message":"DigitalOcean API resources (like Droplets, Kubernetes clusters) often expose list operations that can return many items. While `pydo` aims to simplify this, be mindful of potential performance implications or memory usage when fetching very large lists, as some list methods may internally paginate to return a full collection.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the release notes for `pydo` and the DigitalOcean API documentation when upgrading to a new minor version, especially if you encounter `AttributeError` or unexpected API errors related to model structures.","message":"As `pydo` is generated from the DigitalOcean OpenAPI specification, minor version updates (e.g., 0.29.0 to 0.30.0) can introduce changes to the underlying API models or available endpoints. This might mean new required fields for creating resources, removed fields from existing models, or changes in method signatures.","severity":"gotcha","affected_versions":"All minor versions (e.g., v0.x.y updates)"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Verify that the `DIGITALOCEAN_TOKEN` environment variable is correctly set with a valid, active API token, or that the token passed directly to `Client(token=...)` is correct.","cause":"The DigitalOcean API token used for client initialization is either missing, expired, or incorrect.","error":"pydo.exceptions.UnauthorizedException: You provided an invalid token."},{"fix":"Consult the `pydo` library documentation or use IDE auto-completion to find the correct method name for the desired operation (e.g., `client.droplets.list_droplets()` for listing Droplets).","cause":"Attempting to call a non-existent method or a method with an incorrect name on a service object. For example, `client.droplets.list_all()` when the correct method is `client.droplets.list_droplets()`.","error":"AttributeError: 'DropletsService' object has no attribute 'list_all'"},{"fix":"Double-check the ID or name of the resource you are trying to access. Ensure it exists in your DigitalOcean account and that your API token has the necessary permissions to access it.","cause":"The specific resource (e.g., Droplet, Volume) identified by its ID or name does not exist or is not accessible under your account.","error":"pydo.exceptions.ResourceNotFoundException: The resource you requested could not be found."}]}