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
app_login = "your_application_login"
app_password = "your_application_secret"
api = DnsApi(app_login, app_password)

Authorization

Call the get_token() method and specify the username and the password for your NIC.RU account:

api.get_token(
    username="Your_account/NIC-D",
    password="Your_password",
)

Now you are ready to use the API.

While the token is valid, you don’t need to provide neither client username or password to access the API – just create an instance of the DnsApi class with the same OAuth config, and pass the cached token as token parameter:

api = DnsApi(app_login, app_password, token)

If you have a valid refresh token, you can get a new access token with it:

api.refresh_token(refresh_token)

You can add a callback to cache the token with token_updater_clb parameter of the class constructor.

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


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.4.2.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

nic_api-0.4.2-py2.py3-none-any.whl (23.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: nic_api-0.4.2.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for nic_api-0.4.2.tar.gz
Algorithm Hash digest
SHA256 2b21f3798f8fd7b376cecbe204e3b0e0e4ef9f7faf10021d5eed9c5fbec452d0
MD5 42513158385a56a78f6e5cd6aee5f95d
BLAKE2b-256 fd0b0253ee766bf237004d0d3a2101e00799d47f10b30b197fb0c0cbc628492d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nic_api-0.4.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for nic_api-0.4.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1e79c11b548ffecea14497885ad807114878492d4320767d2cc0899a944a0976
MD5 627649e2dae350ff8d32a035fd226cee
BLAKE2b-256 4237928075757506d6c830b676718fca0c9341877fa39db1ca5e0887afc9fef3

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