Skip to main content

Python implementation of DNSLink protocol

Project description

DNSLink for Python

version downloads license python

linux build windows build coverage quality

Python implementation of DNSLink protocol.

Description

DNSLink is a very simple protocol to link content and services directly from DNS. DNSLink leverages the powerful distributed architecture of DNS for a variety of systems that require internet-scale mutable names or pointers. For more details see DNSLink website.

This package provides a simple way to get and resolve DNSLink TXT records for any domain name.

Installation

Requirements

DNSLink requires Python 3.5 or higher.

From PyPI

The recommended way to install DNSLink is from PyPI with PIP.

pip install dnslink

From Source

Alternatively, you can also install it from the source.

git clone https://github.com/filips123/DNSLinkPy.git
cd DNSLinkPy
python setup.py install

Usage

You can use a resolve function to resolve DNSLink records for a specific domain. It first tries to resolve the domain's _dnslink subdomain and then fall back to the main domain if no records were found.

Note: To illustrate examples, we will assume that domains are using this example DNSLink configuration.

$ dig +short TXT example.com
dnslink=/ipfs/QmaYRVyPKpN8FXy9HS1t9Zhtjo4RpYXgiuNj1ins9fiLuW
dnslink=/ipns/website.ipfs.io

$ dig +short TXT foo.com
dnslink=/dnslink/bar.com

$ dig +short TXT bar.com
dnslink=/ipfs/QmaYRVyPKpN8FXy9HS1t9Zhtjo4RpYXgiuNj1ins9fiLuW

The function takes a domain name as a first (domain) argument and returns a list of all DNSLink records for that domain.

import dnslink

domain = 'example.com'
records = dnslink.resolve(domain=domain)

for record in records:
    print(record)

# /ipfs/QmaYRVyPKpN8FXy9HS1t9Zhtjo4RpYXgiuNj1ins9fiLuW
# /ipns/website.ipfs.io

It is also possible to get only DNSLink records containing a specific protocol type. You can specify it as a second (protocol) argument.

import dnslink

domain = 'example.com'
protocol = 'ipns'
records = dnslink.resolve(domain=domain, protocol=protocol)

for record in records:
    print(record)

# /ipns/website.ipfs.io

As RFC 1034 specifies, DNSLinks also supports chaining. If the record's protocol type is dnslink, it will try to resolve records of the domain that it is specified in it. The default recursion limit is 16. It is possible to change it with a third (depth) argument. When a recursion limit is reached, a record will be returned as is, without any future resolving.

import dnslink

print(dnslink.resolve(domain='foo.com')[0]) # /ipfs/QmaYRVyPKpN8FXy9HS1t9Zhtjo4RpYXgiuNj1ins9fiLuW
print(dnslink.resolve(domain='foo.com', depth=1)[0]) # /dnslink/bar.com

You can specify a custom DNSPython resolver object as a fourth (resolver) argument. This can be used to provide a custom resolver configuration.

import dns.resolver
import dnslink

domain = 'example.com'
resolver = dns.resolver.Resolver()
records = dnslink.resolve(domain=domain, resolver=resolver)

for record in records:
    print(record)

# /ipfs/QmaYRVyPKpN8FXy9HS1t9Zhtjo4RpYXgiuNj1ins9fiLuW
# /ipns/website.ipfs.io

Versioning

This library uses SemVer for versioning. For the versions available, see the tags on this repository.

License

This library is licensed under the MIT license. See the LICENSE file for details.

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

dnslink-1.0.1.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distribution

dnslink-1.0.1-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

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