fix(hanzoai): 3.1.1 — guard optional ZAP import so import hanzoai works without the [zap] extra

zap.py is an httpx.BaseTransport; httpx is not a base dep (client core is urllib3).
3.1.0 imported zap.py eagerly in __init__, so `import hanzoai` crashed on missing
httpx in any clean install. Guard the import (try/except ImportError) and declare
httpx under the [zap] extra. import hanzoai now works with or without extras.
This commit is contained in:
2026-07-05 19:49:03 -07:00
parent 3e22e2c016
commit f7511ac282
2 changed files with 17 additions and 12 deletions
+15 -10
View File
@@ -18,16 +18,21 @@
__version__ = "1.0.0"
# Optional ZAP-native transport (opt-in). Imported lazily inside `zap` so that
# `import hanzoai` still works when the optional `hanzo-zap` extra is not installed.
# These names are additive and intentionally NOT part of the locked `__all__`.
from . import zap as zap
from .zap import (
ZapTransport as ZapTransport,
AsyncZapTransport as AsyncZapTransport,
zap_http_client as zap_http_client,
async_zap_http_client as async_zap_http_client,
)
# Optional ZAP-native transport (opt-in via the `zap` extra). The transport is an
# httpx.BaseTransport, so `zap` requires httpx + hanzo-zap (neither is a base dep —
# the client core is urllib3). Guard the import so `import hanzoai` still works when
# the extra is absent; the names appear only when `pip install hanzoai[zap]` is used.
# Additive and intentionally NOT part of the locked `__all__`.
try:
from . import zap as zap
from .zap import (
ZapTransport as ZapTransport,
AsyncZapTransport as AsyncZapTransport,
zap_http_client as zap_http_client,
async_zap_http_client as async_zap_http_client,
)
except ImportError: # pragma: no cover - hanzoai[zap] not installed
pass
# Define package exports
__all__ = [
+2 -2
View File
@@ -1,6 +1,6 @@
[project]
name = "hanzoai"
version = "3.1.0"
version = "3.1.1"
description = "The official Python library for the Hanzo API"
dynamic = ["readme"]
license = "BSD-3-Clause"
@@ -34,7 +34,7 @@ classifiers = [
llm = ["hanzo-llm>=1.0.0"]
# Optional ZAP-native binary transport (hanzoai.zap). Off by default; opt in via
# `hanzoai.zap_http_client(...)`. hanzo-zap pulls in zap-proto for the wire codec.
zap = ["hanzo-zap>=0.7.0"]
zap = ["hanzo-zap>=0.7.0", "httpx>=0.27.0"]
[project.urls]
Homepage = "https://github.com/hanzoai/python-sdk"