clientwright 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clientwright/__init__.py +179 -0
- clientwright/__version__.py +1 -0
- clientwright/adapters/__init__.py +3 -0
- clientwright/adapters/_httpx_shared.py +831 -0
- clientwright/adapters/_lazy.py +30 -0
- clientwright/adapters/aiohttp/__init__.py +45 -0
- clientwright/adapters/aiohttp/_imports.py +30 -0
- clientwright/adapters/aiohttp/adapter.py +236 -0
- clientwright/adapters/aiohttp/capabilities.py +81 -0
- clientwright/adapters/aiohttp/classify.py +59 -0
- clientwright/adapters/aiohttp/errors.py +57 -0
- clientwright/adapters/aiohttp/middleware.py +103 -0
- clientwright/adapters/aiohttp/normalize.py +64 -0
- clientwright/adapters/aiohttp/options.py +16 -0
- clientwright/adapters/aiohttp/trace.py +109 -0
- clientwright/adapters/aiohttp/views.py +108 -0
- clientwright/adapters/httpx/__init__.py +45 -0
- clientwright/adapters/httpx/_imports.py +17 -0
- clientwright/adapters/httpx/adapter.py +39 -0
- clientwright/adapters/httpx/capabilities.py +9 -0
- clientwright/adapters/httpx/classify.py +14 -0
- clientwright/adapters/httpx/errors.py +35 -0
- clientwright/adapters/httpx/normalize.py +27 -0
- clientwright/adapters/httpx/normalize_sync.py +27 -0
- clientwright/adapters/httpx/transport.py +40 -0
- clientwright/adapters/httpx/views.py +46 -0
- clientwright/adapters/httpx2/__init__.py +46 -0
- clientwright/adapters/httpx2/_imports.py +18 -0
- clientwright/adapters/httpx2/adapter.py +37 -0
- clientwright/adapters/httpx2/capabilities.py +9 -0
- clientwright/adapters/httpx2/classify.py +14 -0
- clientwright/adapters/httpx2/errors.py +36 -0
- clientwright/adapters/httpx2/normalize.py +27 -0
- clientwright/adapters/httpx2/normalize_sync.py +27 -0
- clientwright/adapters/httpx2/transport.py +35 -0
- clientwright/adapters/httpx2/views.py +45 -0
- clientwright/adapters/observability/__init__.py +26 -0
- clientwright/adapters/observability/_metrics/__init__.py +1 -0
- clientwright/adapters/observability/_metrics/prometheus.py +200 -0
- clientwright/adapters/observability/_tracing/__init__.py +3 -0
- clientwright/adapters/observability/_tracing/otel.py +61 -0
- clientwright/adapters/requests/__init__.py +45 -0
- clientwright/adapters/requests/_imports.py +21 -0
- clientwright/adapters/requests/adapter.py +206 -0
- clientwright/adapters/requests/capabilities.py +80 -0
- clientwright/adapters/requests/classify.py +62 -0
- clientwright/adapters/requests/errors.py +40 -0
- clientwright/adapters/requests/normalize.py +63 -0
- clientwright/adapters/requests/views.py +121 -0
- clientwright/adapters/urllib3/__init__.py +48 -0
- clientwright/adapters/urllib3/_imports.py +18 -0
- clientwright/adapters/urllib3/adapter.py +260 -0
- clientwright/adapters/urllib3/capabilities.py +86 -0
- clientwright/adapters/urllib3/classify.py +46 -0
- clientwright/adapters/urllib3/errors.py +55 -0
- clientwright/adapters/urllib3/normalize.py +51 -0
- clientwright/adapters/urllib3/views.py +119 -0
- clientwright/contrib/__init__.py +3 -0
- clientwright/contrib/deadline.py +107 -0
- clientwright/contrib/dishka.py +80 -0
- clientwright/core/__init__.py +6 -0
- clientwright/core/balancer/__init__.py +1 -0
- clientwright/core/balancer/policy.py +23 -0
- clientwright/core/capabilities.py +156 -0
- clientwright/core/config.py +367 -0
- clientwright/core/contracts/__init__.py +33 -0
- clientwright/core/contracts/adapter.py +62 -0
- clientwright/core/contracts/context.py +31 -0
- clientwright/core/contracts/message.py +118 -0
- clientwright/core/contracts/observability.py +92 -0
- clientwright/core/contracts/settings.py +140 -0
- clientwright/core/engine/__init__.py +1 -0
- clientwright/core/engine/aio.py +246 -0
- clientwright/core/engine/base.py +65 -0
- clientwright/core/engine/redirects.py +64 -0
- clientwright/core/engine/suppress.py +30 -0
- clientwright/core/engine/sync.py +241 -0
- clientwright/core/errors.py +113 -0
- clientwright/core/model.py +138 -0
- clientwright/core/native.py +84 -0
- clientwright/core/options.py +46 -0
- clientwright/core/plan.py +190 -0
- clientwright/core/policy/__init__.py +1 -0
- clientwright/core/policy/budget.py +76 -0
- clientwright/core/policy/circuit.py +169 -0
- clientwright/core/policy/concurrency.py +98 -0
- clientwright/core/policy/retry.py +80 -0
- clientwright/core/policy/timeout.py +64 -0
- clientwright/core/registry.py +75 -0
- clientwright/core/telemetry/__init__.py +6 -0
- clientwright/core/telemetry/emitter.py +163 -0
- clientwright/core/telemetry/names.py +61 -0
- clientwright/core/telemetry/null.py +89 -0
- clientwright/core/telemetry/redaction.py +24 -0
- clientwright/core/testing/__init__.py +7 -0
- clientwright/core/testing/doubles.py +107 -0
- clientwright/core/testing/origin.py +201 -0
- clientwright/py.typed +0 -0
- clientwright-0.1.0.dist-info/METADATA +210 -0
- clientwright-0.1.0.dist-info/RECORD +102 -0
- clientwright-0.1.0.dist-info/WHEEL +4 -0
- clientwright-0.1.0.dist-info/licenses/LICENSE +201 -0
clientwright/__init__.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"""clientwright: one resilience and observability core, many HTTP clients.
|
|
2
|
+
|
|
3
|
+
``build()`` returns the REAL native client of the chosen adapter - a genuine
|
|
4
|
+
``httpx.AsyncClient``, not a wrapper - with retries, circuit breaking, owned
|
|
5
|
+
redirects, deadlines and telemetry wired UNDER its public API. ``inspect()``
|
|
6
|
+
returns the handle with the config-application report and runtime state.
|
|
7
|
+
|
|
8
|
+
A bare install is a working install: the core has zero dependencies; adapters
|
|
9
|
+
and observability backends load lazily behind extras.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from .__version__ import __version__
|
|
15
|
+
from .core.capabilities import (
|
|
16
|
+
AdapterCapabilities,
|
|
17
|
+
Capability,
|
|
18
|
+
ConfigApplicationReport,
|
|
19
|
+
DurationBoundary,
|
|
20
|
+
SeamGranularity,
|
|
21
|
+
Support,
|
|
22
|
+
capabilities_matrix,
|
|
23
|
+
)
|
|
24
|
+
from .core.config import (
|
|
25
|
+
DEFAULT_RETRYABLE_KINDS,
|
|
26
|
+
DEFAULT_RETRYABLE_STATUS,
|
|
27
|
+
DEFAULT_SENSITIVE_HEADERS,
|
|
28
|
+
DEFAULT_SENSITIVE_QUERY_PARAMS,
|
|
29
|
+
DEFAULT_TRIP_KINDS,
|
|
30
|
+
UNSET,
|
|
31
|
+
CallerOverride,
|
|
32
|
+
CircuitBreakerConfig,
|
|
33
|
+
ClientConfig,
|
|
34
|
+
Maybe,
|
|
35
|
+
NativeOptions,
|
|
36
|
+
ObservabilityConfig,
|
|
37
|
+
PoolConfig,
|
|
38
|
+
ProxyConfig,
|
|
39
|
+
RedirectMode,
|
|
40
|
+
RetryConfig,
|
|
41
|
+
RetryMode,
|
|
42
|
+
TimeoutConfig,
|
|
43
|
+
TlsConfig,
|
|
44
|
+
UnsupportedPolicy,
|
|
45
|
+
is_set,
|
|
46
|
+
)
|
|
47
|
+
from .core.contracts import (
|
|
48
|
+
AdapterDeps,
|
|
49
|
+
CircuitBreakerSettingsProtocol,
|
|
50
|
+
ClientAdapter,
|
|
51
|
+
ClientMetricsProtocol,
|
|
52
|
+
ClientSettingsProtocol,
|
|
53
|
+
DeadlineSource,
|
|
54
|
+
HeaderProvider,
|
|
55
|
+
RetrySettingsProtocol,
|
|
56
|
+
SpanProtocol,
|
|
57
|
+
TracerProtocol,
|
|
58
|
+
)
|
|
59
|
+
from .core.contracts.adapter import default_deps
|
|
60
|
+
from .core.contracts.settings import client_config_from_settings
|
|
61
|
+
from .core.errors import (
|
|
62
|
+
CallError,
|
|
63
|
+
CircuitOpenError,
|
|
64
|
+
ClientwrightError,
|
|
65
|
+
DeadlineExceededError,
|
|
66
|
+
NativeConfigError,
|
|
67
|
+
NotReplayableError,
|
|
68
|
+
TooManyRedirectsError,
|
|
69
|
+
UnknownAdapterError,
|
|
70
|
+
UnsupportedCapabilityError,
|
|
71
|
+
)
|
|
72
|
+
from .core.model import IDEMPOTENT_METHODS, CircuitKey, FailureKind, Outcome, RequestInfo, ResolvedTimeouts
|
|
73
|
+
from .core.options import CallOptions, call_options, current_call_options
|
|
74
|
+
from .core.plan import ClientHandle, ClientRuntime, inspect_client
|
|
75
|
+
from .core.registry import register_adapter, registered_adapters, resolve_adapter
|
|
76
|
+
|
|
77
|
+
# The builders are typed ``Any`` deliberately. The whole product is "you get the
|
|
78
|
+
# REAL native client", and the core cannot name ``httpx.AsyncClient`` without
|
|
79
|
+
# taking a dependency on it - so a narrower type would be a lie that forces a
|
|
80
|
+
# cast on every caller. ``Any`` lets `client: httpx.AsyncClient = build(...)`
|
|
81
|
+
# type-check, which is exactly what the tutorial promises.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def build_handle(adapter: str, config: ClientConfig, deps: AdapterDeps | None = None) -> ClientHandle[Any]:
|
|
85
|
+
"""Build an ASYNC native client and return its full handle."""
|
|
86
|
+
adapter_cls = resolve_adapter(adapter)
|
|
87
|
+
return adapter_cls().build_async(config, deps or default_deps()) # type: ignore[no-any-return]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def build(adapter: str, config: ClientConfig, deps: AdapterDeps | None = None) -> Any:
|
|
91
|
+
"""Build an ASYNC native client (e.g. a genuine ``httpx.AsyncClient``)."""
|
|
92
|
+
return build_handle(adapter, config, deps).client
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def build_sync_handle(adapter: str, config: ClientConfig, deps: AdapterDeps | None = None) -> ClientHandle[Any]:
|
|
96
|
+
"""Build a SYNC native client and return its full handle."""
|
|
97
|
+
adapter_cls = resolve_adapter(adapter)
|
|
98
|
+
return adapter_cls().build_sync(config, deps or default_deps()) # type: ignore[no-any-return]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def build_sync(adapter: str, config: ClientConfig, deps: AdapterDeps | None = None) -> Any:
|
|
102
|
+
"""Build a SYNC native client (e.g. a genuine ``httpx.Client``)."""
|
|
103
|
+
return build_sync_handle(adapter, config, deps).client
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
inspect = inspect_client
|
|
107
|
+
|
|
108
|
+
__all__ = [
|
|
109
|
+
"DEFAULT_RETRYABLE_KINDS",
|
|
110
|
+
"DEFAULT_RETRYABLE_STATUS",
|
|
111
|
+
"DEFAULT_SENSITIVE_HEADERS",
|
|
112
|
+
"DEFAULT_SENSITIVE_QUERY_PARAMS",
|
|
113
|
+
"DEFAULT_TRIP_KINDS",
|
|
114
|
+
"IDEMPOTENT_METHODS",
|
|
115
|
+
"UNSET",
|
|
116
|
+
"AdapterCapabilities",
|
|
117
|
+
"AdapterDeps",
|
|
118
|
+
"CallError",
|
|
119
|
+
"CallOptions",
|
|
120
|
+
"CallerOverride",
|
|
121
|
+
"Capability",
|
|
122
|
+
"CircuitBreakerConfig",
|
|
123
|
+
"CircuitBreakerSettingsProtocol",
|
|
124
|
+
"CircuitKey",
|
|
125
|
+
"CircuitOpenError",
|
|
126
|
+
"ClientAdapter",
|
|
127
|
+
"ClientConfig",
|
|
128
|
+
"ClientHandle",
|
|
129
|
+
"ClientMetricsProtocol",
|
|
130
|
+
"ClientRuntime",
|
|
131
|
+
"ClientSettingsProtocol",
|
|
132
|
+
"ClientwrightError",
|
|
133
|
+
"ConfigApplicationReport",
|
|
134
|
+
"DeadlineExceededError",
|
|
135
|
+
"DeadlineSource",
|
|
136
|
+
"DurationBoundary",
|
|
137
|
+
"FailureKind",
|
|
138
|
+
"HeaderProvider",
|
|
139
|
+
"Maybe",
|
|
140
|
+
"NativeConfigError",
|
|
141
|
+
"NativeOptions",
|
|
142
|
+
"NotReplayableError",
|
|
143
|
+
"ObservabilityConfig",
|
|
144
|
+
"Outcome",
|
|
145
|
+
"PoolConfig",
|
|
146
|
+
"ProxyConfig",
|
|
147
|
+
"RedirectMode",
|
|
148
|
+
"RequestInfo",
|
|
149
|
+
"ResolvedTimeouts",
|
|
150
|
+
"RetryConfig",
|
|
151
|
+
"RetryMode",
|
|
152
|
+
"RetrySettingsProtocol",
|
|
153
|
+
"SeamGranularity",
|
|
154
|
+
"SpanProtocol",
|
|
155
|
+
"Support",
|
|
156
|
+
"TimeoutConfig",
|
|
157
|
+
"TlsConfig",
|
|
158
|
+
"TooManyRedirectsError",
|
|
159
|
+
"TracerProtocol",
|
|
160
|
+
"UnknownAdapterError",
|
|
161
|
+
"UnsupportedCapabilityError",
|
|
162
|
+
"UnsupportedPolicy",
|
|
163
|
+
"__version__",
|
|
164
|
+
"build",
|
|
165
|
+
"build_handle",
|
|
166
|
+
"build_sync",
|
|
167
|
+
"build_sync_handle",
|
|
168
|
+
"call_options",
|
|
169
|
+
"capabilities_matrix",
|
|
170
|
+
"client_config_from_settings",
|
|
171
|
+
"current_call_options",
|
|
172
|
+
"default_deps",
|
|
173
|
+
"inspect",
|
|
174
|
+
"inspect_client",
|
|
175
|
+
"is_set",
|
|
176
|
+
"register_adapter",
|
|
177
|
+
"registered_adapters",
|
|
178
|
+
"resolve_adapter",
|
|
179
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0" # x-release-please-version
|