NIC.RU API wrapper library
Project description
The package is a wrapper for the API of Russian DNS registrar Ru-Center (a.k.a. NIC.RU). The library provides classes for managing DNS services, zones and records.
Installation
Using pip:
pip install nic-api
If you want to use the module in your project, add this line to the project’s requirements.txt file:
nic-api
Usage
Setting up the OAuth credentials
To start using the API, you should get a pair of OAuth application login and password from NIC.RU. Here is the registration page: https://www.nic.ru/manager/oauth.cgi?step=oauth.app_register
Create a JSON file with the obtained credentials:
{ "APP_LOGIN": "your_application_login", "APP_PASSWORD": "your_application_secret" }
Make it secure and available to your Python app.
Initialization
Create an instance of nic_api.DnsApi and provide the filename of the application credentials storage you created above:
from nic_api import DnsApi api = DnsApi('/path/to/oauth_config.json')
Call the authorize() method and specify the username and the password of your NIC.RU account, and a file to store the OAuth token for future use:
api.authorize(username='Your_account/NIC-D', password='Your_password', token_filename='nic_token.json')
Now you are ready to use the API.
While the token in token_filename file is valid, you don’t need to provide neither username or password to access the API - just create an instance of the DnsApi class with the same OAuth config, and pass only token_filename to the authorize() method.
Viewing services and DNS zones
In the NIC.RU, DNS zones are located in “services”:
api.services()
Usually there is one service per account. Let’s view available zones in the service MY_SERVICE:
api.zones('MY_SERVICE')
Always check if the zone has any uncommitted changes to it before making any modifications - your commit will apply other changes too!
Getting DNS records
For viewing or modifying records, you need to specify both service and DNS zone name:
api.records('MY_SERIVCE', 'example.com')
Creating a record
To add a record, create an instance of one of the nic_api.models.DNSRecord subclasses, i.e. ARecord:
from nic_api.models import ARecord record_www = ARecord(name='www', a='8.8.8.8', ttl=3600)
Add this record to the zone and commit the changes:
api.add_record(record_www, 'MY_SERVICE', 'example.com') api.commit('MY_SERVICE', 'example.com')
Deleting a record
Every record in the zone has an unique ID, and it’s accessible via DNSRecord.id property. When you got the ID, pass it to the delete_record method:
api.delete_record(100000, 'MY_SERVICE', 'example.com') api.commit('MY_SERVICE', 'example.com')
Do not forget to always commit the changes!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nic_api-0.1.tar.gz
.
File metadata
- Download URL: nic_api-0.1.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a4738592440b39406b7b803c6fd3b35033f2e738cff220291754abf25ac1263 |
|
MD5 | d9a7f2a2e396156f53dabc3954e516b8 |
|
BLAKE2b-256 | 973979291784e929bc4e1347c2818539d01ca6816894459ed9eebde21b957e21 |
File details
Details for the file nic_api-0.1-py2-none-any.whl
.
File metadata
- Download URL: nic_api-0.1-py2-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 029b2af2c5dd7d6792676918dfdd66c120068c6fca97142c1bc37281173c1885 |
|
MD5 | fc7e159b649f8fda90829365a5d549c5 |
|
BLAKE2b-256 | ba71b2398eecf66994802acbdda6ae9bb2dfe17f92894c3478cf603ae809a9f8 |