A pydantic integration with requests.
Project description
Marriage of Pydantic and Requests
A helper that integrates Pydantic with requests library for seamless access to defined Models.
Example
from enum import Enum
from pydantic import BaseModel
from pydantic_requests import PydanticSession
class DNSStatus(Enum):
"""DNS OP response codes.
ref: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6
"""
# No Error = 0
NoError = 0
# Format Error = 1
FormErr = 1
# Server Failure
ServFail = 2
# Non-Existent Domain
NXDomain = 3
class DNSQuery(BaseModel):
Status: DNSStatus
class Config:
"""Configure DNS query."""
allow_mutation = False
arbitrary_types_allowed = True
with PydanticSession(
{200: DNSQuery}, headers={"accept": "application/dns-json"}
) as session:
domain = "dz0ny.xyz"
res = session.get(
"https://cloudflare-dns.com/dns-query", params={"name": domain, "type": "NS"}
)
res.raise_for_status()
query: DNSQuery = res.model
if query.Status == DNSStatus.NXDomain:
print("Domain is not registered.")
else:
print("Domain is registered.")
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 pydantic-requests-0.1.4.tar.gz
.
File metadata
- Download URL: pydantic-requests-0.1.4.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.10 Darwin/21.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 893ed9111f29bd45bd2ee62adde44f32958061541605e918844d6b2404aef884 |
|
MD5 | 67a4d18728cc41b1a94dc2aa07b054da |
|
BLAKE2b-256 | 1161f28e17ca58a9ab39ae24e22816fed8573e43cbcc4393d23952a703b04b7f |
File details
Details for the file pydantic_requests-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: pydantic_requests-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.10 Darwin/21.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 526340e0525fd5c7ad995b8335db6e3ea16fa5b8815f028ce6531887f6b1d117 |
|
MD5 | 6fdf31ff3f34658d2971dff96ba2e583 |
|
BLAKE2b-256 | 6e82cf1a4359708b0c1c4984ff3bbc7fd26ba8d88f5c27e937280b1c56683589 |