needlepath 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.
needlepath/__init__.py ADDED
@@ -0,0 +1,137 @@
1
+ """Needlepath — framework-free client for the hosted context-selection service.
2
+
3
+ from needlepath import NeedlepathClient, ContextRecord, TaskSpec
4
+
5
+ client = NeedlepathClient(operating_point="np-2026-07-r2") # key from env
6
+ result = client.select(
7
+ records=[ContextRecord(text=tool_output, kind="tool_result", id="t1")],
8
+ task=TaskSpec(prompt=user_question),
9
+ max_context_tokens=4000,
10
+ )
11
+ context = result.rendered_context if result.applied else my_original_context
12
+
13
+ Three properties this package guarantees, because the framework adapters built
14
+ on it are only as safe as it is:
15
+
16
+ 1. **``select`` never raises.** Timeout, 5xx, a violated contract, an empty
17
+ selection, a stood-down gate — all of them come back as a result with
18
+ ``applied=False``, the error on ``.error``, and a metadata-only summary on
19
+ ``.metadata()``.
20
+ 2. **The operating point is pinned in the constructor**, or construction fails.
21
+ 3. **The 6 MB payload cap is measured client-side**, before the request leaves.
22
+
23
+ The framework integrations live in their own distributions
24
+ (``needlepath-langchain``, ``needlepath-litellm``,
25
+ ``llama-index-postprocessor-needlepath``) so that a framework release can never
26
+ force a release of this package.
27
+ """
28
+
29
+ from .client import (
30
+ DEFAULT_BASE_URL,
31
+ DEFAULT_MAX_RETRIES,
32
+ DEFAULT_TIMEOUT_S,
33
+ HEALTH_PATH,
34
+ MAX_REQUEST_BYTES,
35
+ OPERATING_POINTS_PATH,
36
+ RETRY_STATUSES,
37
+ SELECT_PATH,
38
+ AsyncNeedlepathClient,
39
+ NeedlepathClient,
40
+ build_request,
41
+ classify,
42
+ encode_body,
43
+ new_request_id,
44
+ validate_response_payload,
45
+ )
46
+ from .errors import (
47
+ NeedlepathConfigError,
48
+ NeedlepathContractError,
49
+ NeedlepathError,
50
+ NeedlepathHTTPError,
51
+ NeedlepathPayloadTooLargeError,
52
+ NeedlepathTimeoutError,
53
+ NeedlepathTransportError,
54
+ )
55
+ from .features import WIRE_SHADOW_MODE, wire_shadow_mode_enabled
56
+ from .models import (
57
+ REQUIRED_RESPONSE_FIELDS,
58
+ AdaptiveBudget,
59
+ BudgetSpec,
60
+ ContextRecord,
61
+ ContextRequest,
62
+ ContextResponse,
63
+ GateSummary,
64
+ RecordKind,
65
+ SafetySummary,
66
+ SelectedRecord,
67
+ TaskSpec,
68
+ )
69
+ from .result import BENIGN_REASONS, Reason, SelectionResult, SelectionStats
70
+ from .transport import (
71
+ AsyncTransport,
72
+ HttpResult,
73
+ HttpxAsyncTransport,
74
+ ThreadedAsyncTransport,
75
+ Transport,
76
+ UrllibTransport,
77
+ default_async_transport,
78
+ )
79
+ from .version import __version__
80
+
81
+ __all__ = [
82
+ "__version__",
83
+ # clients
84
+ "NeedlepathClient",
85
+ "AsyncNeedlepathClient",
86
+ # wire types
87
+ "ContextRecord",
88
+ "TaskSpec",
89
+ "BudgetSpec",
90
+ "AdaptiveBudget",
91
+ "ContextRequest",
92
+ "ContextResponse",
93
+ "SelectedRecord",
94
+ "SafetySummary",
95
+ "GateSummary",
96
+ "RecordKind",
97
+ "REQUIRED_RESPONSE_FIELDS",
98
+ # results
99
+ "SelectionResult",
100
+ "SelectionStats",
101
+ "Reason",
102
+ "BENIGN_REASONS",
103
+ # errors
104
+ "NeedlepathError",
105
+ "NeedlepathConfigError",
106
+ "NeedlepathTransportError",
107
+ "NeedlepathTimeoutError",
108
+ "NeedlepathHTTPError",
109
+ "NeedlepathContractError",
110
+ "NeedlepathPayloadTooLargeError",
111
+ # transport seam
112
+ "Transport",
113
+ "AsyncTransport",
114
+ "HttpResult",
115
+ "UrllibTransport",
116
+ "ThreadedAsyncTransport",
117
+ "HttpxAsyncTransport",
118
+ "default_async_transport",
119
+ # helpers
120
+ "build_request",
121
+ "encode_body",
122
+ "classify",
123
+ "validate_response_payload",
124
+ "new_request_id",
125
+ # constants
126
+ "DEFAULT_BASE_URL",
127
+ "SELECT_PATH",
128
+ "HEALTH_PATH",
129
+ "OPERATING_POINTS_PATH",
130
+ "MAX_REQUEST_BYTES",
131
+ "DEFAULT_TIMEOUT_S",
132
+ "DEFAULT_MAX_RETRIES",
133
+ "RETRY_STATUSES",
134
+ # feature flags
135
+ "WIRE_SHADOW_MODE",
136
+ "wire_shadow_mode_enabled",
137
+ ]