Migrating from pyiv 0.x to 1.x
pyiv 1.0 replaces the chain-based NetworkClient HTTP surface with
typed HttpClient / AsyncHttpClient interfaces. There is no
deprecation shim: upgrade call sites when you move to 1.x. The 0.x
maintenance branch remains available for patch releases of the old API.
HTTP clients
Removed
pyiv.network(NetworkClient,HTTPClient,HTTPSClient)ChainType.NETWORK_CLIENTand chain registration for HTTPDict responses (
{"status", "headers", "body", "url"})NetworkClient.handle()tuple / dict / bare-URL dispatch
Use instead
Depend on
HttpClientorAsyncHttpClientBind
UrllibHttpClient(stdlib) orRequestsHttpClient(requests extra)In tests, bind
MemoryHttpClient/MemoryAsyncHttpClient
0.x style:
from pyiv import ChainType, Config, get_injector
from pyiv.network import HTTPClient
class MyConfig(Config):
def configure(self):
self.register_chain_handler(ChainType.NETWORK_CLIENT, "http", HTTPClient)
client = get_injector(MyConfig).inject_chain_handler(
ChainType.NETWORK_CLIENT, "http"
)
result = client.request("GET", "https://example.com/")
body = result["body"]
1.x style:
from pyiv import Config, get_injector
from pyiv.http import HttpClient, UrllibHttpClient
class MyConfig(Config):
def configure(self):
self.register(HttpClient, UrllibHttpClient)
client = get_injector(MyConfig).inject(HttpClient)
response = client.get("https://example.com/")
body = response.content
response.raise_for_status()
pyiv-common
RequestsClientstill exists as an alias ofRequestsHttpClientRegister it as
HttpClient, not as aNETWORK_CLIENTchain handlerpyiv-common0.2+ requirespyiv>=1.0.0
Install: pip install "pyiv>=1.0" and, if needed,
pip install "pyiv-common>=0.2".
What did not change
SerDe chain handlers (ChainType.ENCODING), Binder, scopes, keys,
version-conditioned bindings (including later for_package_present /
for_package_absent), and test doubles for Clock / Filesystem /
Console / DateTimeService are unchanged in spirit. Only the HTTP
integration surface was redesigned.