| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599 |
- import datetime
- from collections.abc import (
- AsyncIterator,
- Awaitable,
- ItemsView,
- Iterable,
- Iterator,
- KeysView,
- Mapping,
- Sequence,
- ValuesView,
- )
- from contextlib import AbstractContextManager
- from types import TracebackType
- from typing import (
- Literal,
- Protocol,
- TypeAlias,
- TypeVar,
- final,
- overload,
- runtime_checkable,
- )
- from opentelemetry.metrics import MeterProvider
- from opentelemetry.trace import TracerProvider
- from ._multipart import Multipart, SyncMultipart
- _T = TypeVar("_T")
- _JSON: TypeAlias = (
- Mapping[str, _JSON] | Sequence[_JSON] | str | int | float | bool | None
- )
- _RequestContent: TypeAlias = (
- bytes | AsyncIterator[bytes] | Mapping[str, _JSON] | Multipart
- )
- _SyncRequestContent: TypeAlias = (
- bytes | Iterable[bytes] | Mapping[str, _JSON] | SyncMultipart
- )
- _Buffer: TypeAlias = bytes | memoryview | bytearray
- _QueryParams: TypeAlias = dict[str, str | None] | Iterable[tuple[str, str | None]]
- @final
- class Headers:
- """Container of HTTP headers.
- This class behaves like a dictionary with case-insensitive keys and
- string values. Standard dictionary access will act as if keys can only
- have a single value. The add method can be used to It additionally can be used to store
- multiple values for the same key by using the add method. Iterating over
- values or items will return all values, including duplicates.
- """
- def __init__(
- self,
- items: Mapping[str | HTTPHeaderName, str]
- | Iterable[tuple[str | HTTPHeaderName, str]]
- | None = None,
- ) -> None:
- """Creates a new Headers object.
- Args:
- items: Initial headers to add.
- """
- def __getitem__(self, key: str | HTTPHeaderName) -> str:
- """Return the header value for the key.
- If multiple values are present for the key, returns the first value.
- Args:
- key: The header name.
- Raises:
- KeyError: If the key is not present.
- """
- def __setitem__(self, key: str | HTTPHeaderName, value: str) -> None:
- """Sets the header value for the key, replacing any existing values.
- Args:
- key: The header name.
- value: The header value.
- """
- def __delitem__(self, key: str | HTTPHeaderName) -> None:
- """Deletes all values for the key.
- Args:
- key: The header name.
- Raises:
- KeyError: If the key is not present.
- """
- def __iter__(self) -> Iterator[str]:
- """Returns an iterator over the header names."""
- def __len__(self) -> int:
- """Returns the number of unique header names."""
- def __eq__(self, other: object) -> bool:
- """Compares the headers for equality with another Headers object,
- mapping, or iterable of key-value pairs.
- Args:
- other: The object to compare against.
- """
- def get(self, key: str | HTTPHeaderName, default: _T | None = None) -> str | _T:
- """Returns the header value for the key, or default if not present.
- Args:
- key: The header name.
- default: The default value to return if the key is not present.
- """
- @overload
- def pop(self, key: str | HTTPHeaderName) -> str:
- """Removes and returns the header value for the key.
- Args:
- key: The header name.
- Raises:
- KeyError: If the key is not present.
- """
- @overload
- def pop(self, key: str | HTTPHeaderName, default: _T) -> str | _T:
- """Removes and returns the header value for the key, or default if not present.
- Args:
- key: The header name.
- default: The default value to return if the key is not present.
- """
- def popitem(self) -> tuple[str, str]:
- """Removes and returns an arbitrary (name, value) pair. Will return the same
- name multiple times if it has multiple values.
- Raises:
- KeyError: If the headers are empty.
- """
- def setdefault(self, key: str | HTTPHeaderName, default: str | None = None) -> str:
- """If the key is not present, sets it to the default value.
- Returns the value for the key.
- Args:
- key: The header name.
- default: The default value to set and return if the key is not present.
- """
- def add(self, key: str | HTTPHeaderName, value: str) -> None:
- """Adds a header value for the key. Existing values are preserved.
- Args:
- key: The header name.
- value: The header value.
- """
- @overload
- def update(self, **kwargs: str) -> None:
- """Updates headers from keyword arguments. Existing values are replaced.
- Args:
- **kwargs: Header names and values to set.
- """
- @overload
- def update(
- self,
- items: Mapping[str | HTTPHeaderName, str]
- | Iterable[tuple[str | HTTPHeaderName, str]],
- /,
- **kwargs: str,
- ) -> None:
- """Updates headers with the provided items. Existing values are replaced.
- Args:
- items: Header names and values to set.
- **kwargs: Additional header names and values to set after items. May overwrite items.
- """
- def clear(self) -> None:
- """Removes all headers."""
- def getall(self, key: str | HTTPHeaderName) -> Sequence[str]:
- """Returns all header values for the key.
- Args:
- key: The header name.
- """
- def items(self) -> ItemsView[str, str]:
- """Returns a new view of all header name-value pairs, including duplicates."""
- def keys(self) -> KeysView[str]:
- """Returns a new view of all unique header names."""
- def values(self) -> ValuesView[str]:
- """Returns a new view of all header values, including duplicates."""
- def __contains__(self, key: object) -> bool:
- """Returns True if the header name is present.
- Args:
- key: The header name.
- """
- @final
- class HTTPVersion:
- """An enumeration of HTTP versions."""
- HTTP1: HTTPVersion
- """HTTP/1.1"""
- HTTP2: HTTPVersion
- """HTTP/2"""
- HTTP3: HTTPVersion
- """HTTP/3"""
- def __eq__(self, other: object) -> bool: ...
- def __ne__(self, other: object) -> bool: ...
- def __lt__(self, other: object) -> bool: ...
- def __le__(self, other: object) -> bool: ...
- def __gt__(self, other: object) -> bool: ...
- def __ge__(self, other: object) -> bool: ...
- @final
- class Client:
- def __init__(self, transport: Transport | None = None) -> None:
- """Creates a new asynchronous HTTP client.
- The asynchronous client does not expose per-request timeouts on its methods.
- Use `asyncio.wait_for` or similar to enforce timeouts on requests.
- Args:
- transport: The transport to use for requests. If None, the shared default
- transport will be used.
- """
- def get(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- *,
- params: _QueryParams | None = None,
- ) -> Awaitable[FullResponse]:
- """Executes a GET HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def post(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- content: _RequestContent | None = None,
- *,
- params: _QueryParams | None = None,
- ) -> Awaitable[FullResponse]:
- """Executes a POST HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- content: The request content. A Python dictionary will be converted
- to JSON and a Multipart will be sent as a multipart form.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def delete(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- *,
- params: _QueryParams | None = None,
- ) -> Awaitable[FullResponse]:
- """Executes a DELETE HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def head(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- *,
- params: _QueryParams | None = None,
- ) -> Awaitable[FullResponse]:
- """Executes a HEAD HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def options(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- *,
- params: _QueryParams | None = None,
- ) -> Awaitable[FullResponse]:
- """Executes a OPTIONS HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def patch(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- content: _RequestContent | None = None,
- *,
- params: _QueryParams | None = None,
- ) -> Awaitable[FullResponse]:
- """Executes a PATCH HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- content: The request content. A Python dictionary will be converted
- to JSON and a Multipart will be sent as a multipart form.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def put(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- content: _RequestContent | None = None,
- *,
- params: _QueryParams | None = None,
- ) -> Awaitable[FullResponse]:
- """Executes a PUT HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- content: The request content. A Python dictionary will be converted
- to JSON and a Multipart will be sent as a multipart form.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def execute(
- self,
- method: str,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- content: _RequestContent | None = None,
- *,
- params: _QueryParams | None = None,
- ) -> Awaitable[FullResponse]:
- """Executes an HTTP request, returning the full buffered response.
- Args:
- method: The HTTP method.
- url: The unencoded request URL.
- headers: The request headers.
- content: The request content. A Python dictionary will be converted
- to JSON and a Multipart will be sent as a multipart form.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def stream(
- self,
- method: str,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- content: _RequestContent | None = None,
- *,
- params: _QueryParams | None = None,
- ) -> Awaitable[Response]:
- """Executes an HTTP request, allowing the response content to be streamed.
- Args:
- method: The HTTP method.
- url: The unencoded request URL.
- headers: The request headers.
- content: The request content. A Python dictionary will be converted
- to JSON and a Multipart will be sent as a multipart form.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- class Proxy:
- """A proxy for transports to route requests through.
- In addition to authentication and extra headers to send to the proxy,
- it allows restricting the requests routed through the proxy by URL
- scheme or exclusion list.
- """
- def __init__(
- self,
- url: str,
- *,
- auth: tuple[str, str] | None = None,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- no_proxy: str | None = None,
- scheme: Literal["http", "https"] | None = None,
- ) -> None:
- """Creates a new Proxy object.
- Args:
- url: The URL of the proxy, for example "http://localhost:8030".
- The URL scheme may be http, https, socks5, or socks5h.
- Credentials in the URL, for example
- "http://user:pass@localhost:8030", will be used for proxy
- authentication.
- auth: A (username, password) tuple to use for basic proxy
- authentication, as an alternative to credentials in the URL.
- headers: Extra headers to send to the proxy.
- no_proxy: A comma-separated list of hosts that should not be proxied.
- Entries may be IP addresses, optionally with a subnet mask
- such as "192.168.1.0/24", or domain names which also match
- all subdomains. The entry "*" matches all hosts.
- scheme: Which request URL scheme to route through the proxy. By default,
- both http and https requests are proxied.
- """
- @runtime_checkable
- class Transport(Protocol):
- """Protocol for asynchronous HTTP transport implementations.
- The default implementation of Transport is HTTPTransport which issues requests.
- Custom implementations may be useful to:
- - Mock requests for testing.
- - Add middleware wrapping transports
- """
- def execute(self, request: Request) -> Awaitable[Response]:
- """Executes a request."""
- @final
- class HTTPTransport:
- """An HTTP transport implementation using reqwest."""
- def __init__(
- self,
- *,
- tls_ca_cert: bytes | None = None,
- tls_include_system_certs: bool = False,
- tls_key: bytes | None = None,
- tls_cert: bytes | None = None,
- http_version: HTTPVersion | None = None,
- proxy: str | Proxy | Sequence[str | Proxy] | None = None,
- timeout: float | None = None,
- connect_timeout: float | None = 30.0,
- read_timeout: float | None = None,
- pool_idle_timeout: float | None = 90.0,
- pool_max_idle_per_host: int | None = None,
- tcp_keepalive_interval: float | None = 30.0,
- enable_gzip: bool = True,
- enable_brotli: bool = True,
- enable_zstd: bool = True,
- use_system_dns: bool = False,
- enable_cookie_store: bool = False,
- follow_redirects: bool = True,
- max_redirects: int = 10,
- enable_otel: bool = True,
- meter_provider: MeterProvider | None = None,
- tracer_provider: TracerProvider | None = None,
- ) -> None:
- """Creates a new HTTPTransport object.
- Without any arguments, the transport behaves like the default transport without trusted TLS certificates.
- When creating a transport, take care to set options to meet your needs.
- Args:
- tls_ca_cert: The PEM-encoded CA certificate(s) to use to verify the server for TLS connections.
- tls_include_system_certs: Whether to include the system CA certificates to verify TLS connections.
- If this is unset and tls_ca_cert is not provided, TLS will not function.
- tls_key: The client private key to identify the client for mTLS connections.
- tls_cert must also be set.
- tls_cert: The client certificate to identify the client for mTLS connections.
- tls_key must also be set.
- http_version: The HTTP version to use for requests. If unset, HTTP/1 is used for
- plaintext and ALPN negotiates the version for TLS connections
- which typically means HTTP/2 if the server supports it.
- proxy: A proxy to send requests through. A URL string such as
- "http://localhost:8030" proxies all requests, equivalent to
- Proxy(url). Pass a Proxy object to configure authentication,
- extra headers, or routing rules, or a sequence of them to
- apply multiple proxy rules, where the first matching proxy
- is used for each request. An empty sequence, like None,
- configures no explicit proxy, in which case proxy
- environment variables such as HTTP_PROXY still apply.
- timeout: Default timeout for requests in seconds. This is the timeout from
- the start of the request to the end of the response.
- connect_timeout: Timeout for connection establishment in seconds.
- read_timeout: Timeout for each read operation of a request in seconds.
- pool_idle_timeout: Timeout for idle connections in the connection pool in seconds.
- pool_max_idle_per_host: Maximum number of idle connections to keep in the pool per host.
- Defaults to 2.
- tcp_keepalive_interval: Interval for TCP keepalive probes in seconds.
- enable_gzip: Whether to enable gzip decompression for responses.
- enable_brotli: Whether to enable brotli decompression for responses.
- enable_zstd: Whether to enable zstd decompression for responses.
- use_system_dns: Whether to use the system DNS resolver. By default, pyqwest uses an
- asynchronous DNS resolver implemented in Rust, but it can have different
- behavior from system DNS in certain environments. Try enabling this option if
- you have any DNS resolution issues.
- enable_cookie_store: Whether to enable automatic cookie storage and sending. When enabled,
- the transport will automatically store cookies from responses and send
- them with subsequent requests.
- follow_redirects: Whether to automatically follow redirect responses. When disabled,
- which is the default, redirect responses are returned as-is.
- Leave this disabled when the transport is used through
- pyqwest.httpx, because httpx clients apply their own
- follow_redirects setting and track redirects in response.history.
- max_redirects: Maximum number of redirects to follow when follow_redirects is enabled.
- A request exceeding it fails with TooManyRedirects.
- """
- def __aenter__(self) -> Awaitable[HTTPTransport]:
- """Enters the context manager for the transport to automatically close it when
- leaving.
- """
- def __aexit__(
- self,
- _exc_type: type[BaseException] | None,
- _exc_value: BaseException | None,
- _traceback: TracebackType | None,
- ) -> Awaitable[None]:
- """Exits the context manager for the transport, closing it."""
- def execute(self, request: Request) -> Awaitable[Response]:
- """Executes the given request, returning the response.
- Args:
- request: The request to execute.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def aclose(self) -> Awaitable[None]:
- """Closes the transport, releasing any underlying resources."""
- def get_default_transport() -> HTTPTransport:
- """Returns the singleton default HTTP transport instance used by clients that do not
- specify a transport.
- The default transport is constructed as follows:
- ```
- HTTPTransport(
- connect_timeout=30.0,
- pool_idle_timeout=90.0,
- tcp_keepalive_interval=30.0,
- enable_gzip: bool = True,
- enable_brotli: bool = True,
- enable_zstd: bool = True,
- )
- ```
- """
- @final
- class Request:
- """An HTTP request."""
- def __init__(
- self,
- method: str,
- url: str,
- headers: Headers | None = None,
- content: _RequestContent | None = None,
- *,
- params: _QueryParams | None = None,
- ) -> None:
- """Creates a new Request object.
- Args:
- method: The HTTP method.
- url: The unencoded request URL.
- headers: The request headers.
- content: The request content. A Python dictionary will be converted
- to JSON and a Multipart will be sent as a multipart form.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- """
- @property
- def method(self) -> str:
- """Returns the HTTP method of the request."""
- @property
- def url(self) -> str:
- """Returns the unencoded request URL."""
- @property
- def headers(self) -> Headers:
- """Returns the request headers."""
- @property
- def content(self) -> bytes | AsyncIterator[bytes]:
- """Returns an async iterator over the request content."""
- @property
- def _json(self) -> bool: ...
- @final
- class Response:
- """An HTTP response."""
- def __init__(
- self,
- *,
- status: int,
- http_version: HTTPVersion | None = None,
- headers: Headers | None = None,
- content: bytes | AsyncIterator[_Buffer] | None = None,
- trailers: Headers | None = None,
- ) -> None:
- """Creates a new Response object.
- Care must be taken if your service uses trailers and you override content.
- Trailers will not be received without fully consuming the original response content.
- Patterns that wrap the original response content should not have any issue but if
- you replace it completely and need trailers, make sure to still read and discard
- the original content.
- Args:
- status: The HTTP status code of the response.
- http_version: The HTTP version of the response.
- headers: The response headers.
- content: The response content.
- trailers: The response trailers.
- Raises:
- RemoteProtocolError: If the status is not a valid HTTP status code.
- """
- def __aenter__(self) -> Awaitable[Response]:
- """Enters the context manager for the response to automatically close it when
- leaving.
- Note that if your code is guaranteed to fully consume the response content,
- it is not necessary to explicitly close the response.
- """
- def __aexit__(
- self,
- _exc_type: type[BaseException] | None,
- _exc_value: BaseException | None,
- _traceback: TracebackType | None,
- ) -> Awaitable[None]:
- """Exits the context manager for the response, closing it."""
- @property
- def status(self) -> int:
- """Returns the HTTP status code of the response."""
- @property
- def http_version(self) -> HTTPVersion:
- """Returns the HTTP version of the response."""
- @property
- def headers(self) -> Headers:
- """Returns the response headers."""
- @property
- def content(self) -> AsyncIterator[_Buffer]:
- """Returns an asynchronous iterator over the response content."""
- @property
- def trailers(self) -> Headers:
- """Returns the response trailers.
- Because trailers complete the response, this will only be filled after fully
- consuming the content iterator.
- """
- def aclose(self) -> Awaitable[None]:
- """Closes the response, releasing any underlying resources.
- Note that if your code is guaranteed to fully consume the response content,
- it is not necessary to explicitly close the response.
- """
- @final
- class SyncClient:
- """A synchronous HTTP client.
- A client is a lightweight wrapper around a SyncTransport, providing convenience methods
- for common HTTP operations with buffering.
- """
- def __init__(self, transport: SyncTransport | None = None) -> None:
- """Creates a new synchronous HTTP client.
- Args:
- transport: The transport to use for requests. If None, the shared default
- transport will be used.
- """
- def get(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- *,
- timeout: float | None = None,
- params: _QueryParams | None = None,
- ) -> FullResponse:
- """Executes a GET HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- timeout: The timeout for the request in seconds.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def post(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- content: _SyncRequestContent | None = None,
- *,
- timeout: float | None = None,
- params: _QueryParams | None = None,
- ) -> FullResponse:
- """Executes a POST HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- content: The request content. A Python dictionary will be converted
- to JSON and a SyncMultipart will be sent as a multipart form.
- timeout: The timeout for the request in seconds.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def delete(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- *,
- timeout: float | None = None,
- params: _QueryParams | None = None,
- ) -> FullResponse:
- """Executes a DELETE HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- timeout: The timeout for the request in seconds.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def head(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- *,
- timeout: float | None = None,
- params: _QueryParams | None = None,
- ) -> FullResponse:
- """Executes a HEAD HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- timeout: The timeout for the request in seconds.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def options(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- *,
- timeout: float | None = None,
- params: _QueryParams | None = None,
- ) -> FullResponse:
- """Executes a OPTIONS HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- timeout: The timeout for the request in seconds.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def patch(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- content: _SyncRequestContent | None = None,
- *,
- timeout: float | None = None,
- params: _QueryParams | None = None,
- ) -> FullResponse:
- """Executes a PATCH HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- content: The request content. A Python dictionary will be converted
- to JSON and a SyncMultipart will be sent as a multipart form.
- timeout: The timeout for the request in seconds.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def put(
- self,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- content: _SyncRequestContent | None = None,
- *,
- timeout: float | None = None,
- params: _QueryParams | None = None,
- ) -> FullResponse:
- """Executes a PUT HTTP request.
- Args:
- url: The unencoded request URL.
- headers: The request headers.
- content: The request content. A Python dictionary will be converted
- to JSON and a SyncMultipart will be sent as a multipart form.
- timeout: The timeout for the request in seconds.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def execute(
- self,
- method: str,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- content: _SyncRequestContent | None = None,
- *,
- timeout: float | None = None,
- params: _QueryParams | None = None,
- ) -> FullResponse:
- """Executes an HTTP request, returning the full buffered response.
- Args:
- method: The HTTP method.
- url: The unencoded request URL.
- headers: The request headers.
- content: The request content. A Python dictionary will be converted
- to JSON and a SyncMultipart will be sent as a multipart form.
- timeout: The timeout for the request in seconds.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- def stream(
- self,
- method: str,
- url: str,
- headers: Headers | Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
- content: _SyncRequestContent | None = None,
- *,
- timeout: float | None = None,
- params: _QueryParams | None = None,
- ) -> AbstractContextManager[SyncResponse]:
- """Executes an HTTP request, allowing the response content to be streamed.
- Args:
- method: The HTTP method.
- url: The unencoded request URL.
- headers: The request headers.
- content: The request content. A Python dictionary will be converted
- to JSON and a SyncMultipart will be sent as a multipart form.
- timeout: The timeout for the request in seconds.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- Raises:
- ConnectionError: If the connection fails.
- TimeoutError: If the request times out.
- RemoteProtocolError: If the peer violates the HTTP protocol.
- ReadError: If an error occurs reading the response.
- WriteError: If an error occurs writing the request.
- """
- @runtime_checkable
- class SyncTransport(Protocol):
- """Protocol for synchronous HTTP transport implementations.
- The default implementation of SyncTransport is SyncHTTPTransport which issues requests.
- Custom implementations may be useful to:
- - Mock requests for testing.
- - Add middleware wrapping transports
- """
- def execute_sync(self, request: SyncRequest) -> SyncResponse:
- """Executes a request."""
- @final
- class SyncHTTPTransport:
- """An HTTP transport implementation using reqwest."""
- def __init__(
- self,
- *,
- tls_ca_cert: bytes | None = None,
- tls_include_system_certs: bool = False,
- tls_key: bytes | None = None,
- tls_cert: bytes | None = None,
- http_version: HTTPVersion | None = None,
- proxy: str | Proxy | Sequence[str | Proxy] | None = None,
- timeout: float | None = None,
- connect_timeout: float | None = 30.0,
- read_timeout: float | None = None,
- pool_idle_timeout: float | None = 90.0,
- pool_max_idle_per_host: int | None = None,
- tcp_keepalive_interval: float | None = 30.0,
- enable_gzip: bool = True,
- enable_brotli: bool = True,
- enable_zstd: bool = True,
- use_system_dns: bool = False,
- enable_cookie_store: bool = False,
- follow_redirects: bool = True,
- max_redirects: int = 10,
- enable_otel: bool = True,
- meter_provider: MeterProvider | None = None,
- tracer_provider: TracerProvider | None = None,
- ) -> None:
- """Creates a new SyncHTTPTransport object.
- Without any arguments, the transport behaves like the default transport without trusted TLS certificates.
- When creating a transport, take care to set options to meet your needs.
- Args:
- tls_ca_cert: The PEM-encoded CA certificate(s) to use to verify the server for TLS connections.
- tls_include_system_certs: Whether to include the system CA certificates to verify TLS connections.
- If this is unset and tls_ca_cert is not provided, TLS will not function.
- tls_key: The client private key to identify the client for mTLS connections.
- tls_cert must also be set.
- tls_cert: The client certificate to identify the client for mTLS connections.
- tls_key must also be set.
- http_version: The HTTP version to use for requests. If unset, HTTP/1 is used for
- plaintext and ALPN negotiates the version for TLS connections
- which typically means HTTP/2 if the server supports it.
- proxy: A proxy to send requests through. A URL string such as
- "http://localhost:8030" proxies all requests, equivalent to
- Proxy(url). Pass a Proxy object to configure authentication,
- extra headers, or routing rules, or a sequence of them to
- apply multiple proxy rules, where the first matching proxy
- is used for each request. An empty sequence, like None,
- configures no explicit proxy, in which case proxy
- environment variables such as HTTP_PROXY still apply.
- timeout: Default timeout for requests in seconds. This is the timeout from
- the start of the request to the end of the response.
- connect_timeout: Timeout for connection establishment in seconds.
- read_timeout: Timeout for each read operation of a request in seconds.
- pool_idle_timeout: Timeout for idle connections in the connection pool in seconds.
- pool_max_idle_per_host: Maximum number of idle connections to keep in the pool per host.
- Defaults to 2.
- tcp_keepalive_interval: Interval for TCP keepalive probes in seconds.
- enable_gzip: Whether to enable gzip decompression for responses.
- enable_brotli: Whether to enable brotli decompression for responses.
- enable_zstd: Whether to enable zstd decompression for responses.
- use_system_dns: Whether to use the system DNS resolver. By default, pyqwest uses an
- asynchronous DNS resolver implemented in Rust, but it can have different
- behavior from system DNS in certain environments. Try enabling this option if
- you have any DNS resolution issues.
- enable_cookie_store: Whether to enable automatic cookie storage and sending. When enabled,
- the transport will automatically store cookies from responses and send
- them with subsequent requests.
- follow_redirects: Whether to automatically follow redirect responses. When disabled,
- which is the default, redirect responses are returned as-is.
- Leave this disabled when the transport is used through
- pyqwest.httpx, because httpx clients apply their own
- follow_redirects setting and track redirects in response.history.
- max_redirects: Maximum number of redirects to follow when follow_redirects is enabled.
- A request exceeding it fails with TooManyRedirects.
- """
- def __enter__(self) -> SyncHTTPTransport:
- """Enters the context manager for the transport to automatically
- close it when leaving.
- """
- def __exit__(
- self,
- _exc_type: type[BaseException] | None,
- _exc_value: BaseException | None,
- _traceback: TracebackType | None,
- ) -> None:
- """Exits the context manager for the transport, closing it."""
- def execute_sync(self, request: SyncRequest) -> SyncResponse:
- """Executes the given request, returning the response.
- Args:
- request: The request to execute.
- """
- def close(self) -> None:
- """Closes the transport, releasing any underlying resources."""
- def get_default_sync_transport() -> SyncHTTPTransport:
- """Returns the singleton default HTTP transport instance used by synchronous clients that do not
- specify a transport.ult HTTP transport instance used by clients that do not
- specify a transport.
- The default transport is constructed as follows:
- ```
- SyncHTTPTransport(
- connect_timeout=30.0,
- pool_idle_timeout=90.0,
- tcp_keepalive_interval=30.0,
- enable_gzip: bool = True,
- enable_brotli: bool = True,
- enable_zstd: bool = True,
- )
- ```
- """
- @final
- class SyncRequest:
- """An HTTP request."""
- def __init__(
- self,
- method: str,
- url: str,
- headers: Headers | None = None,
- content: _SyncRequestContent | None = None,
- *,
- params: _QueryParams | None = None,
- ) -> None:
- """Creates a new SyncRequest object.
- Args:
- method: The HTTP method.
- url: The unencoded request URL.
- headers: The request headers.
- content: The request content. A Python dictionary will be converted
- to JSON and a SyncMultipart will be sent as a multipart form.
- params: Query parameters to append to the URL. None values will be treated as key-only.
- """
- @property
- def method(self) -> str:
- """Returns the HTTP method of the request."""
- @property
- def url(self) -> str:
- """Returns the unencoded request URL."""
- @property
- def headers(self) -> Headers:
- """Returns the request headers."""
- @property
- def content(self) -> bytes | Iterator[bytes]:
- """Returns an iterator over the request content."""
- @property
- def _json(self) -> bool: ...
- @final
- class SyncResponse:
- """An HTTP response."""
- def __init__(
- self,
- *,
- status: int,
- http_version: HTTPVersion | None = None,
- headers: Headers | None = None,
- content: bytes | Iterable[_Buffer] | None = None,
- trailers: Headers | None = None,
- ) -> None:
- """Creates a new SyncResponse object.
- Care must be taken if your service uses trailers and you override content.
- Trailers will not be received without fully consuming the original response content.
- Patterns that wrap the original response content should not have any issue but if
- you replace it completely and need trailers, make sure to still read and discard
- the original content.
- Args:
- status: The HTTP status code of the response.
- http_version: The HTTP version of the response.
- headers: The response headers.
- content: The response content.
- trailers: The response trailers.
- Raises:
- RemoteProtocolError: If the status is not a valid HTTP status code.
- """
- def __enter__(self) -> SyncResponse:
- """Enters the context manager for the response to automatically
- close it when leaving.
- Note that if your code is guaranteed to fully consume the response content,
- it is not necessary to explicitly close the response.
- """
- def __exit__(
- self,
- _exc_type: type[BaseException] | None,
- _exc_value: BaseException | None,
- _traceback: TracebackType | None,
- ) -> None:
- """Exits the context manager for the response, closing it."""
- @property
- def status(self) -> int:
- """Returns the HTTP status code of the response."""
- @property
- def http_version(self) -> HTTPVersion:
- """Returns the HTTP version of the response."""
- @property
- def headers(self) -> Headers:
- """Returns the response headers."""
- @property
- def content(self) -> Iterator[_Buffer]:
- """Returns an iterator over the response content."""
- @property
- def trailers(self) -> Headers:
- """Returns the response trailers.
- Because trailers complete the response, this will only be filled after fully
- consuming the content iterator.
- """
- def close(self) -> None:
- """Closes the response, releasing any underlying resources.
- Note that if your code is guaranteed to fully consume the response content,
- it is not necessary to explicitly close the response.
- """
- @final
- class FullResponse:
- """A fully buffered HTTP response."""
- def __init__(
- self, status: int, headers: Headers, content: bytes, trailers: Headers
- ) -> None:
- """Creates a new FullResponse object.
- Args:
- status: The HTTP status code of the response.
- headers: The response headers.
- content: The response content.
- trailers: The response trailers.
- """
- @property
- def status(self) -> int:
- """Returns the HTTP status code of the response."""
- @property
- def headers(self) -> Headers:
- """Returns the response headers."""
- @property
- def content(self) -> bytes:
- """Returns the response content."""
- @property
- def trailers(self) -> Headers:
- """Returns the response trailers."""
- def text(self) -> str:
- """Returns the response content decoded as text.
- The encoding for decoding is determined from the content-type header if present,
- defaulting to UTF-8 otherwise.
- """
- def json(self) -> _JSON:
- """Parses and returns the response content as JSON.
- The content-type header is not checked when using this method.
- """
- @final
- class ReadError(Exception):
- """An error representing a read error during response reading."""
- @final
- class WriteError(Exception):
- """An error representing a write error during request sending."""
- @final
- class TooManyRedirects(Exception):
- """An error raised when a request exceeded the transport's max_redirects."""
- @final
- class HTTPHeaderName:
- """An enum type corresponding to HTTP header names."""
- def __init__(self, name: str) -> None:
- """Creates a new HTTPHeaderName. When available, prefer one of the
- class attributes.
- Args:
- name: The header name.
- """
- ACCEPT: HTTPHeaderName
- """The "accept" header."""
- ACCEPT_CHARSET: HTTPHeaderName
- """The "accept-charset" header."""
- ACCEPT_ENCODING: HTTPHeaderName
- """The "accept-encoding" header."""
- ACCEPT_LANGUAGE: HTTPHeaderName
- """The "accept-language" header."""
- ACCEPT_RANGES: HTTPHeaderName
- """The "accept-ranges" header."""
- ACCESS_CONTROL_ALLOW_CREDENTIALS: HTTPHeaderName
- """The "access-control-allow-credentials" header."""
- ACCESS_CONTROL_ALLOW_HEADERS: HTTPHeaderName
- """The "access-control-allow-headers" header."""
- ACCESS_CONTROL_ALLOW_METHODS: HTTPHeaderName
- """The "access-control-allow-methods" header."""
- ACCESS_CONTROL_ALLOW_ORIGIN: HTTPHeaderName
- """The "access-control-allow-origin" header."""
- ACCESS_CONTROL_EXPOSE_HEADERS: HTTPHeaderName
- """The "access-control-expose-headers" header."""
- ACCESS_CONTROL_MAX_AGE: HTTPHeaderName
- """The "access-control-max-age" header."""
- ACCESS_CONTROL_REQUEST_HEADERS: HTTPHeaderName
- """The "access-control-request-headers" header."""
- ACCESS_CONTROL_REQUEST_METHOD: HTTPHeaderName
- """The "access-control-request-method" header."""
- AGE: HTTPHeaderName
- """The "age" header."""
- ALLOW: HTTPHeaderName
- """The "allow" header."""
- ALT_SVC: HTTPHeaderName
- """The "alt-svc" header."""
- AUTHORIZATION: HTTPHeaderName
- """The "authorization" header."""
- CACHE_CONTROL: HTTPHeaderName
- """The "cache-control" header."""
- CACHE_STATUS: HTTPHeaderName
- """The "cache-status" header."""
- CDN_CACHE_CONTROL: HTTPHeaderName
- """The "cdn-cache-control" header."""
- CONNECTION: HTTPHeaderName
- """The "connection" header."""
- CONTENT_DISPOSITION: HTTPHeaderName
- """The "content-disposition" header."""
- CONTENT_ENCODING: HTTPHeaderName
- """The "content-encoding" header."""
- CONTENT_LANGUAGE: HTTPHeaderName
- """The "content-language" header."""
- CONTENT_LENGTH: HTTPHeaderName
- """The "content-length" header."""
- CONTENT_LOCATION: HTTPHeaderName
- """The "content-location" header."""
- CONTENT_RANGE: HTTPHeaderName
- """The "content-range" header."""
- CONTENT_SECURITY_POLICY: HTTPHeaderName
- """The "content-security-policy" header."""
- CONTENT_SECURITY_POLICY_REPORT_ONLY: HTTPHeaderName
- """The "content-security-policy-report-only" header."""
- CONTENT_TYPE: HTTPHeaderName
- """The "content-type" header."""
- COOKIE: HTTPHeaderName
- """The "cookie" header."""
- DNT: HTTPHeaderName
- """The "dnt" header."""
- DATE: HTTPHeaderName
- """The "date" header."""
- ETAG: HTTPHeaderName
- """The "etag" header."""
- EXPECT: HTTPHeaderName
- """The "expect" header."""
- EXPIRES: HTTPHeaderName
- """The "expires" header."""
- FORWARDED: HTTPHeaderName
- """The "forwarded" header."""
- FROM: HTTPHeaderName
- """The "from" header."""
- HOST: HTTPHeaderName
- """The "host" header."""
- IF_MATCH: HTTPHeaderName
- """The "if-match" header."""
- IF_MODIFIED_SINCE: HTTPHeaderName
- """The "if-modified-since" header."""
- IF_NONE_MATCH: HTTPHeaderName
- """The "if-none-match" header."""
- IF_RANGE: HTTPHeaderName
- """The "if-range" header."""
- IF_UNMODIFIED_SINCE: HTTPHeaderName
- """The "if-unmodified-since" header."""
- LAST_MODIFIED: HTTPHeaderName
- """The "last-modified" header."""
- LINK: HTTPHeaderName
- """The "link" header."""
- LOCATION: HTTPHeaderName
- """The "location" header."""
- MAX_FORWARDS: HTTPHeaderName
- """The "max-forwards" header."""
- ORIGIN: HTTPHeaderName
- """The "origin" header."""
- PRAGMA: HTTPHeaderName
- """The "pragma" header."""
- PROXY_AUTHENTICATE: HTTPHeaderName
- """The "proxy-authenticate" header."""
- PROXY_AUTHORIZATION: HTTPHeaderName
- """The "proxy-authorization" header."""
- PUBLIC_KEY_PINS: HTTPHeaderName
- """The "public-key-pins" header."""
- PUBLIC_KEY_PINS_REPORT_ONLY: HTTPHeaderName
- """The "public-key-pins-report-only" header."""
- RANGE: HTTPHeaderName
- """The "range" header."""
- REFERER: HTTPHeaderName
- """The "referer" header."""
- REFERRER_POLICY: HTTPHeaderName
- """The "referrer-policy" header."""
- REFRESH: HTTPHeaderName
- """The "refresh" header."""
- RETRY_AFTER: HTTPHeaderName
- """The "retry-after" header."""
- SEC_WEBSOCKET_ACCEPT: HTTPHeaderName
- """The "sec-websocket-accept" header."""
- SEC_WEBSOCKET_EXTENSIONS: HTTPHeaderName
- """The "sec-websocket-extensions" header."""
- SEC_WEBSOCKET_KEY: HTTPHeaderName
- """The "sec-websocket-key" header."""
- SEC_WEBSOCKET_PROTOCOL: HTTPHeaderName
- """The "sec-websocket-protocol" header."""
- SEC_WEBSOCKET_VERSION: HTTPHeaderName
- """The "sec-websocket-version" header."""
- SERVER: HTTPHeaderName
- """The "server" header."""
- SET_COOKIE: HTTPHeaderName
- """The "set-cookie" header."""
- STRICT_TRANSPORT_SECURITY: HTTPHeaderName
- """The "strict-transport-security" header."""
- TE: HTTPHeaderName
- """The "te" header."""
- TRAILER: HTTPHeaderName
- """The "trailer" header."""
- TRANSFER_ENCODING: HTTPHeaderName
- """The "transfer-encoding" header."""
- USER_AGENT: HTTPHeaderName
- """The "user-agent" header."""
- UPGRADE: HTTPHeaderName
- """The "upgrade" header."""
- UPGRADE_INSECURE_REQUESTS: HTTPHeaderName
- """The "upgrade-insecure-requests" header."""
- VARY: HTTPHeaderName
- """The "vary" header."""
- VIA: HTTPHeaderName
- """The "via" header."""
- WARNING: HTTPHeaderName
- """The "warning" header."""
- WWW_AUTHENTICATE: HTTPHeaderName
- """The "www-authenticate" header."""
- X_CONTENT_TYPE_OPTIONS: HTTPHeaderName
- """The "x-content-type-options" header."""
- X_DNS_PREFETCH_CONTROL: HTTPHeaderName
- """The "x-dns-prefetch-control" header."""
- X_FRAME_OPTIONS: HTTPHeaderName
- """The "x-frame-options" header."""
- X_XSS_PROTECTION: HTTPHeaderName
- """The "x-xss-protection" header."""
- def set_sync_timeout(timeout: float) -> AbstractContextManager[None]: ...
- def get_sync_timeout() -> datetime.timedelta | None: ...
- class _BrotliDecompressor:
- def feed(self, data: bytes, *, end: bool) -> bytes: ...
- class _ZstdDecompressor:
- def feed(self, data: bytes, *, end: bool) -> bytes: ...
- class _Backoff:
- def __init__(
- self,
- initial_interval: float,
- randomization_factor: float,
- multiplier: float,
- max_interval: float,
- ) -> None: ...
- def next_backoff(self) -> float | None: ...
|