{"id":13469341,"url":"https://github.com/koalalorenzo/python-digitalocean","last_synced_at":"2025-05-13T22:00:25.498Z","repository":{"id":6926660,"uuid":"8177778","full_name":"koalalorenzo/python-digitalocean","owner":"koalalorenzo","description":"🐍🐳 Python module to manage Digital Ocean droplets","archived":false,"fork":false,"pushed_at":"2023-08-09T22:18:23.000Z","size":679,"stargazers_count":1273,"open_issues_count":11,"forks_count":301,"subscribers_count":46,"default_branch":"main","last_synced_at":"2025-05-08T07:03:13.255Z","etag":null,"topics":["api","digitalocean","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koalalorenzo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2013-02-13T11:09:49.000Z","updated_at":"2025-05-07T21:30:04.000Z","dependencies_parsed_at":"2022-08-06T20:01:02.269Z","dependency_job_id":"47a0a423-8a8d-4080-92b2-59b7d4f67519","html_url":"https://github.com/koalalorenzo/python-digitalocean","commit_stats":{"total_commits":550,"total_committers":110,"mean_commits":5.0,"dds":0.6018181818181818,"last_synced_commit":"3d802463be6220ab044dc1e5d381c93e94365ac4"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koalalorenzo%2Fpython-digitalocean","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koalalorenzo%2Fpython-digitalocean/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koalalorenzo%2Fpython-digitalocean/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koalalorenzo%2Fpython-digitalocean/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koalalorenzo","download_url":"https://codeload.github.com/koalalorenzo/python-digitalocean/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253660846,"owners_count":21943823,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","digitalocean","python"],"created_at":"2024-07-31T15:01:34.814Z","updated_at":"2025-05-13T22:00:25.468Z","avatar_url":"https://github.com/koalalorenzo.png","language":"Python","readme":"\u003ch1 align=\"center\"\u003epython-digitalocean\u003c/h1\u003e\n\u003cp align=\"center\"\u003eEasy access to Digital Ocean APIs to deploy droplets, images and more.\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://travis-ci.org/koalalorenzo/python-digitalocean\"\u003e\u003cimg src=\"https://travis-ci.org/koalalorenzo/python-digitalocean.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/koalalorenzo/python-digitalocean\"\u003e\u003cimg src=\"https://img.shields.io/github/forks/koalalorenzo/python-digitalocean.svg?style=social\u0026label=Fork\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/koalalorenzo/python-digitalocean\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/koalalorenzo/python-digitalocean.svg?style=social\u0026label=Star\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/koalalorenzo/python-digitalocean\"\u003e\u003cimg src=\"https://img.shields.io/github/watchers/koalalorenzo/python-digitalocean.svg?style=social\u0026label=Watch\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Table of Contents\n\n- [How to install](#how-to-install)\n- [Configurations](#configurations)\n- [Features](#features)\n- [Examples](#examples)\n   - [Listing the droplets](#listing-the-droplets)\n   - [Listing the droplets by tags](#listing-the-droplets-by-tags)\n   - [Add a tag to a droplet](#add-a-tag-to-a-droplet)\n   - [Shutdown all droplets](#shutdown-all-droplets)\n   - [Creating a Droplet and checking its status](#creating-a-droplet-and-checking-its-status)\n   - [Creating a Reserved IP and Deleting it](#create-or-delete-reserved-ip)\n   - [Checking the status of the droplet](#checking-the-status-of-the-droplet)\n   - [Listing the Projects](#listing-the-projects)\n   - [Assign a resource for specific project](#assign-a-resource-for-specific-project)\n   - [List all the resources of a project](#list-all-the-resources-of-a-project)\n   - [Add SSHKey into DigitalOcean Account](#add-sshkey-into-digitalocean-account)\n   - [Creating a new droplet with all your SSH keys](#creating-a-new-droplet-with-all-your-ssh-keys)\n   - [Creating a Firewall](#creating-a-firewall)\n   - [Listing the domains](#listing-the-domains)\n   - [Listing records of a domain](#listing-records-of-a-domain)\n   - [Creating a domain record](#creating-a-domain-record)\n   - [Update a domain record](#update-a-domain-record)\n- [Getting account requests/hour limits status](#getting-account-requestshour-limits-status)\n- [Session customization](#session-customization)\n- [Testing](#testing)\n   - [Test using Docker](#test-using-docker)\n   - [Testing using pytest manually](#testing-using-pytest-manually)\n- [Links](#links)\n\n## How to install\n\nYou can install python-digitalocean using **pip**\n\n    pip install -U python-digitalocean\n\nor via sources:\n\n    python setup.py install\n\n**[⬆ back to top](#table-of-contents)**\n\n## Configurations\n\nSpecify a custom provider using environment variable\n\n    export DIGITALOCEAN_END_POINT=http://example.com/\n\nSpecify the DIGITALOCEAN_ACCESS_TOKEN using environment variable\n\n    export DIGITALOCEAN_ACCESS_TOKEN='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'\n\nNote: Probably want to add the export line above to your `.bashrc` file.\n\n**[⬆ back to top](#table-of-contents)**\n\n## Features\npython-digitalocean support all the features provided via digitalocean.com APIs, such as:\n\n* Get user's Projects\n* Assign a resource to a user project\n* List the resources of user's project\n* Get user's Droplets\n* Get user's Images (Snapshot and Backups)\n* Get public Images\n* Get Droplet's event status\n* Create and Remove a Droplet\n* Create or Delete Reserve IP\n* Create, Add and Remove Tags from Droplets\n* Resize a Droplet\n* Shutdown, restart and boot a Droplet\n* Power off, power on and \"power cycle\" a Droplet\n* Perform Snapshot\n* Enable/Disable automatic Backups\n* Restore root password of a Droplet\n\n**[⬆ back to top](#table-of-contents)**\n\n## Examples\n\n### Listing the Projects\n\nThis example shows how to list all the projects:\n\n```python\nimport digitalocean\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\nmy_projects = manager.get_all_projects()\nprint(my_projects)\n```\n\n### Assign a resource for specific project\n\n```python\nimport digitalocean\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\nmy_projects = manager.get_all_projects()\nmy_projects[0].assign_resource([\"do:droplet:\u003cDroplet Number\u003e\"])\n```\n\n### List all the resources of a project\n```python\nimport digitalocean\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\nmy_projects = manager.get_all_projects()\nresources = my_projects[0].get_all_resources()\nprint(resources)\n```\n\n### Listing the droplets\n\nThis example shows how to list all the active droplets:\n\n```python\nimport digitalocean\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\nmy_droplets = manager.get_all_droplets()\nprint(my_droplets)\n```\n\nThis example shows how to specify custom provider's end point URL:\n\n```python\nimport digitalocean\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\", end_point=\"http://example.com/\")\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Listing the droplets by tags\n\nThis example shows how to list all the active droplets:\n\n```python\nimport digitalocean\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\nmy_droplets = manager.get_all_droplets(tag_name=\"awesome\")\nprint(my_droplets)\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Add a tag to a droplet\n\nThis example shows how to add a tag to a droplet:\n\n```python\nimport digitalocean\ntag = digitalocean.Tag(token=\"secretspecialuniquesnowflake\", name=\"tag_name\")\ntag.create() # create tag if not already created\ntag.add_droplets([\"DROPLET_ID\"])\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Shutdown all droplets\n\nThis example shows how to shutdown all the active droplets:\n\n```python\nimport digitalocean\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\nmy_droplets = manager.get_all_droplets()\nfor droplet in my_droplets:\n    droplet.shutdown()\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Creating a Droplet and checking its status\n\nThis example shows how to create a droplet and how to check its status\n\n```python\nimport digitalocean\ndroplet = digitalocean.Droplet(token=\"secretspecialuniquesnowflake\",\n                               name='Example',\n                               region='nyc2', # New York 2\n                               image='ubuntu-20-04-x64', # Ubuntu 20.04 x64\n                               size_slug='s-1vcpu-1gb',  # 1GB RAM, 1 vCPU\n                               backups=True)\ndroplet.create()\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Create or Delete Reserved IP\n\nThis example shows how to create a reserved ip in specific region and delete it\n```python\nimport digitalocean\n\nfloating_ip = digitalocean.FloatingIP(region_slug='nyc2', token=\"secretspecialuniquesnowflake\")\n         \n# To Create IP\nstatic_ip = floating_ip.reserve()\nprint(static_ip)\n\n# To Delete IP\nrelease_static_ip = floating_ip.destroy()\nprint(release_static_ip) # returns True on success\n        \n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Checking the status of the droplet\n```python\nactions = droplet.get_actions()\nfor action in actions:\n    action.load()\n    # Once it shows \"completed\", droplet is up and running\n    print(action.status)\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Listing the Projects\n\nThis example shows how to list all the projects:\n\n```python\nimport digitalocean\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\nmy_projects = manager.get_all_projects()\nprint(my_projects)\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Assign a resource for specific project\n\n```python\nimport digitalocean\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\nmy_projects = manager.get_all_projects()\nmy_projects[0].assign_resource([\"do:droplet:\u003cDroplet Number\u003e\"])\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### List all the resources of a project\n```python\nimport digitalocean\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\nmy_projects = manager.get_all_projects()\nresources = my_projects[0].get_all_resources()\nprint(resources)\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Add SSHKey into DigitalOcean Account\n```python\nfrom digitalocean import SSHKey\n\nuser_ssh_key = open('/home/\u003c$USER\u003e/.ssh/id_rsa.pub').read()\nkey = SSHKey(token='secretspecialuniquesnowflake',\n             name='uniquehostname',\n             public_key=user_ssh_key)\nkey.create()\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Creating a new droplet with all your SSH keys\n```python\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\nkeys = manager.get_all_sshkeys()\n\ndroplet = digitalocean.Droplet(token=manager.token,\n                               name='DropletWithSSHKeys',\n                               region='ams3', # Amster\n                               image='ubuntu-20-04-x64', # Ubuntu 20.04 x64\n                               size_slug='s-1vcpu-1gb',  # 1GB RAM, 1 vCPU\n                               ssh_keys=keys, #Automatic conversion\n                               backups=False)\ndroplet.create()\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Creating a Firewall\n\nThis example creates a firewall that only accepts inbound tcp traffic on port 80 from a specific load balancer and allows outbound tcp traffic on all ports to all addresses.\n\n```python\nfrom digitalocean import Firewall, InboundRule, OutboundRule, Destinations, Sources\n\ninbound_rule = InboundRule(protocol=\"tcp\", ports=\"80\",\n                           sources=Sources(\n                               load_balancer_uids=[\n                                   \"4de7ac8b-495b-4884-9a69-1050c6793cd6\"]\n                               )\n                           )\n\noutbound_rule = OutboundRule(protocol=\"tcp\", ports=\"all\",\n                             destinations=Destinations(\n                               addresses=[\n                                   \"0.0.0.0/0\",\n                                   \"::/0\"]\n                                 )\n                             )\n\nfirewall = Firewall(token=\"secretspecialuniquesnowflake\",\n                    name=\"new-firewall\",\n                    inbound_rules=[inbound_rule],\n                    outbound_rules=[outbound_rule],\n                    droplet_ids=[8043964, 8043972])\nfirewall.create()\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Listing the domains\n\nThis example shows how to list all the active domains:\n\n```python\nimport digitalocean\nTOKEN=\"secretspecialuniquesnowflake\"\nmanager = digitalocean.Manager(token=TOKEN)\nmy_domains = manager.get_all_domains()\nprint(my_domains)\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Listing records of a domain\n\nThis example shows how to list all records of a domain:\n\n```python\nimport digitalocean\nTOKEN=\"secretspecialuniquesnowflake\"\ndomain = digitalocean.Domain(token=TOKEN, name=\"example.com\")\nrecords = domain.get_records()\nfor r in records:\n    print(r.name, r.domain, r.type, r.data)\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Creating a domain record\n\nThis example shows how to create new domain record (sub.example.com):\n\n```python\nimport digitalocean\nTOKEN=\"secretspecialuniquesnowflake\"\ndomain = digitalocean.Domain(token=TOKEN, name=\"example.com\")\nnew_record =  domain.create_new_domain_record(\n                type='A',\n                name='sub',\n                data='93.184.216.34'\n                )\nprint(new_record)\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n### Update a domain record\n\nThis example shows how to modify an existing domain record (sub.example.com):\n\n```python\nimport digitalocean\nTOKEN=\"secretspecialuniquesnowflake\"\ndomain = digitalocean.Domain(token=TOKEN, name=\"example.com\")\nrecords = domain.get_records()\nid = None\nfor r in records:\n    if r.name == 'sub':\n        r.data = '1.1.1.1'\n        r.save()\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n## Getting account requests/hour limits status\n\nEach request will also include the rate limit information:\n\n```python\nimport digitalocean\naccount = digitalocean.Account(token=\"secretspecialuniquesnowflake\").load()\n# or\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\naccount = manager.get_account()\n```\nOutput:\n```text\ndroplet_limit: 25\nemail: 'name@domain.me'\nemail_verified: True\nend_point: 'https://api.digitalocean.com/v2/'\nfloating_ip_limit: 3\nratelimit_limit: '5000'\nratelimit_remaining: '4995'\nratelimit_reset: '1505378973'\nstatus: 'active'\nstatus_message: ''\ntoken:'my_secret_token'\nuuid: 'my_id'\n```\n\nWhen using the Manager().get_all.. functions, the rate limit will be stored on the manager object:\n ```python\nimport digitalocean\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\ndomains = manager.get_all_domains()\n\nprint(manager.ratelimit_limit)\n```\n\n**[⬆ back to top](#table-of-contents)**\n\n## Session customization\n\nYou can take advantage of the [requests](http://docs.python-requests.org/en/master/) library and configure the HTTP client under python-digitalocean.\n\n### Configure retries in case of connection error\n\nThis example shows how to configure your client to retry 3 times in case of `ConnectionError`:\n```python\nimport digitalocean\nimport requests\nfrom requests.adapters import HTTPAdapter\nfrom requests.packages.urllib3.util.retry import Retry\n\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\nretry = Retry(connect=3)\nadapter = HTTPAdapter(max_retries=retry)\nmanager._session.mount('https://', adapter)\n```\n\nSee [`Retry`](https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#urllib3.util.retry.Retry) object reference to get more details about all retries options.\n\n### Configure a hook on specified answer\n\nThis example shows how to launch custom actions if a HTTP 500 occurs:\n\n```python\nimport digitalocean\n\ndef handle_response(response, *args, **kwargs):\n    if response.status_code == 500:\n        # Make a lot things from the raw response\n        pass\n    return response\n\nmanager = digitalocean.Manager(token=\"secretspecialuniquesnowflake\")\nmanager._session.hooks['response'].append(handle_response)\n```\n\nSee [event hooks documentation](http://docs.python-requests.org/en/master/user/advanced/?highlight=HTTPAdapter#event-hooks) to get more details about this feature.\n\n**[⬆ back to top](#table-of-contents)**\n\n## Testing\n\n### Test using Docker\nTo test this python-digitalocean you can use [docker](https://www.docker.com) to have a **clean environment automatically**. First you have to build the container by running in your shell on the repository directory:\n\n    docker build -t \"pdo-tests\" .\n\nThen you can run all the tests (for both python 2 and python 3)\n\n    docker run pdo-tests\n\n**Note**: This will use Ubuntu 14.04 as base and use your repository to run tests. So every time you edit some files, please run these commands to perform tests on your changes.\n\n**[⬆ back to top](#table-of-contents)**\n\n### Testing using pytest manually\nUse [pytest](http://pytest.org/) to perform testing. It is recommended to use a dedicated virtualenv to perform tests, using these commands:\n\n    $ virtualenv /tmp/digitalocean_env\n    $ source /tmp/digitalocean_env/bin/activate\n    $ pip install -r requirements.txt\n\nTo run all the tests manually use py.test command:\n\n    $ python -m pytest\n\n**[⬆ back to top](#table-of-contents)**\n\n## Links\n\n  * GitHub: [https://github.com/koalalorenzo/python-digitalocean](https://github.com/koalalorenzo/python-digitalocean)\n  * PyPI page: [https://pypi.python.org/pypi/python-digitalocean/](https://pypi.python.org/pypi/python-digitalocean/)\n  * Author Website: [http://who.is.lorenzo.setale.me/?](http://setale.me/)\n  * Author Blog: [http://blog.setale.me/](http://blog.setale.me/)\n\n**[⬆ back to top](#table-of-contents)**\n","funding_links":[],"categories":["Python","HarmonyOS"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoalalorenzo%2Fpython-digitalocean","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoalalorenzo%2Fpython-digitalocean","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoalalorenzo%2Fpython-digitalocean/lists"}