A Python library for secure DNS resolution (DoH, DoT, mTLS) with sync & async support.
Project description
PrivyDNS 
PrivyDNS is a Python library designed to securely query DNS records over encrypted protocols including DNS over HTTPS (DoH), DNS over TLS (DoT), and DNSCrypt. It supports both synchronous and asynchronous DNS queries with features such as caching, retry mechanisms, logging, and encryption. It provides developers with an easy-to-use interface to enhance DNS security, reliability, and performance.
Features
- Protocols Supported:
- DNS over HTTPS (DoH)
- DNS over TLS (DoT)
- DNSCrypt
- Cache Support: Caches DNS responses to improve performance.
- Retry Mechanism: Automatically retries failed DNS queries.
- Logging: Provides detailed logs for better debugging.
- Async & Sync Support: Supports both asynchronous and synchronous operations.
Architecture
You can learn more about the architecture, protocols, and features of PrivyDNS in the ARCHITECTURE.md file.
Background
For an in-depth explanation of DNS over HTTPS (DoH), DNS over TLS (DoT), and DNSCrypt, refer to the BACKGROUND.md file.
Installation
pip install privydns
Usage
Synchronous DNS Query
from privydns import DNSResolver
resolver = DNSResolver()
# DNS over HTTPS query
response = resolver.query("example.com", protocol="doh")
print(response)
# DNS over TLS query
response = resolver.query("example.com", protocol="dot")
print(response)
Asynchronous DNS Query
import asyncio
from privydns import DNSResolver
async def main():
resolver = DNSResolver()
response = await resolver.query("example.com", protocol="doh", async_mode=True)
print(response)
asyncio.run(main())
DNSCrypt Query
from privydns import DNSCryptResolver
crypt_resolver = DNSCryptResolver()
response = crypt_resolver.query("example.com")
print(response)
Testing
To run the tests, install the required packages and run the following command:
pip install -r requirements.txt
pytest .
Running Tests in Docker 🐳
This project includes a Dockerfile and docker-compose.yml file to run the tests inside a Docker container. It was build to mimic the GitHub Actions workflow.
To build the Docker image, run the following command:
docker compose build
To run the tests inside the Docker container, execute the following command:
docker compose run
Publishing to PyPI
To publish this project to PyPI, follow these steps:
-
Install Required Tools Ensure you have the latest versions of
setuptools,wheel, andtwineinstalled.pip install --upgrade setuptools wheel twine
-
Build the Distribution Files Run the following command to build the source distribution (
.tar.gz) and the wheel distribution (.whl).python setup.py sdist bdist_wheel
The distribution files will be available in the
distdirectory. -
Upload to Test PyPI (Optional) Before uploading to the official PyPI, you can test the package on Test PyPI:
twine upload --repository testpypi dist/*
You can verify your package at the Test PyPI URL (
https://test.pypi.org/project/your-package-name). -
Upload to PyPI If everything looks good, upload the package to the official PyPI repository:
twine upload dist/*
Make sure you have your PyPI credentials ready—refer to the PyPI website documentation if needed.
-
Verify the Package After publishing, verify that your package is listed on PyPI. You can install it like any other package to confirm the installation is working:
pip install privydns
-
Important Notes:
- Ensure the
setup.pyfile has all required metadata filled in (e.g.,name,version,author,description, etc.). - Keep the version number updated for every new release.
- Ensure the
License
This project 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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file privydns-0.1.1.tar.gz.
File metadata
- Download URL: privydns-0.1.1.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04b3dd3ed5691f584718fa67fe282ae5554dc329e12327ce1f7b8053d9e6a29f
|
|
| MD5 |
70499b258bccdacf15c6aded4a905d0d
|
|
| BLAKE2b-256 |
7603efc0e25d5d5fbf47760b656c3e74aded36479fdb77e97339732daa4475c7
|
File details
Details for the file privydns-0.1.1-py3-none-any.whl.
File metadata
- Download URL: privydns-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
641dc00a9c2d9ba3eedac27e5644b31842bd9ccadb69db3fde8bb58bf68e54f7
|
|
| MD5 |
b7ccbf683903acf80517111fffbd2142
|
|
| BLAKE2b-256 |
5d635f0d0e1b9432c4a900275005d8bedd35d2182bea27984d8077fcea1eb84f
|