Skip to main content

Python wrapper for Digital Ocean API V2.

Latest Version

Number of PyPI downloads

Travis Build

Installation

pip install dosa

Usage

import dosa

API_KEY = 'Your API Key'
dosa.set_debug()  # enables debug logs

client = dosa.Client(api_key=API_KEY)

# Droplets
client.droplets.list()
status, result = client.droplets.create(name='terminator', region='nyc2',\
    size='512mb', image='ubuntu-14-04-x32', ssh_keys=[12345])
new_droplet_id = result['id']

# Droplet
new_droplet = client.Droplet(new_droplet_id)
print(new_droplet.info())
## shortcuts
new_droplet.status()
new_droplet.ip_addresses()
client.droplets.delete(new_droplet_id)


# Get all available size configs
client.sizes.list()

# SSH Keys
pub_key = open('~/.ssh/id_rsa.pub').read()
client.keys.create(name='RSA key', public_key=pub_key)
client.keys.list()

# Images
client.images.list()
client.images.all()
client.images.search('ubuntu', 'sgp1', show_op=True)

# Domains
client.domains.list()
client.domains.all()
client.domains.create(name='example.com', ip_address='1.2.3.4')
client.domains.delete(id='example.com')

### Get specific domain
domain = client.Domain(domain='example.com')
domain.info()

# Domain Records
dr = client.DomainRecords(domain='example.com')
dr.list()
dr.create(type='A', name='example.com', data='162.10.66.0')

### Get specific domain record for a domain
record = dr.Record(record_id='7976006')
record.info()
record.update(name='new.example.com')

# Firewalls
## Create a firewall
params = {
 'inbound_rules': [{'ports': '22',
   'protocol': 'tcp',
   'sources': {'addresses': ['0.0.0.0/0', '::/0']}},
  {'ports': '80',
   'protocol': 'tcp',
   'sources': {'addresses': ['0.0.0.0/0', '::/0']}}],
 'name': 'firewall',
 'outbound_rules': [{'destinations': {'addresses': ['0.0.0.0/0', '::/0']},
   'ports': 'all',
   'protocol': 'tcp'}],
 'tags': []}
firewall = client.firewalls.create(**params)

# search firewall by name
firewall = client.firewalls.get_by_name('firewall')

## add a droplet to a firewall
firewall.add_droplet(new_droplet_id)

## remove a droplet from a firewall
firewall.remove_droplet(new_droplet_id)

## delete a firewall
client.firewalls.delete(id=firewall.id)

# Extras
# $ ls keys/
# rsa_pub1.id  rsa_pub2.key  rsa_pub3.key
keys_dir = 'keys'
client.sync_ssh_keys(keys_dir)

Notes

Image search:

>>> client.images.search('ubuntu', region='sgp1', show_op=True)

Above code snippets searches for images containing ubuntu in description or slug. Since region is specified (sgp1), only images in sgp1 region would be considered. If no region is specified all regions are included.

Tests:

>>> tox

To run tests, run tox in the root directory of the repo. It will create virtual environments specified in tox.ini, install dependancies, and run pytest.

Credits

Created while working on Scroll.in's project.

Dosa?

"Paper Masala Dosa" by SteveR- - http://www.flickr.com/photos/git/3936135033/. Licensed under Creative Commons Attribution 2.0 via Wikimedia Commons

Metadata

Release files for dosa 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dosa 1.0.0
File Size Uploaded
dosa-1.0.0.tar.gz 10.8 kB Details

Release files / dosa-1.0.0.tar.gz

Download URL dosa-1.0.0.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a71748036e1b2185d4aed2eaa39e477b147add464a525cc64abb107ebbbd9bf1
BLAKE2b-256 checksum
How to use checksums
3ee37f86eadf8b7be88ecca7833b95c1b7ff936f0f4d068619f560dc98db5757
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

0.10

2 release files

0.8

1 release file

0.7

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6

1 release file

0.5

1 release file

0.4.1

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page