Skip to main content

DNS over HTTPS resolver for python requests

Project description

requests-doh

DNS over HTTPS resolver for python requests

Installation

# For Linux / Mac OS
python3 -m pip install requests-doh

# For Windows
py -3 -m pip install requests-doh

Usage

Basic usage

import requests
from requests_doh import DNSOverHTTPSAdapter

adapter = DNSOverHTTPSAdapter(provider='cloudflare') # You can choose between 'google' and 'cloudflare'
session = requests.Session()
# For HTTPS
session.mount('https://', adapter)
# For HTTP
session.mount('http://', adapter)

r = session.get('https://google.com')
print(r.text)

Set a custom session for DoH resolver

import requests
from requests_doh import set_resolver_session, DNSOverHTTPSAdapter

resolver_session = requests.Session()
# Insert some additional process here
# ...

set_resolver_session(resolver_session)

adapter = DNSOverHTTPSAdapter(provider='google')
session = requests.Session()
# For HTTPS
session.mount('https://', adapter)
# For HTTP
session.mount('http://', adapter)

r = session.get('https://google.com')
print(r.text)

Set an expire time (in seconds) for DoH caching

import requests
from requests_doh import purge_dns_cache, DNSOverHTTPSAdapter

# Default value of `cache_expire_time` is 300
adapter = DNSOverHTTPSAdapter(provider='google', cache_expire_time=1500) 
session = requests.Session()
# For HTTPS
session.mount('https://', adapter)
# For HTTP
session.mount('http://', adapter)

r = session.get('https://google.com')
print(r.text)

# You can purge single DNS cache
purge_dns_cache('google.com')
# or all of them
purge_dns_cache()

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

requests-doh-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

requests_doh-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file requests-doh-0.1.0.tar.gz.

File metadata

  • Download URL: requests-doh-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for requests-doh-0.1.0.tar.gz
Algorithm Hash digest
SHA256 09a7bb0522833241d1abfe9ed9905cb7ebdb608d23ca33142848d7060f03d2ad
MD5 4a0ac6164cfc762cd45bbff045a8d0a2
BLAKE2b-256 f397d28ce2ae811d070fb3a05dbf8b14b9b25fb190fb5701ca9fbb91374cf87f

See more details on using hashes here.

Provenance

File details

Details for the file requests_doh-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for requests_doh-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85b32fcceefe986e8ea955eb34b295f53b52b735c82ede4d79a8c377a13fb1b1
MD5 796bf098b82929bac26cbee63aa8eb11
BLAKE2b-256 dd3415ff47bb0fb0984d3a0a48da44f38a9730151c4d68a2a9d314bf5b4c170c

See more details on using hashes here.

Provenance

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