Skip to main content

An API client for ICANN's Centralized Zone Data Service (CZDS). Learn more under https://czds.icann.org/.

Project description

pyCZDS – An API client for ICANN's Centralized Zone Data Service (CZDS)

This package allows you to seamlessly interact with ICANN's CZDS and download zone files for participating Top-Level Domains.

The Centralized Zone Data Service (CZDS) is an online portal where any interested party can request access to the Zone Files provided by participating generic Top-Level Domains (gTLDs).

Source

Relevant links:

Installation

This package requires Python 3 and has been tested with Python 3.10.8. It requires the requests package. The library implements a client against the official API documentation which can be found under this link.

Install pyCZDS with the command pip install pyCZDS.

Usage

The library supports the following actions:

  • client.get_zonefiles_list – retrieves the download links all zone files the respective account is authorized to access;
  • client.head_zonefile – retrieves the headers for a specified zone file, which contain metadata such as the last modified timestamp and the file's size;
  • client.get_zonefile – download a specified zone file.

Instantiating a client

Use the following code to create a new CZDSClient object:

from pyczds.client import CZDSClient

# replace username and password with actual credentials
c = CZDSClient(username, password)

The client handles the authentication with the API transparently. It will authenticate with the first call of any method, and will retain the acquired token for subsequent requests. When the token expires, it will renew the authentication automatically.

Getting zone file download URLs

The following command will retrieve a list of all zone files the account is authorized to access. It returns a list with the respective URLs.

print(c.get_zonefiles_list())
# [
    'https://czds-download-api.icann.org/czds/downloads/net.zone',
    ...
    'https://czds-download-api.icann.org/czds/downloads/com.zone'
]

Requests for accessing additional zone files can be made online under this link.

Requesting the headers for a zone file

Using one of the links received via get_zonefiles_list(), the following command will retrieve the headers for a specified zonefile. It returns a dict:

print(c.head_zonefile('https://czds-download-api.icann.org/czds/downloads/vision.zone'))
# {
    'Date': 'Fri, 16 Dec 2022 19:42:58 GMT',
    ...
    'Last-Modified': 'Fri, 16 Dec 2022 01:29:08 GMT',
    ...
    'Content-Disposition': 'attachment;filename=vision.txt.gz',
    ...
    'Content-Length': '602034',
    ...
}

Downloading a zone file

The following command will download a specified zone file:

c.get_zonefile('https://czds-download-api.icann.org/czds/downloads/vision.zone', download_dir='zonefiles/', filename='vision_zonefile')

Both parameters are optional.

  • download_dir sets the local directory where the file should be downloaded to. If it is not passed, the file will be downloaded to the working directory of your script.
  • filename sets the local filename of the downloaded file. If it is not passed, the filename will be set according to the value the API provides in the Content-Disposition header, e.g., vision.tar.gz.

Troubleshooting

Should you encounter errors, a good first step is to increase the logging level to debug and then analyze the output.

import logging

from pyczds import client

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

# Run the problematic command
c = client.CZDSClient(username, password)

Tests

The entire codebase is covered. Run the test from the tests directory. Before you do so, make sure you set username and password in tests/test_pyczds.py:

class TestPyCZDS(unittest.TestCase):
    def setUp(self):
        # In order to run these tests, enter your valid username and password for the CZDS website here.
        # Please note that these tests do not change any data.

        # TODO PASTE USERNAME AND PASSWORD HERE
        username = ''
        password = ''
        # END TODO

Legal disclaimer

I am a hobby enthusiast and am neither affiliated with ICANN, nor is this library endorsed by ICANN.

Links and further information

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

pyCZDS-1.2.1.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

pyCZDS-1.2.1-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file pyCZDS-1.2.1.tar.gz.

File metadata

  • Download URL: pyCZDS-1.2.1.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for pyCZDS-1.2.1.tar.gz
Algorithm Hash digest
SHA256 9e048fda0535920054685e06e6f829624c7e4a11e9427ff6cbd15bb2f542edbf
MD5 8347fef29fb91a4cc50522bb67dda86c
BLAKE2b-256 464467389c7488e3aec6e9fbddefc716a16815bc43738738d763000be6f1b900

See more details on using hashes here.

File details

Details for the file pyCZDS-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: pyCZDS-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for pyCZDS-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fab50ccf86941e0f0f3c3bc07507263748b97a04508331094557b518cc73284c
MD5 5483510071a9839053668d5b91e95922
BLAKE2b-256 f438a9ffe25a455d0b22da302a8bacb96da1960e08dae44ff22d1179f5028491

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