python-wrap 0.2.1__py3-none-any.whl → 0.4.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.
- python_wrap/__init__.py +348 -1
- python_wrap/__main__.py +57 -0
- python_wrap/_backend.py +133 -0
- python_wrap/_buckets.py +162 -0
- python_wrap/_core.py +12 -3
- python_wrap/_data/agent_guide.md +103 -0
- python_wrap/_data/recipes.json +703 -0
- python_wrap/_fork.py +113 -0
- python_wrap/_integration.py +29 -0
- python_wrap/_runtime.py +157 -0
- python_wrap/adapters/__init__.py +101 -0
- python_wrap/adapters/_frameworks.py +251 -0
- python_wrap/adapters/_sdk.py +1978 -0
- python_wrap/adapters/anthropic.py +139 -0
- python_wrap/adapters/langchain.py +288 -0
- python_wrap/adapters/openai.py +169 -0
- python_wrap/adapters/openai_agents.py +468 -0
- python_wrap/adapters/pydantic_ai.py +459 -0
- python_wrap/adaptive.py +605 -0
- python_wrap/agents.py +2503 -0
- python_wrap/alerts.py +293 -0
- python_wrap/async_cache.py +745 -0
- python_wrap/batching.py +17 -4
- python_wrap/buffering.py +952 -0
- python_wrap/bulkhead.py +58 -6
- python_wrap/caching.py +425 -56
- python_wrap/celery.py +528 -0
- python_wrap/chaos.py +519 -0
- python_wrap/circuit.py +454 -23
- python_wrap/compat.py +267 -0
- python_wrap/concurrency.py +82 -1746
- python_wrap/config.py +25 -4
- python_wrap/coordination.py +638 -0
- python_wrap/credentials.py +126 -0
- python_wrap/dashboard.py +358 -0
- python_wrap/debounce.py +538 -0
- python_wrap/django.py +100 -0
- python_wrap/doctor.py +599 -0
- python_wrap/events.py +145 -4
- python_wrap/exporters.py +663 -0
- python_wrap/fastapi.py +81 -0
- python_wrap/flask.py +61 -0
- python_wrap/genai.py +1101 -0
- python_wrap/health.py +187 -0
- python_wrap/http.py +940 -0
- python_wrap/idempotency.py +446 -0
- python_wrap/introspect.py +738 -0
- python_wrap/lifecycle.py +620 -0
- python_wrap/llm.py +2574 -0
- python_wrap/llm_cassette.py +948 -0
- python_wrap/llm_http_chaos.py +326 -0
- python_wrap/llm_shared.py +772 -0
- python_wrap/llm_testing.py +990 -0
- python_wrap/llm_validate.py +383 -0
- python_wrap/local_state.py +395 -0
- python_wrap/logs.py +82 -26
- python_wrap/mcp.py +490 -0
- python_wrap/mcp_guard.py +357 -0
- python_wrap/metrics.py +6 -3
- python_wrap/migrate.py +1452 -0
- python_wrap/observability.py +484 -0
- python_wrap/periodic.py +24 -2
- python_wrap/policies.py +396 -0
- python_wrap/policy.py +14 -0
- python_wrap/predicates.py +276 -0
- python_wrap/presets.py +378 -0
- python_wrap/processing.py +227 -0
- python_wrap/propagation.py +62 -0
- python_wrap/pytest_plugin.py +85 -0
- python_wrap/quotas.py +319 -0
- python_wrap/ratelimit.py +560 -0
- python_wrap/redaction.py +228 -0
- python_wrap/retry.py +448 -70
- python_wrap/shared.py +653 -0
- python_wrap/singleflight.py +255 -0
- python_wrap/slow.py +72 -0
- python_wrap/stores.py +168 -0
- python_wrap/switches.py +164 -0
- python_wrap/testing.py +34 -8
- python_wrap/timeouts.py +874 -0
- python_wrap/timing.py +239 -17
- python_wrap/validation.py +187 -12
- python_wrap/web.py +723 -0
- {python_wrap-0.2.1.dist-info → python_wrap-0.4.0.dist-info}/METADATA +117 -7
- python_wrap-0.4.0.dist-info/RECORD +95 -0
- python_wrap-0.2.1.dist-info/RECORD +0 -29
- {python_wrap-0.2.1.dist-info → python_wrap-0.4.0.dist-info}/WHEEL +0 -0
- {python_wrap-0.2.1.dist-info → python_wrap-0.4.0.dist-info}/licenses/LICENSE +0 -0
python_wrap/events.py
CHANGED
|
@@ -23,12 +23,17 @@ Listener = Callable[[Event], None]
|
|
|
23
23
|
#: function's qualified name unless noted). The docs page renders this mapping.
|
|
24
24
|
EVENT_NAMES: Mapping[str, str] = MappingProxyType(
|
|
25
25
|
{
|
|
26
|
+
"timing.slow": "A call exceeded its slow-call threshold. Fields: seconds (float).",
|
|
26
27
|
"retry.attempt_failed": (
|
|
27
28
|
"An attempt failed and another will follow. Fields: attempt (int, 1-based), "
|
|
28
29
|
"exception (BaseException, or None for a value rejected by retry_if_result), "
|
|
29
|
-
"next_delay (float seconds before the next attempt)
|
|
30
|
+
"next_delay (float seconds before the next attempt), attempt_seconds (float or None, "
|
|
31
|
+
"how long the attempt ran)."
|
|
32
|
+
),
|
|
33
|
+
"retry.succeeded": (
|
|
34
|
+
"The call finally succeeded. Fields: attempts (int, total made), "
|
|
35
|
+
"attempt_seconds (float or None, the last attempt's duration)."
|
|
30
36
|
),
|
|
31
|
-
"retry.succeeded": "The call finally succeeded. Fields: attempts (int, total made).",
|
|
32
37
|
"retry.budget_exhausted": (
|
|
33
38
|
"A shared RetryBudget refused another retry; the call stops (retry.gave_up "
|
|
34
39
|
"follows). Fields: attempts (int), exception (BaseException, or None when "
|
|
@@ -36,12 +41,14 @@ EVENT_NAMES: Mapping[str, str] = MappingProxyType(
|
|
|
36
41
|
),
|
|
37
42
|
"retry.gave_up": (
|
|
38
43
|
"Attempts were exhausted. Fields: attempts (int), exception (BaseException, or "
|
|
39
|
-
"None when the last attempt returned a value rejected by retry_if_result)
|
|
44
|
+
"None when the last attempt returned a value rejected by retry_if_result), "
|
|
45
|
+
"attempt_seconds (float or None, the last attempt's duration)."
|
|
40
46
|
),
|
|
41
47
|
"timeout.expired": "A call exceeded its time limit. Fields: seconds (float, the limit).",
|
|
42
48
|
"circuit.state_changed": (
|
|
43
49
|
"A circuit breaker moved between states. function is the breaker name. "
|
|
44
|
-
"Fields: old (str), new (str): 'closed', 'open' or 'half_open'
|
|
50
|
+
"Fields: old (str), new (str): 'closed', 'open' or 'half_open'; a breaker "
|
|
51
|
+
"with failure_rate or slow_call_rate adds failure_rate and slow_rate (float)."
|
|
45
52
|
),
|
|
46
53
|
"circuit.rejected": (
|
|
47
54
|
"A call was refused because the circuit is open. Fields: retry_after (float seconds)."
|
|
@@ -55,6 +62,7 @@ EVENT_NAMES: Mapping[str, str] = MappingProxyType(
|
|
|
55
62
|
"throttle.skipped": "A call was skipped by throttle. No fields.",
|
|
56
63
|
"cache.hit": "A cached value was returned. No fields.",
|
|
57
64
|
"cache.miss": "No cached value; the function ran. No fields.",
|
|
65
|
+
"cache.rejected": "A cache entry failed signature verification. Fields: reason (str).",
|
|
58
66
|
"cache.evicted": "An entry left the cache. Fields: reason (str): 'lru' or 'ttl'.",
|
|
59
67
|
"cache.stale": (
|
|
60
68
|
"A stale value was served (stale-while-revalidate) and a background refresh "
|
|
@@ -75,6 +83,139 @@ EVENT_NAMES: Mapping[str, str] = MappingProxyType(
|
|
|
75
83
|
"A background run of a periodic function raised. Fields: run (int), "
|
|
76
84
|
"exception (BaseException)."
|
|
77
85
|
),
|
|
86
|
+
"adaptive.limit_changed": (
|
|
87
|
+
"An AdaptiveLimiter changed its concurrency limit. function is the limiter name. "
|
|
88
|
+
"Fields: old (int), new (int)."
|
|
89
|
+
),
|
|
90
|
+
"adaptive.shed": (
|
|
91
|
+
"An AdaptiveLimiter rejected a call over its limit (LoadShed). "
|
|
92
|
+
"Fields: limit (int), in_flight (int)."
|
|
93
|
+
),
|
|
94
|
+
"lifecycle.drain_started": "A shutdown drain began. Fields: items (int).",
|
|
95
|
+
"lifecycle.item_done": (
|
|
96
|
+
"One registered item finished draining. function is the item name. "
|
|
97
|
+
"Fields: status (str): 'ok', 'error' or 'timeout'; seconds (float)."
|
|
98
|
+
),
|
|
99
|
+
"lifecycle.drain_finished": (
|
|
100
|
+
"A shutdown drain completed. Fields: ok (bool), seconds (float)."
|
|
101
|
+
),
|
|
102
|
+
"genai.llm_call": (
|
|
103
|
+
"A traced_llm call finished. function is the traced function. Fields: kind, "
|
|
104
|
+
"run_id, step, tool, model, system, input_tokens, output_tokens, cost, latency "
|
|
105
|
+
"(seconds), started (epoch seconds), status ('ok'/'error'), error_type, attempts "
|
|
106
|
+
"(failed inner retry attempts or None); input/output/error only with content capture."
|
|
107
|
+
),
|
|
108
|
+
"genai.tool_call": (
|
|
109
|
+
"A traced_tool call finished. Same fields as genai.llm_call; tool is the tool name."
|
|
110
|
+
),
|
|
111
|
+
"llm.fallback_served": (
|
|
112
|
+
"A fallback_models chain returned an answer. function is the chain name. "
|
|
113
|
+
"Fields: model (str, the entry that served, or 'cached'), index (int, -1 for "
|
|
114
|
+
"the cached answer), failed (tuple of str, entries that failed first)."
|
|
115
|
+
),
|
|
116
|
+
"llm.budget_exceeded": (
|
|
117
|
+
"A Budget refused a call. Fields: budget (str), scope (str), tokens (int), "
|
|
118
|
+
"usd (float), the spend so far."
|
|
119
|
+
),
|
|
120
|
+
"llm.validation_failed": (
|
|
121
|
+
"A validated() call's output failed validation. function is the wrapped function. "
|
|
122
|
+
"Fields: attempt (int, 1-based), error (str, truncated)."
|
|
123
|
+
),
|
|
124
|
+
"llm.repair_exhausted": (
|
|
125
|
+
"A validated() call gave up. Fields: attempts (int), reason (str: 'max_repairs', "
|
|
126
|
+
"'max_tokens' or 'budget')."
|
|
127
|
+
),
|
|
128
|
+
"llm.cassette_recorded": (
|
|
129
|
+
"A Cassette recorded one HTTP exchange. function is 'cassette'. "
|
|
130
|
+
"Fields: status (int), key (str, the first 12 characters of the request key)."
|
|
131
|
+
),
|
|
132
|
+
"rate_limit.store_error": (
|
|
133
|
+
"A shared token window could not reach its storage and fell back to a local "
|
|
134
|
+
"bucket (or raised, with fail_open=False). function is the window name. "
|
|
135
|
+
"Fields: error (str, the exception class), op (str)."
|
|
136
|
+
),
|
|
137
|
+
"backend.error": (
|
|
138
|
+
"A shared backend (breaker state, window, quota, cache store, switch source) "
|
|
139
|
+
"raised. function is the backend name. Fields: backend (str kind), operation "
|
|
140
|
+
"(str), error (str, the exception class). The call then follows on_backend_error."
|
|
141
|
+
),
|
|
142
|
+
"config.changed": (
|
|
143
|
+
"A named policy was (re)loaded. function is the policy name. Fields: generation (int)."
|
|
144
|
+
),
|
|
145
|
+
"config.rejected": (
|
|
146
|
+
"A watched policy source could not be read or validated; the current policies "
|
|
147
|
+
"stay. function is 'policies'. Fields: error (str, the exception class)."
|
|
148
|
+
),
|
|
149
|
+
"backend.recovered": (
|
|
150
|
+
"A shared backend answered again after backend.error. Fields: backend (str)."
|
|
151
|
+
),
|
|
152
|
+
"llm.stream_resumed": (
|
|
153
|
+
"A resume_safe stream failed before any output and is reopened. function is "
|
|
154
|
+
"the stream name. Fields: attempt (int, the attempt that failed), exception "
|
|
155
|
+
"(BaseException), delay (float seconds before reopening)."
|
|
156
|
+
),
|
|
157
|
+
"llm.stream_interrupted": (
|
|
158
|
+
"A resume_safe stream failed after output started; StreamInterrupted is raised "
|
|
159
|
+
"instead of replaying. Fields: chars (int, partial text length), tool_calls "
|
|
160
|
+
"(int, completed tool calls), exception (BaseException)."
|
|
161
|
+
),
|
|
162
|
+
"llm.prompt_cache_cold": (
|
|
163
|
+
"A CacheGuard saw almost no prompt-cache hits across its calls. function is the "
|
|
164
|
+
"guard name. Fields: calls (int), hit_rate (float), reasons (tuple of str)."
|
|
165
|
+
),
|
|
166
|
+
"llm.prompt_cache_volatile": (
|
|
167
|
+
"A CacheGuard found a value that changes per request (timestamp, UUID...) in "
|
|
168
|
+
"the cached prompt prefix. Fields: kinds (tuple of str)."
|
|
169
|
+
),
|
|
170
|
+
"chaos.injected": (
|
|
171
|
+
"A python_wrap.chaos rule injected a fault. function is the fault point name. "
|
|
172
|
+
"Fields: kind (str): 'latency', 'exception' or 'result'; point (str); "
|
|
173
|
+
"pattern (str, the matching rule)."
|
|
174
|
+
),
|
|
175
|
+
"agent.run.start": (
|
|
176
|
+
"An agent run (RunGuard / agent_run) began. function is the guard name. "
|
|
177
|
+
"Fields: run_id (str), parent_id (str, or None for a top-level run)."
|
|
178
|
+
),
|
|
179
|
+
"agent.run.step": (
|
|
180
|
+
"A step was admitted into an agent run. function is the guard name. "
|
|
181
|
+
"Fields: run_id (str), step (int, 1-based), kind (str: 'tool', 'llm', ...), "
|
|
182
|
+
"tool (str, the tool or step name)."
|
|
183
|
+
),
|
|
184
|
+
"agent.run.end": (
|
|
185
|
+
"An agent run finished. function is the guard name. Fields: run_id (str), "
|
|
186
|
+
"steps (int), seconds (float), error (str exception class name, or None)."
|
|
187
|
+
),
|
|
188
|
+
"tool.call": (
|
|
189
|
+
"An agent tool is about to run (not a replay or dry run). function is the tool "
|
|
190
|
+
"name. Fields: run_id (str or None)."
|
|
191
|
+
),
|
|
192
|
+
"tool.denied": (
|
|
193
|
+
"A tool call was refused. function is the tool name. Fields: run_id (str or "
|
|
194
|
+
"None), reason (str): 'unknown', 'denied', 'read_only', 'approval_denied' or "
|
|
195
|
+
"'approval_timeout'."
|
|
196
|
+
),
|
|
197
|
+
"tool.replayed": (
|
|
198
|
+
"A tool call matched a stored idempotency key; the stored result was returned "
|
|
199
|
+
"without running. function is the tool name. Fields: run_id (str or None)."
|
|
200
|
+
),
|
|
201
|
+
"tool.dry_run": (
|
|
202
|
+
"A write tool was skipped in a dry run. function is the tool name. "
|
|
203
|
+
"Fields: run_id (str or None)."
|
|
204
|
+
),
|
|
205
|
+
"tool.effect_unknown": (
|
|
206
|
+
"An EffectLedger found a side effect whose outcome is unknown (a crash, a "
|
|
207
|
+
"store failure, a timeout or cancellation, or a lost result). function is the "
|
|
208
|
+
"tool name. Fields: run_id (str or None), reason (str): 'crashed', "
|
|
209
|
+
"'uncertain' or 'result_lost'."
|
|
210
|
+
),
|
|
211
|
+
"tool.effect_resolved": (
|
|
212
|
+
"An EffectLedger's on_unknown hook resolved an unknown effect with a result. "
|
|
213
|
+
"function is the tool name. Fields: run_id (str or None)."
|
|
214
|
+
),
|
|
215
|
+
"mcp.cancelled": (
|
|
216
|
+
"An in-flight MCP tool call was cancelled because the current CancelToken "
|
|
217
|
+
"fired. function is 'mcp:<server>'. No extra fields."
|
|
218
|
+
),
|
|
78
219
|
}
|
|
79
220
|
)
|
|
80
221
|
|