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.
Files changed (102) hide show
  1. clientwright/__init__.py +179 -0
  2. clientwright/__version__.py +1 -0
  3. clientwright/adapters/__init__.py +3 -0
  4. clientwright/adapters/_httpx_shared.py +831 -0
  5. clientwright/adapters/_lazy.py +30 -0
  6. clientwright/adapters/aiohttp/__init__.py +45 -0
  7. clientwright/adapters/aiohttp/_imports.py +30 -0
  8. clientwright/adapters/aiohttp/adapter.py +236 -0
  9. clientwright/adapters/aiohttp/capabilities.py +81 -0
  10. clientwright/adapters/aiohttp/classify.py +59 -0
  11. clientwright/adapters/aiohttp/errors.py +57 -0
  12. clientwright/adapters/aiohttp/middleware.py +103 -0
  13. clientwright/adapters/aiohttp/normalize.py +64 -0
  14. clientwright/adapters/aiohttp/options.py +16 -0
  15. clientwright/adapters/aiohttp/trace.py +109 -0
  16. clientwright/adapters/aiohttp/views.py +108 -0
  17. clientwright/adapters/httpx/__init__.py +45 -0
  18. clientwright/adapters/httpx/_imports.py +17 -0
  19. clientwright/adapters/httpx/adapter.py +39 -0
  20. clientwright/adapters/httpx/capabilities.py +9 -0
  21. clientwright/adapters/httpx/classify.py +14 -0
  22. clientwright/adapters/httpx/errors.py +35 -0
  23. clientwright/adapters/httpx/normalize.py +27 -0
  24. clientwright/adapters/httpx/normalize_sync.py +27 -0
  25. clientwright/adapters/httpx/transport.py +40 -0
  26. clientwright/adapters/httpx/views.py +46 -0
  27. clientwright/adapters/httpx2/__init__.py +46 -0
  28. clientwright/adapters/httpx2/_imports.py +18 -0
  29. clientwright/adapters/httpx2/adapter.py +37 -0
  30. clientwright/adapters/httpx2/capabilities.py +9 -0
  31. clientwright/adapters/httpx2/classify.py +14 -0
  32. clientwright/adapters/httpx2/errors.py +36 -0
  33. clientwright/adapters/httpx2/normalize.py +27 -0
  34. clientwright/adapters/httpx2/normalize_sync.py +27 -0
  35. clientwright/adapters/httpx2/transport.py +35 -0
  36. clientwright/adapters/httpx2/views.py +45 -0
  37. clientwright/adapters/observability/__init__.py +26 -0
  38. clientwright/adapters/observability/_metrics/__init__.py +1 -0
  39. clientwright/adapters/observability/_metrics/prometheus.py +200 -0
  40. clientwright/adapters/observability/_tracing/__init__.py +3 -0
  41. clientwright/adapters/observability/_tracing/otel.py +61 -0
  42. clientwright/adapters/requests/__init__.py +45 -0
  43. clientwright/adapters/requests/_imports.py +21 -0
  44. clientwright/adapters/requests/adapter.py +206 -0
  45. clientwright/adapters/requests/capabilities.py +80 -0
  46. clientwright/adapters/requests/classify.py +62 -0
  47. clientwright/adapters/requests/errors.py +40 -0
  48. clientwright/adapters/requests/normalize.py +63 -0
  49. clientwright/adapters/requests/views.py +121 -0
  50. clientwright/adapters/urllib3/__init__.py +48 -0
  51. clientwright/adapters/urllib3/_imports.py +18 -0
  52. clientwright/adapters/urllib3/adapter.py +260 -0
  53. clientwright/adapters/urllib3/capabilities.py +86 -0
  54. clientwright/adapters/urllib3/classify.py +46 -0
  55. clientwright/adapters/urllib3/errors.py +55 -0
  56. clientwright/adapters/urllib3/normalize.py +51 -0
  57. clientwright/adapters/urllib3/views.py +119 -0
  58. clientwright/contrib/__init__.py +3 -0
  59. clientwright/contrib/deadline.py +107 -0
  60. clientwright/contrib/dishka.py +80 -0
  61. clientwright/core/__init__.py +6 -0
  62. clientwright/core/balancer/__init__.py +1 -0
  63. clientwright/core/balancer/policy.py +23 -0
  64. clientwright/core/capabilities.py +156 -0
  65. clientwright/core/config.py +367 -0
  66. clientwright/core/contracts/__init__.py +33 -0
  67. clientwright/core/contracts/adapter.py +62 -0
  68. clientwright/core/contracts/context.py +31 -0
  69. clientwright/core/contracts/message.py +118 -0
  70. clientwright/core/contracts/observability.py +92 -0
  71. clientwright/core/contracts/settings.py +140 -0
  72. clientwright/core/engine/__init__.py +1 -0
  73. clientwright/core/engine/aio.py +246 -0
  74. clientwright/core/engine/base.py +65 -0
  75. clientwright/core/engine/redirects.py +64 -0
  76. clientwright/core/engine/suppress.py +30 -0
  77. clientwright/core/engine/sync.py +241 -0
  78. clientwright/core/errors.py +113 -0
  79. clientwright/core/model.py +138 -0
  80. clientwright/core/native.py +84 -0
  81. clientwright/core/options.py +46 -0
  82. clientwright/core/plan.py +190 -0
  83. clientwright/core/policy/__init__.py +1 -0
  84. clientwright/core/policy/budget.py +76 -0
  85. clientwright/core/policy/circuit.py +169 -0
  86. clientwright/core/policy/concurrency.py +98 -0
  87. clientwright/core/policy/retry.py +80 -0
  88. clientwright/core/policy/timeout.py +64 -0
  89. clientwright/core/registry.py +75 -0
  90. clientwright/core/telemetry/__init__.py +6 -0
  91. clientwright/core/telemetry/emitter.py +163 -0
  92. clientwright/core/telemetry/names.py +61 -0
  93. clientwright/core/telemetry/null.py +89 -0
  94. clientwright/core/telemetry/redaction.py +24 -0
  95. clientwright/core/testing/__init__.py +7 -0
  96. clientwright/core/testing/doubles.py +107 -0
  97. clientwright/core/testing/origin.py +201 -0
  98. clientwright/py.typed +0 -0
  99. clientwright-0.1.0.dist-info/METADATA +210 -0
  100. clientwright-0.1.0.dist-info/RECORD +102 -0
  101. clientwright-0.1.0.dist-info/WHEEL +4 -0
  102. clientwright-0.1.0.dist-info/licenses/LICENSE +201 -0
@@ -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
@@ -0,0 +1,3 @@
1
+ """Adapter namespace marker. Import concrete adapters from their subpackages."""
2
+
3
+ __all__: list[str] = []