pyiv_common
Ubiquitous-library integrations for pyiv.
pyiv-common is the #include <stdlib.h> extra for pyiv: PyYAML and
requests. Core pyiv stays stdlib-only (including urllib HTTP clients).
What Problem Does This Solve?
Libraries such as PyYAML and requests are everywhere in Python, but they
are not the standard library. Putting them in core would break pyiv’s
zero-runtime-dependency guarantee. A dedicated package per library would
proliferate wheels. pyiv-common is that middle tier.
Real-World Use Cases:
- YAML config files via YAMLSerDe
- HTTP with the requests stack via RequestsHttpClient
- Injecting those types through a pyiv Config
Usage:
>>> from pyiv_common.serde import YAMLSerDe
>>> YAMLSerDe().handler_type
'yaml'
>>> 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/
- pyiv_common.RequestsClient
alias of
RequestsHttpClient
- class pyiv_common.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
- class pyiv_common.YAMLSerDe[source]
Bases:
SerDeYAML encoding SerDe using PyYAML.
Install with
pip install pyiv-common. Register on the ENCODING chain like any otherSerDe.Example
>>> from pyiv import ChainType, Config, get_injector >>> from pyiv_common.serde import YAMLSerDe >>> class MyConfig(Config): ... def configure(self): ... self.register_chain_handler(ChainType.ENCODING, "yaml", YAMLSerDe) >>> injector = get_injector(MyConfig) >>> serde = injector.inject_chain_handler(ChainType.ENCODING, "yaml") >>> serde.deserialize(serde.serialize({"a": 1})) {'a': 1}
Modules
YAML SerDe for pyiv, backed by PyYAML. |
|
requests-backed HttpClient for pyiv. |