NIC.RU API Python library
The package is the async library for the API of Russian DNS registrator Ru-Center (a.k.a. NIC.RU). It provides classes for managing DNS services, zones and records.
This project bases on: https://github.com/andr1an/nic-api
Installation
Using pip:
pip install aionic
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
import asyncio
from nic_api import NICApi
def print_token(token: dict):
print("Token:", token)
api = NICApi(
client_id = "---",
client_secret = "---",
username = "---/NIC-D",
password = "---",
scope = "GET:/dns-master/.+",
token_updater=print_token
)
# First you need to get token
async def main():
await api.get_token()
asyncio.run(main)
Get token
Call the get_token() method:
# First you need to get token
async def main():
await api.get_token()
asyncio.run(main)
Now you are ready to use the API.
A token can be saved anywhere, for example, to a file, using the callback: token_updater. It also could be used for authorization. Neither password nor username is required as long as the token is valid.
Viewing services and DNS zones
On 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:
async def main():
await api.zones('MY_SERVICE')
asyncio.run(main)
When starting a modification make sure that there is no any uncommited changes in the zone, cause they would be applied on commit.
Getting DNS records
One has to specify both service and DNS zone name to view or modify a record:
async def main():
await api.records('MY_SERIVCE', 'example.com')
asyncio.run(main)
Creating a record
To add a record, create an instance of one of the nic_api.models.DNSRecord subclasses, i.e. ARecord:
import aionic.models as nic_models
record_www = nic_models.ARecord(name='www', a='8.8.8.8', ttl=3600)
Add this record to the zone and commit the changes:
async def main():
await api.add_record(record_www, 'MY_SERVICE', 'example.com')
await api.commit('MY_SERVICE', 'example.com')
asyncio.run(main)
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:
async def main():
await api.delete_record(10, 'MY_SERVICE', 'example.com')
await api.commit('MY_SERVICE', 'example.com')
asyncio.run(main)
Do not forget to always commit the changes!
Metadata
Release files for aionic 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aionic-1.0.3.tar.gz | 2.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aionic-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.0 kB
Release files / aionic-1.0.3.tar.gz
| Download URL | aionic-1.0.3.tar.gz |
|---|---|
| Size | 2.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de395ef968c8ec0b45878bed01964f4af9507f49ce480166847860bc0f55895f
|
|
BLAKE2b-256 checksum How to use checksums |
3dbb502c36ab5b9cb510f58fb07916b6439214c2c9c9e7606bf584d1785c793c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Release files / aionic-1.0.3-py3-none-any.whl
| Download URL | aionic-1.0.3-py3-none-any.whl |
|---|---|
| Size | 2.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ec9ae1e48ea239a26b8b119e08559d20ec24ac3f261cd7e236779605a89c92e7
|
|
BLAKE2b-256 checksum How to use checksums |
d298fddcaa4eceea63746bf05b72dc2e991e47b57020c4f5676512eb5e30717e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|