NIC.RU Async API Python library
Project description
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!
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 aionic-1.0.3.tar.gz
.
File metadata
- Download URL: aionic-1.0.3.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de395ef968c8ec0b45878bed01964f4af9507f49ce480166847860bc0f55895f |
|
MD5 | 2e212e0d4a858eb52cf34652c61dd124 |
|
BLAKE2b-256 | 3dbb502c36ab5b9cb510f58fb07916b6439214c2c9c9e7606bf584d1785c793c |
File details
Details for the file aionic-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: aionic-1.0.3-py3-none-any.whl
- Upload date:
- Size: 2.4 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec9ae1e48ea239a26b8b119e08559d20ec24ac3f261cd7e236779605a89c92e7 |
|
MD5 | 0c13565ed7313e44151c52818a6eb78a |
|
BLAKE2b-256 | d298fddcaa4eceea63746bf05b72dc2e991e47b57020c4f5676512eb5e30717e |