Skip to main content

A Python library for secure DNS resolution (DoH, DoT, mTLS) with sync & async support.

Project description

PrivyDNS Python Test Suite

Pytest Python Python Version PyPi MIT License

PrivyDNS is a Python library designed to securely query DNS records over encrypted protocols including DNS over HTTPS (DoH), DNS over TLS (DoT), DNS over Mutual TLS (mTLS), 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)
    • DNS over Mutual TLS (mTLS)
    • 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

DNS Query

import asyncio
from privydns import DNSResolver

async def main():
    resolver = DNSResolver()
    response = await resolver.query("example.com", protocol="doh")
    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 up

Publishing to PyPI

To publish this project to PyPI, follow these steps:

  1. Install Required Tools Ensure you have the latest versions of setuptools, wheel, and twine installed.

    pip install --upgrade setuptools wheel twine build
    
  2. Build the Distribution Files Run the following command to build the source distribution (.tar.gz) and the wheel distribution (.whl).

    python -m build
    

    The distribution files will be available in the dist directory.

  3. 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).

  4. 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.

  5. 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
    
  6. Important Notes:

    • Ensure the setup.py file has all required metadata filled in (e.g., name, version, author, description, etc.).
    • Keep the version number updated for every new release.

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

privydns-0.1.2.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

privydns-0.1.2-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file privydns-0.1.2.tar.gz.

File metadata

  • Download URL: privydns-0.1.2.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for privydns-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9aafcd67d77801db2c1562f369a698bf3ec864a4a159849ac018be7343b574c4
MD5 395155a4e0c3338cd4d963a7b482a1ce
BLAKE2b-256 2d2296c46ffc4243a2dcb7b3aae23ccd6522c01549a283291c4805b935e099d8

See more details on using hashes here.

File details

Details for the file privydns-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: privydns-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for privydns-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fee2282a9e847b156d6107aa9a42c65a602e91e21902f4f141b323bf59510a6e
MD5 2225e0ead2aa2800856ee8a71f9db1c9
BLAKE2b-256 1443cbb5ef77cb8e2cbfa87affd465041dfe94ee59bbbf24c413089b2eb659c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page