requests API reference
105 public APIs from requests (psf/requests) — 32 classes, 44 functions, 29 methods. Signatures extracted by static analysis of the actual source.
Repository: psf/requests
| Kind | Count |
|---|---|
| Classes | 32 |
| Functions | 44 |
| Methods | 29 |
API list
func
src.requests._internal_utils.unicode_is_ascii(u_string:str) -> boolDetermine if unicode string only contains ASCII characters.
class
src.requests._types.DataKwargskwargs for put(), patch().
class
src.requests._types.RequestKwargskwargs for request(), options(), head(), delete().
func
src.requests._types.has_read(obj:Any) -> TypeIs[SupportsRead[str | bytes]]Check if obj supports read, including __getattr__ based proxies.
func
src.requests._types.is_prepared(request:PreparedRequest) -> TypeIs[_ValidatedRequest]Verify a PreparedRequest has been fully prepared.
class
src.requests.adapters.BaseAdapterThe Base Transport Adapter
method
src.requests.adapters.BaseAdapter.close() -> NoneCleans up adapter specific items.
method
src.requests.adapters.BaseAdapter.send(request:PreparedRequest, stream:bool=False, timeout:_t.TimeoutType=None, verify:_t.VerifyType=True, cert:_t.CertType=None, proxies:dict[str, str] | None=None) -> ResponseSends PreparedRequest object.
class
src.requests.adapters.HTTPAdapterThe built-in HTTP Adapter for urllib3.
method
src.requests.adapters.HTTPAdapter.add_headers(request:PreparedRequest, **kwargs:Any) -> NoneAdd any headers needed by the connection.
method
src.requests.adapters.HTTPAdapter.cert_verify(conn:Any, url:str, verify:_t.VerifyType, cert:_t.CertType) -> NoneVerify a SSL certificate.
method
src.requests.adapters.HTTPAdapter.close() -> NoneDisposes of any internal state.
method
src.requests.adapters.HTTPAdapter.init_poolmanager(connections:int, maxsize:int, block:bool=DEFAULT_POOLBLOCK, **pool_kwargs:Any) -> NoneInitializes a urllib3 PoolManager.
method
src.requests.adapters.HTTPAdapter.proxy_manager_for(proxy:str, **proxy_kwargs:Any) -> AnyReturn urllib3 ProxyManager for the given proxy.
method
src.requests.adapters.HTTPAdapter.request_url(request:PreparedRequest, proxies:dict[str, str] | None) -> strObtain the url to use when making the final request.
method
src.requests.adapters.HTTPAdapter.send(request:PreparedRequest, stream:bool=False, timeout:_t.TimeoutType=None, verify:_t.VerifyType=True, cert:_t.CertType=None, proxies:dict[str, str] | None=None) -> ResponseSends PreparedRequest object.
func
src.requests.api.delete(url:_t.UriType, **kwargs:Unpack[_t.RequestKwargs]) -> ResponseSends a DELETE request.
func
src.requests.api.get(url:_t.UriType, params:_t.ParamsType=None, **kwargs:Unpack[_t.GetKwargs]) -> ResponseSends a GET request.
func
src.requests.api.head(url:_t.UriType, **kwargs:Unpack[_t.RequestKwargs]) -> ResponseSends a HEAD request.
func
src.requests.api.options(url:_t.UriType, **kwargs:Unpack[_t.RequestKwargs]) -> ResponseSends an OPTIONS request.
func
src.requests.api.patch(url:_t.UriType, data:_t.DataType=None, **kwargs:Unpack[_t.DataKwargs]) -> ResponseSends a PATCH request.
func
src.requests.api.post(url:_t.UriType, data:_t.DataType=None, json:_t.JsonType=None, **kwargs:Unpack[_t.PostKwargs]) -> ResponseSends a POST request.
func
src.requests.api.put(url:_t.UriType, data:_t.DataType=None, **kwargs:Unpack[_t.DataKwargs]) -> ResponseSends a PUT request.
func
src.requests.api.request(method:str, url:_t.UriType, **kwargs:Unpack[_t.RequestKwargs]) -> ResponseConstructs and sends a :class:`Request <Request>`.
class
src.requests.auth.AuthBaseBase class that all auth implementations derive from
class
src.requests.auth.HTTPBasicAuthAttaches HTTP Basic Authentication to the given Request object.
method
src.requests.auth.HTTPDigestAuth.build_digest_header(method:str, url:str) -> str | None:rtype: str
method
src.requests.auth.HTTPDigestAuth.handle_401(r:Response, **kwargs:Any) -> ResponseTakes the given response and tries digest-auth, if needed.
method
src.requests.auth.HTTPDigestAuth.handle_redirect(r:Response, **kwargs:Any) -> NoneReset num_401_calls counter on redirects.
class
src.requests.auth.HTTPProxyAuthAttaches HTTP Proxy Authentication to a given Request object.
class
src.requests.cookies.MockRequestWraps a `requests.PreparedRequest` to mimic a `urllib2.Request`.
class
src.requests.cookies.MockResponseWraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`.
func
src.requests.cookies.create_cookie(name:str, value:str, **kwargs:Any) -> CookieMake a cookie from underspecified parameters.
func
src.requests.cookies.extract_cookies_to_jar(jar:CookieJar, request:PreparedRequest, response:Any) -> NoneExtract the cookies from the response into a CookieJar.
func
src.requests.cookies.merge_cookies(cookiejar:CookieJar, cookies:dict[str, str] | CookieJar | None) -> CookieJarAdd cookies to cookiejar and returns a merged CookieJar.
func
src.requests.cookies.morsel_to_cookie(morsel:Morsel[Any]) -> CookieConvert a Morsel object into a Cookie containing the one k/v pair.
class
src.requests.exceptions.ConnectionErrorA Connection error occurred.
class
src.requests.exceptions.ContentDecodingErrorFailed to decode response content.
class
src.requests.exceptions.HTTPErrorAn HTTP error occurred.
class
src.requests.exceptions.InvalidHeaderThe header value provided was somehow invalid.
class
src.requests.exceptions.InvalidJSONErrorA JSON error occurred.
class
src.requests.exceptions.InvalidProxyURLThe proxy URL provided is invalid.
class
src.requests.exceptions.InvalidSchemaThe URL scheme provided is either invalid or unsupported.
class
src.requests.exceptions.InvalidURLThe URL provided was somehow invalid.
class
src.requests.exceptions.JSONDecodeErrorCouldn't decode the text into json
class
src.requests.exceptions.MissingSchemaThe URL scheme (e.g.
class
src.requests.exceptions.ProxyErrorA proxy error occurred.
class
src.requests.exceptions.RequestExceptionThere was an ambiguous exception that occurred while handling your request.
class
src.requests.exceptions.RequestsWarningBase warning for Requests.
class
src.requests.exceptions.RetryErrorCustom retries logic failed
class
src.requests.exceptions.SSLErrorAn SSL error occurred.
class
src.requests.exceptions.StreamConsumedErrorThe content for this response was already consumed.
class
src.requests.exceptions.TimeoutThe request timed out.
class
src.requests.exceptions.TooManyRedirectsToo many redirects.
class
src.requests.exceptions.URLRequiredA valid URL is required to make a request.
func
src.requests.help.info() -> dict[str, Any]Generate information for a bug report.
func
src.requests.help.main()Pretty-print the bug information as JSON.
func
src.requests.hooks.dispatch_hook(key:str, hooks:_t.HooksInputType | None, hook_data:Response, **kwargs:Any) -> ResponseDispatches a hook dictionary on a given piece of data.
class
src.requests.models.RequestA user-created :class:`Request <Request>` object.
method
src.requests.models.Response.close() -> NoneReleases the connection back to the pool.
method
src.requests.models.Response.content() -> bytesContent of the response, in bytes.
method
src.requests.models.Response.json(**kwargs:Any) -> AnyDecodes the JSON response body (if any) as a Python object.
method
src.requests.models.Response.raise_for_status() -> NoneRaises :class:`HTTPError`, if one occurred.
method
src.requests.models.Response.text() -> strContent of the response, in unicode.
class
src.requests.sessions.SessionA Requests session.
method
src.requests.sessions.Session.close() -> NoneCloses all adapters and as such the session
method
src.requests.sessions.Session.delete(url:_t.UriType, **kwargs:Unpack[_t.RequestKwargs]) -> ResponseSends a DELETE request.
method
src.requests.sessions.Session.get(url:_t.UriType, params:_t.ParamsType=None, **kwargs:Unpack[_t.GetKwargs]) -> ResponseSends a GET request.
method
src.requests.sessions.Session.get_adapter(url:str) -> BaseAdapterReturns the appropriate connection adapter for the given URL.
method
src.requests.sessions.Session.head(url:_t.UriType, **kwargs:Unpack[_t.RequestKwargs]) -> ResponseSends a HEAD request.
method
src.requests.sessions.Session.mount(prefix:str, adapter:BaseAdapter) -> NoneRegisters a connection adapter to a prefix.
method
src.requests.sessions.Session.options(url:_t.UriType, **kwargs:Unpack[_t.RequestKwargs]) -> ResponseSends a OPTIONS request.
method
src.requests.sessions.Session.patch(url:_t.UriType, data:_t.DataType=None, **kwargs:Unpack[_t.DataKwargs]) -> ResponseSends a PATCH request.
method
src.requests.sessions.Session.post(url:_t.UriType, data:_t.DataType=None, json:_t.JsonType=None, **kwargs:Unpack[_t.PostKwargs]) -> ResponseSends a POST request.
method
src.requests.sessions.Session.put(url:_t.UriType, data:_t.DataType=None, **kwargs:Unpack[_t.DataKwargs]) -> ResponseSends a PUT request.
method
src.requests.sessions.Session.send(request:PreparedRequest, **kwargs:Any) -> ResponseSend a given PreparedRequest.
func
src.requests.sessions.merge_hooks(request_hooks:_t.HooksType, session_hooks:_t.HooksType, dict_class:type=OrderedDict) -> _t.HooksTypeProperly merges both requests and session hooks.
func
src.requests.sessions.session() -> SessionReturns a :class:`Session` for context-management.
class
src.requests.structures.CaseInsensitiveDictA case-insensitive ``dict``-like object.
method
src.requests.structures.CaseInsensitiveDict.lower_items() -> Iterator[tuple[str, _VT]]Like iteritems(), but with all lowercase keys.
class
src.requests.structures.LookupDictDictionary lookup object.
func
src.requests.utils.add_dict_to_cookiejar(cj:CookieJar, cookie_dict:dict[str, str]) -> CookieJarReturns a CookieJar from a key/value dictionary.
func
src.requests.utils.atomic_open(filename:str) -> Generator[BufferedWriter, None, None]Write a file to the disk in an atomic fashion
func
src.requests.utils.default_headers() -> CaseInsensitiveDict[str]:rtype: requests.structures.CaseInsensitiveDict
func
src.requests.utils.default_user_agent(name:str='python-requests') -> strReturn a string representing the default user agent.
func
src.requests.utils.dict_from_cookiejar(cj:CookieJar) -> dict[str, str | None]Returns a key/value dictionary from a CookieJar.
func
src.requests.utils.dict_to_sequence(d:_t.SupportsItems[Any, Any] | Iterable[tuple[Any, Any]]) -> Iterable[tuple[Any, Any]]Returns an internal sequence dictionary update.
func
src.requests.utils.get_encoding_from_headers(headers:CaseInsensitiveDict[str]) -> str | NoneReturns encodings from given HTTP Header Dict.
func
src.requests.utils.get_encodings_from_content(content:str) -> list[str]Returns encodings from given content string.
func
src.requests.utils.get_environ_proxies(url:str, no_proxy:str | None=None) -> dict[str, str]Return a dict of environment proxies.
func
src.requests.utils.get_netrc_auth(url:_t.UriType, raise_errors:bool=False) -> tuple[str, str] | NoneReturns the Requests tuple auth for a given url from netrc.
func
src.requests.utils.get_unicode_from_response(r:Response) -> str | bytes | NoneReturns the requested content back in unicode.
func
src.requests.utils.guess_filename(obj:Any) -> str | NoneTries to guess the filename of the given object.
func
src.requests.utils.guess_json_utf(data:bytes) -> str | None:rtype: str
func
src.requests.utils.is_ipv4_address(string_ip:str) -> bool:rtype: bool
func
src.requests.utils.is_valid_cidr(string_network:str) -> boolVery simple check of the cidr format in no_proxy variable.
func
src.requests.utils.parse_header_links(value:str) -> list[dict[str, str]]Return a list of parsed link headers proxies.
func
src.requests.utils.parse_list_header(value:str) -> list[str]Parse lists as described by RFC 2068 Section 2.
func
src.requests.utils.proxy_bypass(host:str) -> boolReturn True, if the host should be bypassed.
func
src.requests.utils.requote_uri(uri:str) -> strRe-quote the given URI.
func
src.requests.utils.select_proxy(url:str, proxies:dict[str, str] | None) -> str | NoneSelect a proxy for the url, if applicable.
func
src.requests.utils.should_bypass_proxies(url:str, no_proxy:str | None) -> boolReturns whether we should bypass proxies or not.
func
src.requests.utils.stream_decode_response_unicode(iterator:Iterable[bytes], r:Response) -> Generator[str | bytes, None, None]Stream decodes an iterator.
func
src.requests.utils.unquote_header_value(value:str, is_filename:bool=False) -> strUnquotes a header value.
func
src.requests.utils.urldefragauth(url:str) -> strGiven a url remove the fragment and the authentication part.
About this data
These signatures were extracted from the public source of psf/requests
using Python's ast module. Argument names, default values,
type annotations and return types are taken verbatim from the code.
Implementation bodies are never stored. See
how it works for details.