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
Initialization
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 an instance of nic_api.DnsApi and provide the OAuth application credentials:
from nic_api import DnsApi
app_login = "your_application_login"
app_password = "your_application_secret"
api = DnsApi(app_login, app_password)
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!
Default service and zone
The service and zone parameters can be optional in all DnsApi methods, if you set default_service and default_zone properties:
api.default_service = "MY_SERVICE"
api.default_zone = "example.com"
api.delete_record(100000) # service or zone are not needed
api.commit() # the same for commit() method
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 Distributions
Built Distribution
File details
Details for the file nic_api-0.4.0-py2.py3-none-any.whl
.
File metadata
- Download URL: nic_api-0.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e247f99af2bfb05168b384d9dc578d8d3f1449485d4bf256b57beffd82a50c3 |
|
MD5 | 7362b402ec4ead1404a3dab332ff50c7 |
|
BLAKE2b-256 | d53d06cda1440d5ed7c7149a7fdf30ec5b276de69bd640602a7c4877a70b6f54 |