Skip to main content

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
oauth_config = {
    'APP_LOGIN': 'your_application_login',
    'APP_PASSWORD': 'your_application_secret'
}
api = DnsApi(oauth_config)

Authorization

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


Download files

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

Source Distribution

nic_api-0.2.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

nic_api-0.2.1-py2.py3-none-any.whl (22.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file nic_api-0.2.1.tar.gz.

File metadata

  • Download URL: nic_api-0.2.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for nic_api-0.2.1.tar.gz
Algorithm Hash digest
SHA256 237ad67542d2c22a45175fba02b3b2cb5bdda5a49b5feb14121e2d69a0c95242
MD5 ae0f6f6ae8992fb2f4332ab17f9dc37f
BLAKE2b-256 138e9ecc1f7bcee377618d7e88bcc1349e421cd62cd3e69c32c6aea2f52adbfe

See more details on using hashes here.

File details

Details for the file nic_api-0.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: nic_api-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for nic_api-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e3e8037e2b5648ad24d8a8ca1e93441bae175d50f4fedf7191d690c584033c9b
MD5 e9b898bc6f40d6e8902a7ee39dc8f206
BLAKE2b-256 86106424b71112364c0c83345ab1caa6a8c527cf9178e0c4a7fd20a46d53d215

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