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/__init__.py
CHANGED
|
@@ -8,7 +8,14 @@ Testing helpers live in ``python_wrap.testing`` and the event catalogue in
|
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
import logging
|
|
11
|
+
from contextlib import AbstractContextManager
|
|
11
12
|
|
|
13
|
+
from .adaptive import (
|
|
14
|
+
AdaptiveLimiter,
|
|
15
|
+
LoadShed,
|
|
16
|
+
PerKeyLimiter,
|
|
17
|
+
per_key,
|
|
18
|
+
)
|
|
12
19
|
from .aio import (
|
|
13
20
|
RaceFailed,
|
|
14
21
|
amap_iter,
|
|
@@ -17,11 +24,27 @@ from .aio import (
|
|
|
17
24
|
race,
|
|
18
25
|
run_sync,
|
|
19
26
|
)
|
|
27
|
+
from .alerts import (
|
|
28
|
+
WebhookAlerter,
|
|
29
|
+
)
|
|
30
|
+
from .async_cache import (
|
|
31
|
+
AsyncCacheStore,
|
|
32
|
+
AsyncMemoryStore,
|
|
33
|
+
AsyncRedisStore,
|
|
34
|
+
ThreadedStore,
|
|
35
|
+
amemoize,
|
|
36
|
+
)
|
|
20
37
|
from .batching import (
|
|
21
38
|
AsyncBatched,
|
|
22
39
|
Batched,
|
|
23
40
|
batch_calls,
|
|
24
41
|
)
|
|
42
|
+
from .buffering import (
|
|
43
|
+
AsyncBuffered,
|
|
44
|
+
Buffered,
|
|
45
|
+
BufferStats,
|
|
46
|
+
buffered,
|
|
47
|
+
)
|
|
25
48
|
from .bulkhead import (
|
|
26
49
|
Bulkhead,
|
|
27
50
|
Limited,
|
|
@@ -33,9 +56,11 @@ from .caching import (
|
|
|
33
56
|
CacheStore,
|
|
34
57
|
Memoized,
|
|
35
58
|
Once,
|
|
59
|
+
ainvalidate_tags,
|
|
36
60
|
cache,
|
|
37
61
|
cached_property,
|
|
38
62
|
invalidate,
|
|
63
|
+
invalidate_tags,
|
|
39
64
|
memoize,
|
|
40
65
|
once,
|
|
41
66
|
)
|
|
@@ -48,9 +73,14 @@ from .circuit import (
|
|
|
48
73
|
)
|
|
49
74
|
from .concurrency import (
|
|
50
75
|
AsyncDebounced,
|
|
76
|
+
CancelToken,
|
|
51
77
|
Debounced,
|
|
52
78
|
RateLimiter,
|
|
79
|
+
SignalTimerConflictWarning,
|
|
53
80
|
Timeout,
|
|
81
|
+
cancel_requested,
|
|
82
|
+
checkpoint,
|
|
83
|
+
current_token,
|
|
54
84
|
debounce,
|
|
55
85
|
limiter_of,
|
|
56
86
|
rate_limit,
|
|
@@ -65,6 +95,23 @@ from .config import (
|
|
|
65
95
|
get_config,
|
|
66
96
|
reset_config,
|
|
67
97
|
)
|
|
98
|
+
from .coordination import (
|
|
99
|
+
AlreadyRunning,
|
|
100
|
+
AsyncRedisLock,
|
|
101
|
+
AsyncRedisSemaphore,
|
|
102
|
+
Lease,
|
|
103
|
+
LeaseLost,
|
|
104
|
+
LocalLease,
|
|
105
|
+
PgAdvisoryLock,
|
|
106
|
+
RedisLock,
|
|
107
|
+
RedisSemaphore,
|
|
108
|
+
SqlAppLock,
|
|
109
|
+
single_instance,
|
|
110
|
+
)
|
|
111
|
+
from .credentials import (
|
|
112
|
+
Expiring,
|
|
113
|
+
expiring,
|
|
114
|
+
)
|
|
68
115
|
from .deadline import (
|
|
69
116
|
Deadline,
|
|
70
117
|
deadline,
|
|
@@ -90,18 +137,42 @@ from .events import (
|
|
|
90
137
|
listening,
|
|
91
138
|
subscribe,
|
|
92
139
|
)
|
|
140
|
+
from .health import (
|
|
141
|
+
HealthRegistry,
|
|
142
|
+
health,
|
|
143
|
+
)
|
|
93
144
|
from .hedging import (
|
|
94
145
|
hedge,
|
|
95
146
|
)
|
|
147
|
+
from .http import (
|
|
148
|
+
HttpRetryPolicy,
|
|
149
|
+
)
|
|
150
|
+
from .idempotency import (
|
|
151
|
+
MemoryResultStore,
|
|
152
|
+
SqlResultStore,
|
|
153
|
+
idempotent,
|
|
154
|
+
)
|
|
155
|
+
from .lifecycle import (
|
|
156
|
+
ShutdownError,
|
|
157
|
+
ShutdownManager,
|
|
158
|
+
ShutdownReport,
|
|
159
|
+
shutdown,
|
|
160
|
+
)
|
|
161
|
+
from .local_state import (
|
|
162
|
+
SQLiteBreakerState,
|
|
163
|
+
)
|
|
96
164
|
from .logs import (
|
|
97
165
|
DEFAULT_REDACT,
|
|
98
166
|
AuditRecord,
|
|
167
|
+
ContextFilter,
|
|
99
168
|
audit,
|
|
169
|
+
bind,
|
|
100
170
|
current_log_context,
|
|
101
171
|
log_args,
|
|
102
172
|
log_context,
|
|
103
173
|
log_return,
|
|
104
174
|
trace,
|
|
175
|
+
unbind,
|
|
105
176
|
)
|
|
106
177
|
from .metrics import (
|
|
107
178
|
CallStats,
|
|
@@ -113,18 +184,56 @@ from .periodic import (
|
|
|
113
184
|
Periodic,
|
|
114
185
|
periodic,
|
|
115
186
|
)
|
|
187
|
+
from .policies import (
|
|
188
|
+
PolicyRegistry,
|
|
189
|
+
policies,
|
|
190
|
+
resilient,
|
|
191
|
+
)
|
|
116
192
|
from .policy import (
|
|
117
193
|
Policy,
|
|
118
194
|
policy,
|
|
119
195
|
)
|
|
196
|
+
from .predicates import (
|
|
197
|
+
Predicate,
|
|
198
|
+
db_transient,
|
|
199
|
+
error_code,
|
|
200
|
+
in_cause_chain,
|
|
201
|
+
message_contains,
|
|
202
|
+
mysql_transient,
|
|
203
|
+
postgres_transient,
|
|
204
|
+
sqlserver_transient,
|
|
205
|
+
sqlstate,
|
|
206
|
+
)
|
|
207
|
+
from .processing import (
|
|
208
|
+
BatchResult,
|
|
209
|
+
MemoryCheckpoint,
|
|
210
|
+
Outcome,
|
|
211
|
+
RedisCheckpoint,
|
|
212
|
+
aprocess_batches,
|
|
213
|
+
process_batches,
|
|
214
|
+
)
|
|
215
|
+
from .quotas import (
|
|
216
|
+
AsyncRedisWindow,
|
|
217
|
+
Quota,
|
|
218
|
+
QuotaExhausted,
|
|
219
|
+
RedisWindow,
|
|
220
|
+
shared_rate_limit,
|
|
221
|
+
)
|
|
222
|
+
from .redaction import (
|
|
223
|
+
is_sensitive,
|
|
224
|
+
redact,
|
|
225
|
+
)
|
|
120
226
|
from .retry import (
|
|
121
227
|
Attempt,
|
|
228
|
+
AttemptRecord,
|
|
122
229
|
RetryBudget,
|
|
123
230
|
RetryBudgetStats,
|
|
124
231
|
Retrying,
|
|
125
232
|
RetryState,
|
|
126
233
|
RetryStats,
|
|
234
|
+
attempt_history,
|
|
127
235
|
fallback,
|
|
236
|
+
http_status,
|
|
128
237
|
retry,
|
|
129
238
|
retry_after_header,
|
|
130
239
|
retry_on_exception,
|
|
@@ -132,6 +241,13 @@ from .retry import (
|
|
|
132
241
|
retrying,
|
|
133
242
|
suppress,
|
|
134
243
|
)
|
|
244
|
+
from .shared import (
|
|
245
|
+
AsyncRedisBreakerState,
|
|
246
|
+
RedisBreakerState,
|
|
247
|
+
)
|
|
248
|
+
from .slow import (
|
|
249
|
+
timed,
|
|
250
|
+
)
|
|
135
251
|
from .state import (
|
|
136
252
|
INJECTED,
|
|
137
253
|
Transaction,
|
|
@@ -140,6 +256,15 @@ from .state import (
|
|
|
140
256
|
revert_on_failure,
|
|
141
257
|
transactional,
|
|
142
258
|
)
|
|
259
|
+
from .stores import (
|
|
260
|
+
RedisStore,
|
|
261
|
+
)
|
|
262
|
+
from .switches import (
|
|
263
|
+
EnvSource,
|
|
264
|
+
FeatureDisabled,
|
|
265
|
+
RedisSource,
|
|
266
|
+
switch,
|
|
267
|
+
)
|
|
143
268
|
from .timing import (
|
|
144
269
|
BenchmarkResult,
|
|
145
270
|
MemoryRecord,
|
|
@@ -156,7 +281,7 @@ from .validation import (
|
|
|
156
281
|
validate_args,
|
|
157
282
|
)
|
|
158
283
|
|
|
159
|
-
__version__ = "0.
|
|
284
|
+
__version__ = "0.4.0"
|
|
160
285
|
|
|
161
286
|
# A library must never configure logging; this only silences "no handler" warnings.
|
|
162
287
|
logging.getLogger("python_wrap").addHandler(logging.NullHandler())
|
|
@@ -164,74 +289,143 @@ logging.getLogger("python_wrap").addHandler(logging.NullHandler())
|
|
|
164
289
|
__all__ = [
|
|
165
290
|
"DEFAULT_REDACT",
|
|
166
291
|
"INJECTED",
|
|
292
|
+
"AdaptiveLimiter",
|
|
293
|
+
"AlreadyRunning",
|
|
167
294
|
"ArgumentTypeError",
|
|
168
295
|
"AsyncBatched",
|
|
296
|
+
"AsyncBuffered",
|
|
297
|
+
"AsyncCacheStore",
|
|
169
298
|
"AsyncDebounced",
|
|
299
|
+
"AsyncMemoryStore",
|
|
170
300
|
"AsyncPeriodic",
|
|
301
|
+
"AsyncRedisBreakerState",
|
|
302
|
+
"AsyncRedisLock",
|
|
303
|
+
"AsyncRedisSemaphore",
|
|
304
|
+
"AsyncRedisStore",
|
|
305
|
+
"AsyncRedisWindow",
|
|
171
306
|
"Attempt",
|
|
307
|
+
"AttemptRecord",
|
|
172
308
|
"AuditRecord",
|
|
173
309
|
"BatchError",
|
|
310
|
+
"BatchResult",
|
|
174
311
|
"Batched",
|
|
175
312
|
"BenchmarkResult",
|
|
313
|
+
"BufferStats",
|
|
314
|
+
"Buffered",
|
|
176
315
|
"Bulkhead",
|
|
177
316
|
"BulkheadFull",
|
|
178
317
|
"CacheInfo",
|
|
179
318
|
"CacheStore",
|
|
180
319
|
"CachedProperty",
|
|
181
320
|
"CallStats",
|
|
321
|
+
"CancelToken",
|
|
182
322
|
"CircuitBreaker",
|
|
183
323
|
"CircuitOpenError",
|
|
184
324
|
"CircuitProtected",
|
|
185
325
|
"CircuitState",
|
|
186
326
|
"CircuitStats",
|
|
327
|
+
"ContextFilter",
|
|
187
328
|
"Counted",
|
|
188
329
|
"Deadline",
|
|
189
330
|
"Debounced",
|
|
331
|
+
"EnvSource",
|
|
332
|
+
"Expiring",
|
|
333
|
+
"FeatureDisabled",
|
|
334
|
+
"HealthRegistry",
|
|
335
|
+
"HttpRetryPolicy",
|
|
336
|
+
"Lease",
|
|
337
|
+
"LeaseLost",
|
|
190
338
|
"Limited",
|
|
339
|
+
"LoadShed",
|
|
340
|
+
"LocalLease",
|
|
191
341
|
"Memoized",
|
|
342
|
+
"MemoryCheckpoint",
|
|
192
343
|
"MemoryRecord",
|
|
344
|
+
"MemoryResultStore",
|
|
193
345
|
"Once",
|
|
346
|
+
"Outcome",
|
|
347
|
+
"PerKeyLimiter",
|
|
194
348
|
"Periodic",
|
|
349
|
+
"PgAdvisoryLock",
|
|
195
350
|
"Policy",
|
|
351
|
+
"PolicyRegistry",
|
|
352
|
+
"Predicate",
|
|
196
353
|
"PythonWrapError",
|
|
354
|
+
"Quota",
|
|
355
|
+
"QuotaExhausted",
|
|
197
356
|
"RaceFailed",
|
|
198
357
|
"RateLimitExceeded",
|
|
199
358
|
"RateLimiter",
|
|
359
|
+
"RedisBreakerState",
|
|
360
|
+
"RedisCheckpoint",
|
|
361
|
+
"RedisLock",
|
|
362
|
+
"RedisSemaphore",
|
|
363
|
+
"RedisSource",
|
|
364
|
+
"RedisStore",
|
|
365
|
+
"RedisWindow",
|
|
200
366
|
"RetryBudget",
|
|
201
367
|
"RetryBudgetStats",
|
|
202
368
|
"RetryState",
|
|
203
369
|
"RetryStats",
|
|
204
370
|
"Retrying",
|
|
371
|
+
"SQLiteBreakerState",
|
|
372
|
+
"ShutdownError",
|
|
373
|
+
"ShutdownManager",
|
|
374
|
+
"ShutdownReport",
|
|
375
|
+
"SignalTimerConflictWarning",
|
|
376
|
+
"SqlAppLock",
|
|
377
|
+
"SqlResultStore",
|
|
378
|
+
"ThreadedStore",
|
|
205
379
|
"Timeout",
|
|
206
380
|
"TimeoutExpired",
|
|
207
381
|
"TimingRecord",
|
|
208
382
|
"Transaction",
|
|
209
383
|
"ValidationError",
|
|
384
|
+
"WebhookAlerter",
|
|
210
385
|
"__version__",
|
|
386
|
+
"ainvalidate_tags",
|
|
211
387
|
"amap_iter",
|
|
388
|
+
"amemoize",
|
|
389
|
+
"aprocess_batches",
|
|
390
|
+
"attempt_history",
|
|
212
391
|
"audit",
|
|
213
392
|
"batch_calls",
|
|
214
393
|
"benchmark",
|
|
215
394
|
"benchmark_async",
|
|
395
|
+
"bind",
|
|
396
|
+
"buffered",
|
|
216
397
|
"cache",
|
|
217
398
|
"cached_property",
|
|
399
|
+
"cancel_requested",
|
|
218
400
|
"check_type",
|
|
401
|
+
"checkpoint",
|
|
219
402
|
"circuit_breaker",
|
|
220
403
|
"compose",
|
|
221
404
|
"configure",
|
|
222
405
|
"configured",
|
|
223
406
|
"count_calls",
|
|
224
407
|
"current_log_context",
|
|
408
|
+
"current_token",
|
|
225
409
|
"current_transaction",
|
|
410
|
+
"db_transient",
|
|
226
411
|
"deadline",
|
|
227
412
|
"debounce",
|
|
228
413
|
"deprecate",
|
|
414
|
+
"disabled",
|
|
229
415
|
"enforce_types",
|
|
416
|
+
"error_code",
|
|
417
|
+
"expiring",
|
|
230
418
|
"fallback",
|
|
231
419
|
"gather_limit",
|
|
232
420
|
"get_config",
|
|
421
|
+
"health",
|
|
233
422
|
"hedge",
|
|
423
|
+
"http_status",
|
|
424
|
+
"idempotent",
|
|
425
|
+
"in_cause_chain",
|
|
234
426
|
"invalidate",
|
|
427
|
+
"invalidate_tags",
|
|
428
|
+
"is_sensitive",
|
|
235
429
|
"limit_concurrency",
|
|
236
430
|
"limiter_of",
|
|
237
431
|
"listening",
|
|
@@ -241,16 +435,24 @@ __all__ = [
|
|
|
241
435
|
"map_async",
|
|
242
436
|
"measure_memory",
|
|
243
437
|
"memoize",
|
|
438
|
+
"message_contains",
|
|
244
439
|
"mock_data",
|
|
440
|
+
"mysql_transient",
|
|
245
441
|
"no_debug",
|
|
246
442
|
"once",
|
|
443
|
+
"per_key",
|
|
247
444
|
"periodic",
|
|
445
|
+
"policies",
|
|
248
446
|
"policy",
|
|
447
|
+
"postgres_transient",
|
|
448
|
+
"process_batches",
|
|
249
449
|
"profile",
|
|
250
450
|
"race",
|
|
251
451
|
"rate_limit",
|
|
452
|
+
"redact",
|
|
252
453
|
"require_transaction",
|
|
253
454
|
"reset_config",
|
|
455
|
+
"resilient",
|
|
254
456
|
"retry",
|
|
255
457
|
"retry_after_header",
|
|
256
458
|
"retry_on_exception",
|
|
@@ -259,14 +461,159 @@ __all__ = [
|
|
|
259
461
|
"revert_on_failure",
|
|
260
462
|
"run_in_thread",
|
|
261
463
|
"run_sync",
|
|
464
|
+
"shared_rate_limit",
|
|
465
|
+
"shutdown",
|
|
466
|
+
"single_instance",
|
|
262
467
|
"singleflight",
|
|
468
|
+
"sqlserver_transient",
|
|
469
|
+
"sqlstate",
|
|
263
470
|
"subscribe",
|
|
264
471
|
"suppress",
|
|
472
|
+
"switch",
|
|
265
473
|
"throttle",
|
|
474
|
+
"timed",
|
|
266
475
|
"timeout",
|
|
267
476
|
"timing",
|
|
268
477
|
"trace",
|
|
269
478
|
"transactional",
|
|
479
|
+
"unbind",
|
|
270
480
|
"validate_args",
|
|
271
481
|
"wrap_methods",
|
|
272
482
|
]
|
|
483
|
+
|
|
484
|
+
# Effect ledger, call ids and MCP guards (python_wrap.agents, python_wrap.mcp_guard).
|
|
485
|
+
from .mcp_guard import mcp_guard # noqa: E402
|
|
486
|
+
|
|
487
|
+
__all__ += [
|
|
488
|
+
"mcp_guard",
|
|
489
|
+
]
|
|
490
|
+
|
|
491
|
+
# Agent tool-use safety (python_wrap.agents).
|
|
492
|
+
__all__ += []
|
|
493
|
+
|
|
494
|
+
# OpenAI / Anthropic SDK adapters (python_wrap.adapters); no SDK is imported.
|
|
495
|
+
__all__ += []
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
def disabled() -> AbstractContextManager[None]:
|
|
499
|
+
"""Temporarily bypass caches, retry attempts and rate limits; see testing.disabled."""
|
|
500
|
+
from .testing import disabled as scope
|
|
501
|
+
|
|
502
|
+
return scope()
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
# LLM, agent and MCP helpers live in their submodules. The old top-level names keep
|
|
506
|
+
# working (with a DeprecationWarning) until 0.6.0.
|
|
507
|
+
_MOVED: dict[str, str] = {
|
|
508
|
+
"AgentError": "python_wrap.agents",
|
|
509
|
+
"AgentRun": "python_wrap.agents",
|
|
510
|
+
"ApprovalDenied": "python_wrap.agents",
|
|
511
|
+
"ApprovalTimeout": "python_wrap.agents",
|
|
512
|
+
"AsyncRedisTokenWindow": "python_wrap.llm_shared",
|
|
513
|
+
"AuditTape": "python_wrap.genai",
|
|
514
|
+
"Budget": "python_wrap.llm",
|
|
515
|
+
"BudgetBackend": "python_wrap.llm",
|
|
516
|
+
"BudgetExceeded": "python_wrap.llm",
|
|
517
|
+
"CacheGuard": "python_wrap.adapters._sdk",
|
|
518
|
+
"Cassette": "python_wrap.llm_cassette",
|
|
519
|
+
"CassetteError": "python_wrap.llm_cassette",
|
|
520
|
+
"CassetteMiss": "python_wrap.llm_cassette",
|
|
521
|
+
"DryRun": "python_wrap.agents",
|
|
522
|
+
"EffectConflict": "python_wrap.agents",
|
|
523
|
+
"EffectLedger": "python_wrap.agents",
|
|
524
|
+
"EffectRecord": "python_wrap.agents",
|
|
525
|
+
"EffectResolved": "python_wrap.agents",
|
|
526
|
+
"EffectStore": "python_wrap.agents",
|
|
527
|
+
"EffectUnknown": "python_wrap.agents",
|
|
528
|
+
"FakeProvider": "python_wrap.llm_testing",
|
|
529
|
+
"FakeResponse": "python_wrap.llm_testing",
|
|
530
|
+
"FakeStream": "python_wrap.llm_testing",
|
|
531
|
+
"LLMFaults": "python_wrap.llm_testing",
|
|
532
|
+
"LoopDetected": "python_wrap.agents",
|
|
533
|
+
"MCPGuard": "python_wrap.mcp_guard",
|
|
534
|
+
"MemoryEffectStore": "python_wrap.agents",
|
|
535
|
+
"RecordingTransport": "python_wrap.llm_cassette",
|
|
536
|
+
"Redactor": "python_wrap.genai",
|
|
537
|
+
"RedisBudgetBackend": "python_wrap.llm",
|
|
538
|
+
"RedisEffectStore": "python_wrap.agents",
|
|
539
|
+
"RedisTokenWindow": "python_wrap.llm_shared",
|
|
540
|
+
"ReplayMismatch": "python_wrap.genai",
|
|
541
|
+
"ReplayProvider": "python_wrap.genai",
|
|
542
|
+
"ReplayTransport": "python_wrap.llm_cassette",
|
|
543
|
+
"ReplayedError": "python_wrap.genai",
|
|
544
|
+
"ResumableStream": "python_wrap.adapters._sdk",
|
|
545
|
+
"RunBudgetExceeded": "python_wrap.agents",
|
|
546
|
+
"RunCancelled": "python_wrap.agents",
|
|
547
|
+
"RunContext": "python_wrap.genai",
|
|
548
|
+
"RunGuard": "python_wrap.agents",
|
|
549
|
+
"RunTimeout": "python_wrap.agents",
|
|
550
|
+
"SQLiteBudgetBackend": "python_wrap.llm_shared",
|
|
551
|
+
"SQLiteEffectStore": "python_wrap.agents",
|
|
552
|
+
"SQLiteTokenWindow": "python_wrap.llm_shared",
|
|
553
|
+
"SharedTokenWindow": "python_wrap.llm_shared",
|
|
554
|
+
"Spend": "python_wrap.llm",
|
|
555
|
+
"Step": "python_wrap.agents",
|
|
556
|
+
"StepLimitExceeded": "python_wrap.agents",
|
|
557
|
+
"StreamInterrupted": "python_wrap.adapters._sdk",
|
|
558
|
+
"StreamTimeout": "python_wrap.llm",
|
|
559
|
+
"TapeRecord": "python_wrap.genai",
|
|
560
|
+
"TokenRateLimiter": "python_wrap.llm",
|
|
561
|
+
"ToolCall": "python_wrap.agents",
|
|
562
|
+
"ToolNotAllowed": "python_wrap.agents",
|
|
563
|
+
"ToolPolicy": "python_wrap.agents",
|
|
564
|
+
"ToolRegistry": "python_wrap.agents",
|
|
565
|
+
"ToolSpec": "python_wrap.agents",
|
|
566
|
+
"Usage": "python_wrap.llm",
|
|
567
|
+
"ValidationRepairExhausted": "python_wrap.llm_validate",
|
|
568
|
+
"agent_run": "python_wrap.agents",
|
|
569
|
+
"budget": "python_wrap.llm",
|
|
570
|
+
"current_run": "python_wrap.agents",
|
|
571
|
+
"estimate_tokens": "python_wrap.llm",
|
|
572
|
+
"extract_usage": "python_wrap.genai",
|
|
573
|
+
"fake_llm": "python_wrap.llm_testing",
|
|
574
|
+
"fallback_models": "python_wrap.llm",
|
|
575
|
+
"guard_anthropic": "python_wrap.adapters.anthropic",
|
|
576
|
+
"guard_openai": "python_wrap.adapters.openai",
|
|
577
|
+
"instrument": "python_wrap.genai",
|
|
578
|
+
"llm_cache": "python_wrap.llm",
|
|
579
|
+
"llm_retry": "python_wrap.llm",
|
|
580
|
+
"llm_retry_after": "python_wrap.llm",
|
|
581
|
+
"llm_transient": "python_wrap.llm",
|
|
582
|
+
"mcp_breaker": "python_wrap.mcp_guard",
|
|
583
|
+
"no_sdk_retries": "python_wrap.adapters._sdk",
|
|
584
|
+
"parse_rate_limit_headers": "python_wrap.llm_shared",
|
|
585
|
+
"read_usage": "python_wrap.llm",
|
|
586
|
+
"record_step": "python_wrap.agents",
|
|
587
|
+
"replay": "python_wrap.genai",
|
|
588
|
+
"resume_safe": "python_wrap.adapters._sdk",
|
|
589
|
+
"run_context": "python_wrap.genai",
|
|
590
|
+
"stream_timeout": "python_wrap.llm",
|
|
591
|
+
"token_rate_limit": "python_wrap.llm",
|
|
592
|
+
"tool": "python_wrap.agents",
|
|
593
|
+
"tool_call_id": "python_wrap.agents",
|
|
594
|
+
"tool_spec": "python_wrap.agents",
|
|
595
|
+
"traced_llm": "python_wrap.genai",
|
|
596
|
+
"traced_tool": "python_wrap.genai",
|
|
597
|
+
"validated": "python_wrap.llm_validate",
|
|
598
|
+
"with_call_id": "python_wrap.agents",
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
def __getattr__(name: str) -> object:
|
|
603
|
+
module = _MOVED.get(name)
|
|
604
|
+
if module is None:
|
|
605
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
606
|
+
import importlib
|
|
607
|
+
import warnings
|
|
608
|
+
|
|
609
|
+
warnings.warn(
|
|
610
|
+
f"python_wrap.{name} moved: import it from {module} (the top-level name is "
|
|
611
|
+
"removed in 0.6.0)",
|
|
612
|
+
DeprecationWarning,
|
|
613
|
+
stacklevel=2,
|
|
614
|
+
)
|
|
615
|
+
return getattr(importlib.import_module(module), name)
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
def __dir__() -> list[str]:
|
|
619
|
+
return sorted({*globals(), *_MOVED})
|
python_wrap/__main__.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Command line entry point: ``python -m python_wrap <command> ...``.
|
|
2
|
+
|
|
3
|
+
Commands:
|
|
4
|
+
|
|
5
|
+
* ``doctor TARGET...``: explain resilience stacks and flag risky combinations
|
|
6
|
+
(see `python_wrap.doctor`).
|
|
7
|
+
* ``migrate PATH...``: rewrite tenacity/backoff decorators to python-wrap
|
|
8
|
+
(see `python_wrap.migrate`).
|
|
9
|
+
* ``api [SYMBOL | search WORDS...] [--json]``: the public API index
|
|
10
|
+
(see `python_wrap.introspect`).
|
|
11
|
+
* ``recipe NEED...``: which API solves a plain-language need.
|
|
12
|
+
* ``guide``: how to use python-wrap correctly (for people and coding agents).
|
|
13
|
+
* ``mcp``: a read-only Model Context Protocol server over stdio (see `python_wrap.mcp`).
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import sys
|
|
19
|
+
from collections.abc import Sequence
|
|
20
|
+
|
|
21
|
+
_USAGE = "usage: python -m python_wrap {doctor,migrate,api,recipe,guide,mcp} ..."
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
25
|
+
"""Dispatch to a subcommand and return its exit status."""
|
|
26
|
+
args = list(sys.argv[1:] if argv is None else argv)
|
|
27
|
+
if not args or args[0] in {"-h", "--help"}:
|
|
28
|
+
print(_USAGE)
|
|
29
|
+
return 0 if args else 2
|
|
30
|
+
command, rest = args[0], args[1:]
|
|
31
|
+
if command == "doctor":
|
|
32
|
+
from python_wrap.doctor import main as doctor
|
|
33
|
+
|
|
34
|
+
return doctor(rest)
|
|
35
|
+
if command == "migrate":
|
|
36
|
+
from python_wrap.migrate import main as migrate
|
|
37
|
+
|
|
38
|
+
return migrate(rest)
|
|
39
|
+
if command in {"api", "recipe", "guide"}:
|
|
40
|
+
from python_wrap import introspect
|
|
41
|
+
|
|
42
|
+
handler = {
|
|
43
|
+
"api": introspect.api_main,
|
|
44
|
+
"recipe": introspect.recipe_main,
|
|
45
|
+
"guide": introspect.guide_main,
|
|
46
|
+
}[command]
|
|
47
|
+
return handler(rest)
|
|
48
|
+
if command == "mcp":
|
|
49
|
+
from python_wrap.mcp import main as mcp
|
|
50
|
+
|
|
51
|
+
return mcp(rest)
|
|
52
|
+
print(f"unknown command {command!r}\n{_USAGE}", file=sys.stderr)
|
|
53
|
+
return 2
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
if __name__ == "__main__":
|
|
57
|
+
raise SystemExit(main())
|