Python implementation of DNSLink protocol
Project description
DNSLink for Python
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.4 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
Built Distribution
File details
Details for the file dnslink-1.0.3.tar.gz
.
File metadata
- Download URL: dnslink-1.0.3.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e33d3b2fcc8e6ef479d5a8fc541aa9becf50c0e0b6d126da5a109569fde00be |
|
MD5 | 96e9a774d7675f21582cfbcf3d434c66 |
|
BLAKE2b-256 | 9a20095eb3b6c60e5fa6eb64ed81dade8ae56e21ea9640baa4b0602876c305ea |
File details
Details for the file dnslink-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: dnslink-1.0.3-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 978cfe70e869b4d0af255b2dd64042193384754aa9e332c19b481f7e2f70e931 |
|
MD5 | df24263d1594dfbba2664e665982a7ad |
|
BLAKE2b-256 | ca5087d98df9b415effefd7c5ec8ec42294e7532b47a7f2a774836283bf00aec |