Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pydantic-requests

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pydantic-requests

A pydantic integration with requests.

  • 0.1.4
  • PyPI
  • Socket score

Maintainers
1

Language grade: Python PyPI

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc