pyiv_common.network
requests-backed HttpClient for pyiv.
This module provides RequestsHttpClient, a pyiv.http.HttpClient that
uses the requests library and an optional Session. Stdlib urllib clients
stay in core.
What Problem Does This Solve?
Many apps already depend on requests (sessions, adapters, timeouts). Core
pyiv cannot import it. This extra implements the same HttpClient shape
as UrllibHttpClient so you can swap transports in Config.
Real-World Use Cases:
- Inject an HTTP client that reuses a requests.Session
- Prefer requests connection pooling while keeping call sites on HttpClient
Example
>>> from pyiv_common.network import RequestsHttpClient
>>> client = RequestsHttpClient()
>>> client.request("GET", "ftp://example.com/")
Traceback (most recent call last):
...
ValueError: Only http:// and https:// URLs are allowed, got: ftp://example.com/
Classes
alias of |
|
|
HTTP(S) client using the requests library. |
- pyiv_common.network.RequestsClient
alias of
RequestsHttpClient
- class pyiv_common.network.RequestsHttpClient(base_url=None, headers=None, timeout=None, https_only=False, session=None)[source]
Bases:
HttpClientHTTP(S) client using the requests library.
Why this exists: Teams that already standardize on requests can bind this implementation to
HttpClientwithout changing call sites that expectjson=,raise_for_status, or streaming lines.Example
>>> from pyiv import Config, get_injector >>> from pyiv.http import HttpClient >>> from pyiv_common.network import RequestsHttpClient >>> class MyConfig(Config): ... def configure(self): ... self.register(HttpClient, RequestsHttpClient) >>> injector = get_injector(MyConfig) >>> isinstance(injector.inject(HttpClient), RequestsHttpClient) True