Skip to main content

NIC.RU API Python library

Project description

The package is the library for the API of Russian DNS registrar Ru-Center (a.k.a. NIC.RU). It provides classes for managing DNS services, zones and records.

This fork: https://github.com/andr1an/nic-api

Async version: https://github.com/shizacat/aionic

Installation

Using pip:

pip install https://git+https://github.com/shizacat/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

from nic_api import DnsApi

def print_token(token: dict):
    print("Token:", token)

api = DnsApi(
    client_id = "---",
    client_secret = "---",
    username = "---/NIC-D",
    password = "---",
    scope = "GET:/dns-master/.+",
    token_updater=print_token
)

# First you need to get token
api.get_token()

Get token

Call the get_token() method:

# First you need to get token
api.get_token()

Now you are ready to use the API.

If you want, you may to save token to anything (example into file) throuht callback token_updater and then he had used for authorize. While the token is valie, you don’t need to provide neither username or password to access the API.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sh_nic_api-1.0.3.tar.gz (21.9 kB view details)

Uploaded Source

File details

Details for the file sh_nic_api-1.0.3.tar.gz.

File metadata

  • Download URL: sh_nic_api-1.0.3.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for sh_nic_api-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b2917dc9691c7359c3050ee67211187e7389500f24237297fc09af8660901ff2
MD5 8d265a8d2cc2b6f0c702e0d8cfdf7a48
BLAKE2b-256 326b8e0c81868f40576bb257fc03603c3da906e7d4b9d733e9a9b5de4813d984

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page