Python implementation of DNSLink protocol
DNSLink for Python
Python implementation of DNSLink protocol.
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.
DNSLink requires Python 3.4 or higher.
The recommended way to install DNSLink is from PyPI with PIP.
pip install dnslink
Alternatively, you can also install it from the source.
git clone https://github.com/filips123/DNSLinkPy.git cd DNSLinkPy python setup.py install
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 (
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')) # /ipfs/QmaYRVyPKpN8FXy9HS1t9Zhtjo4RpYXgiuNj1ins9fiLuW print(dnslink.resolve(domain='foo.com', depth=1)) # /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
This library is licensed under the MIT license. See the LICENSE file for details.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size dnslink-1.0.2-py3-none-any.whl (8.0 kB)||File type Wheel||Python version py3||Upload date||Hashes View hashes|
|Filename, size dnslink-1.0.2.tar.gz (7.2 kB)||File type Source||Python version None||Upload date||Hashes View hashes|