|
| 1 | +Python DNSimple |
| 2 | +=============== |
| 3 | + |
| 4 | +## Introduction |
| 5 | + |
| 6 | +This is a client for the [DNSimple REST API](https://developer.dnsimple.com/). It currently allows you to fetch existing domain info, as well as register new domains and manage domain records. |
| 7 | + |
| 8 | +`dnsimple-python` works for both python 2 & 3. |
| 9 | + |
| 10 | +**Note:** As of 1.0.0 this now uses [DNSimple's APIv2](https://blog.dnsimple.com/2016/12/api-v2-stable/). This has some incompatibilities with APIv1, including auth changes. Please test for breakages before use. |
| 11 | + |
| 12 | +### Getting started |
| 13 | + |
| 14 | +You'll need the `json` module that is included with python version 2.6 and later, or the `simplejson` module if you are using an earlier version. |
| 15 | + |
| 16 | +`dnsimple-python` also depends on the `requests` library. |
| 17 | + |
| 18 | +Import the module: |
| 19 | + |
| 20 | +```python |
| 21 | +from dnsimple import DNSimple |
| 22 | +``` |
| 23 | + |
| 24 | +You can provide your DNSimple credentials in one of two ways: |
| 25 | + |
| 26 | +#### Provide username/password or email/api\_token credentials programmatically: |
| 27 | + |
| 28 | +```python |
| 29 | +# Use username/password authentication: HTTP Basic |
| 30 | +dns = DNSimple(username=YOUR_USERNAME, password=YOUR_PASSWORD) |
| 31 | + |
| 32 | +# Use email/api_token credentials |
| 33 | +dns = DNSimple(api_token=YOUR_API_TOKEN) |
| 34 | + |
| 35 | +# If you have many accounts you can provide account_id (661 is an example) |
| 36 | +# You can find your account id in url (https://sandbox.dnsimple.com/a/661/account) |
| 37 | +dns = DNSimple(username=YOUR_USERNAME, password=YOUR_PASSWORD, account_id=661) |
| 38 | +``` |
| 39 | + |
| 40 | +##### Store you username/password or email/api\_token credentials in a file called `.dnsimple` in the current directory with the following data: |
| 41 | + |
| 42 | +``` |
| 43 | +[DNSimple] |
| 44 | + |
| 45 | +password: yourpassword |
| 46 | +``` |
| 47 | + |
| 48 | +Or: |
| 49 | + |
| 50 | +``` |
| 51 | +[DNSimple] |
| 52 | +api_token: yourapitoken |
| 53 | +``` |
| 54 | + |
| 55 | +Or (assuming `$DNSIMPLE_EMAIL` and `$DNSIMPLE_TOKEN` are environment variables): |
| 56 | + |
| 57 | +``` |
| 58 | +[DNSimple] |
| 59 | +email: %(DNSIMPLE_EMAIL)s |
| 60 | +api_token: %(DNSIMPLE_TOKEN)s |
| 61 | +``` |
| 62 | + |
| 63 | +You then need not provide any credentials when constructing `DNSimple`: |
| 64 | + |
| 65 | +```python |
| 66 | +dns = DNSimple() |
| 67 | +``` |
| 68 | + |
| 69 | +## Domain Operations |
| 70 | + |
| 71 | +### Check out your existing domains: |
| 72 | + |
| 73 | +Just run: |
| 74 | + |
| 75 | +```python |
| 76 | +domains = dns.domains() |
| 77 | +``` |
| 78 | + |
| 79 | +Results appear as a Python dict: |
| 80 | + |
| 81 | +```python |
| 82 | +{'domain': {'created_at': '2010-10-14T09:45:32Z', |
| 83 | + 'expires_at': '10/14/2011 5:45:00 AM', |
| 84 | + 'id': 999, |
| 85 | + 'last_enom_order_id': None, |
| 86 | + 'name': 'yourdomain.com', |
| 87 | + 'name_server_status': 'active', |
| 88 | + 'registrant_id': 99, |
| 89 | + 'registration_status': 'registered', |
| 90 | + 'updated_at': '2010-10-14T10:00:14Z', |
| 91 | + 'user_id': 99}}, |
| 92 | +{'domain': {'created_at': '2010-10-15T16:02:34Z', |
| 93 | + 'expires_at': '10/15/2011 12:02:00 PM', |
| 94 | + 'id': 999, |
| 95 | + 'last_enom_order_id': None, |
| 96 | + 'name': 'anotherdomain.com', |
| 97 | + 'name_server_status': 'active', |
| 98 | + 'registrant_id': 99, |
| 99 | + 'registration_status': 'registered', |
| 100 | + 'updated_at': '2010-10-15T16:30:16Z', |
| 101 | + 'user_id': 99}}] |
| 102 | +``` |
| 103 | + |
| 104 | +### Get details for a specific domain |
| 105 | + |
| 106 | +```python |
| 107 | +dns.domain('mikemaccana.com') |
| 108 | +``` |
| 109 | + |
| 110 | +Results are the same as `domains()` above, but only show the domain specified. |
| 111 | + |
| 112 | +### Check whether a domain is available |
| 113 | + |
| 114 | +```python |
| 115 | +dns.check('google.com') |
| 116 | + |
| 117 | +# Hmm, looks like I'm too late to get that one... |
| 118 | +{u'currency': u'USD', |
| 119 | +u'currency_symbol': u'$', |
| 120 | +u'minimum_number_of_years': 1, |
| 121 | +u'name': u'google.com', |
| 122 | +u'price': u'14.00', |
| 123 | +u'status': u'unavailable'} |
| 124 | +``` |
| 125 | + |
| 126 | +### Register a new domain |
| 127 | + |
| 128 | +```python |
| 129 | +dns.register('newdomain.com') |
| 130 | +``` |
| 131 | + |
| 132 | +This will register 'newdomain.com', automatically picking the registrant\_id from your first domain. To specify a particularly `registrant_id`, just run: |
| 133 | + |
| 134 | +```python |
| 135 | +dns.register('newdomain.com', 99) |
| 136 | +``` |
| 137 | + |
| 138 | +Responses will be in a dictionary describing the newly created domain, same as the `domain()` call above. |
| 139 | + |
| 140 | +### Delete a domain |
| 141 | + |
| 142 | +Careful with this one! |
| 143 | + |
| 144 | +```python |
| 145 | +dns.delete('domain-to-die.com') |
| 146 | +``` |
| 147 | + |
| 148 | +## Record operations |
| 149 | + |
| 150 | +All operations on domain records are now supported: |
| 151 | + |
| 152 | +* List records: `records(id_or_domainname)` |
| 153 | +* Get record details: `record(id_or_domainname, record_id)` |
| 154 | +* Add record: `add_record(id_or_domainname, data)` |
| 155 | +* Update record: `update_record(id_or_domainname, record_id, data)` |
| 156 | +* Delete record: `delete_record(id_or_domainname, record_id)` |
| 157 | + |
| 158 | +## Running Tests |
| 159 | + |
| 160 | +Before running tests, you'll need to ensure your environment is set up correctly: |
| 161 | + |
| 162 | +1. If you don't already have a DNSimple sandbox account, [create one](https://sandbox.dnsimple.com/signup) and make sure to have your email address, password, and API token handy. |
| 163 | +1. Ensure you have the `virtualenv` package installed (`pip install virtualenv --upgrade`) since tests are run from this isolated environment |
| 164 | +1. Copy the file `tests/.env.example` to `tests/.env` and supply your sandbox credentials |
| 165 | +1. From the project root, run `make test` -- this will set up your local environment with `virutalenv`, install all necessary dependencies, and run all the tests. |
| 166 | + |
| 167 | +## License |
| 168 | + |
| 169 | +Licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.php) |
| 170 | + |
| 171 | +## Authors |
| 172 | + |
| 173 | +* Original Author [Mike MacCana](https://github.com/mikemaccana/) |
| 174 | +* APIv2 Support [Kirill Motkov](https://github.com/lcd1232) |
0 commit comments