3tears-search 0.34.0__tar.gz

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 (71) hide show
  1. 3tears_search-0.34.0/.gitignore +250 -0
  2. 3tears_search-0.34.0/LICENSE +21 -0
  3. 3tears_search-0.34.0/PKG-INFO +158 -0
  4. 3tears_search-0.34.0/README.md +132 -0
  5. 3tears_search-0.34.0/pyproject.toml +48 -0
  6. 3tears_search-0.34.0/src/threetears/search/__init__.py +14 -0
  7. 3tears_search-0.34.0/src/threetears/search/adapters/__init__.py +20 -0
  8. 3tears_search-0.34.0/src/threetears/search/adapters/_common.py +236 -0
  9. 3tears_search-0.34.0/src/threetears/search/adapters/searxng.py +1469 -0
  10. 3tears_search-0.34.0/src/threetears/search/adapters/tavily.py +1342 -0
  11. 3tears_search-0.34.0/src/threetears/search/aggregate.py +255 -0
  12. 3tears_search-0.34.0/src/threetears/search/bind.py +326 -0
  13. 3tears_search-0.34.0/src/threetears/search/call.py +588 -0
  14. 3tears_search-0.34.0/src/threetears/search/contracts/__init__.py +177 -0
  15. 3tears_search-0.34.0/src/threetears/search/contracts/_base.py +60 -0
  16. 3tears_search-0.34.0/src/threetears/search/contracts/_canonical.py +101 -0
  17. 3tears_search-0.34.0/src/threetears/search/contracts/budget.py +147 -0
  18. 3tears_search-0.34.0/src/threetears/search/contracts/candidate.py +151 -0
  19. 3tears_search-0.34.0/src/threetears/search/contracts/capabilities.py +237 -0
  20. 3tears_search-0.34.0/src/threetears/search/contracts/corpus.py +173 -0
  21. 3tears_search-0.34.0/src/threetears/search/contracts/criteria.py +297 -0
  22. 3tears_search-0.34.0/src/threetears/search/contracts/errors.py +361 -0
  23. 3tears_search-0.34.0/src/threetears/search/contracts/facets.py +86 -0
  24. 3tears_search-0.34.0/src/threetears/search/contracts/fidelity.py +29 -0
  25. 3tears_search-0.34.0/src/threetears/search/contracts/limiter.py +114 -0
  26. 3tears_search-0.34.0/src/threetears/search/contracts/metadata.py +136 -0
  27. 3tears_search-0.34.0/src/threetears/search/contracts/provenance.py +70 -0
  28. 3tears_search-0.34.0/src/threetears/search/contracts/provider.py +98 -0
  29. 3tears_search-0.34.0/src/threetears/search/contracts/ranker.py +64 -0
  30. 3tears_search-0.34.0/src/threetears/search/contracts/request.py +80 -0
  31. 3tears_search-0.34.0/src/threetears/search/contracts/scores.py +77 -0
  32. 3tears_search-0.34.0/src/threetears/search/contracts/shortlist.py +45 -0
  33. 3tears_search-0.34.0/src/threetears/search/contracts/spend.py +103 -0
  34. 3tears_search-0.34.0/src/threetears/search/contracts/transport.py +299 -0
  35. 3tears_search-0.34.0/src/threetears/search/extract.py +525 -0
  36. 3tears_search-0.34.0/src/threetears/search/limiter.py +373 -0
  37. 3tears_search-0.34.0/src/threetears/search/py.typed +0 -0
  38. 3tears_search-0.34.0/src/threetears/search/select.py +432 -0
  39. 3tears_search-0.34.0/src/threetears/search/standalone.py +1138 -0
  40. 3tears_search-0.34.0/src/threetears/search/testing/__init__.py +39 -0
  41. 3tears_search-0.34.0/src/threetears/search/testing/conformance.py +307 -0
  42. 3tears_search-0.34.0/src/threetears/search/testing/fakes.py +271 -0
  43. 3tears_search-0.34.0/src/threetears/search/testing/http_server.py +163 -0
  44. 3tears_search-0.34.0/tests/__init__.py +0 -0
  45. 3tears_search-0.34.0/tests/_search_instances.py +211 -0
  46. 3tears_search-0.34.0/tests/_searxng_payloads.py +141 -0
  47. 3tears_search-0.34.0/tests/_tavily_payloads.py +102 -0
  48. 3tears_search-0.34.0/tests/conftest.py +18 -0
  49. 3tears_search-0.34.0/tests/test_aggregate.py +375 -0
  50. 3tears_search-0.34.0/tests/test_bind.py +378 -0
  51. 3tears_search-0.34.0/tests/test_call.py +319 -0
  52. 3tears_search-0.34.0/tests/test_call_wiring.py +629 -0
  53. 3tears_search-0.34.0/tests/test_canonical_serialization.py +98 -0
  54. 3tears_search-0.34.0/tests/test_capabilities.py +86 -0
  55. 3tears_search-0.34.0/tests/test_conditional_revalidation.py +356 -0
  56. 3tears_search-0.34.0/tests/test_conformance_searxng.py +52 -0
  57. 3tears_search-0.34.0/tests/test_conformance_tavily.py +55 -0
  58. 3tears_search-0.34.0/tests/test_contract_discipline.py +320 -0
  59. 3tears_search-0.34.0/tests/test_egress_independence.py +215 -0
  60. 3tears_search-0.34.0/tests/test_embedded_smoke.py +282 -0
  61. 3tears_search-0.34.0/tests/test_extract.py +503 -0
  62. 3tears_search-0.34.0/tests/test_import_cost.py +216 -0
  63. 3tears_search-0.34.0/tests/test_limiter.py +411 -0
  64. 3tears_search-0.34.0/tests/test_package_boundaries.py +136 -0
  65. 3tears_search-0.34.0/tests/test_ports.py +452 -0
  66. 3tears_search-0.34.0/tests/test_searxng_adapter.py +873 -0
  67. 3tears_search-0.34.0/tests/test_searxng_live_scoring.py +140 -0
  68. 3tears_search-0.34.0/tests/test_select.py +358 -0
  69. 3tears_search-0.34.0/tests/test_standalone.py +852 -0
  70. 3tears_search-0.34.0/tests/test_tavily_adapter.py +926 -0
  71. 3tears_search-0.34.0/tests/test_wire_roundtrip.py +142 -0
@@ -0,0 +1,250 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ # Anchored: these name top-level build output. Unanchored, `lib/` matches at ANY depth --
18
+ # it swallowed a vendored `.../pako/lib/` tree, and hatchling reads this file with its own
19
+ # matcher that does NOT honour `!` re-inclusion, so the miss reached built artifacts.
20
+ /lib/
21
+ /lib64/
22
+ parts/
23
+ sdist/
24
+ var/
25
+ wheels/
26
+ share/python-wheels/
27
+ *.egg-info/
28
+ .installed.cfg
29
+ *.egg
30
+ MANIFEST
31
+
32
+ # PyInstaller
33
+ # Usually these files are written by a python script from a template
34
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
35
+ *.manifest
36
+ *.spec
37
+
38
+ # Installer logs
39
+ pip-log.txt
40
+ pip-delete-this-directory.txt
41
+
42
+ # Unit test / coverage reports
43
+ htmlcov/
44
+ .tox/
45
+ .nox/
46
+ .coverage
47
+ .coverage.*
48
+ .cache
49
+ nosetests.xml
50
+ coverage.xml
51
+ *.cover
52
+ *.py.cover
53
+ .hypothesis/
54
+ .pytest_cache/
55
+ cover/
56
+
57
+ # Translations
58
+ *.mo
59
+ *.pot
60
+
61
+ # Django stuff:
62
+ *.log
63
+ local_settings.py
64
+ db.sqlite3
65
+ db.sqlite3-journal
66
+
67
+ # Flask stuff:
68
+ instance/
69
+ .webassets-cache
70
+
71
+ # Scrapy stuff:
72
+ .scrapy
73
+
74
+ # Sphinx documentation
75
+ docs/_build/
76
+
77
+ # PyBuilder
78
+ .pybuilder/
79
+ target/
80
+
81
+ # Jupyter Notebook
82
+ .ipynb_checkpoints
83
+
84
+ # IPython
85
+ profile_default/
86
+ ipython_config.py
87
+
88
+ # pyenv
89
+ # For a library or package, you might want to ignore these files since the code is
90
+ # intended to run in multiple environments; otherwise, check them in:
91
+ # .python-version
92
+
93
+ # pipenv
94
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
96
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
97
+ # install all needed dependencies.
98
+ #Pipfile.lock
99
+
100
+ # UV
101
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
102
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
103
+ # commonly ignored for libraries.
104
+ #uv.lock
105
+
106
+ # poetry
107
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
108
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
109
+ # commonly ignored for libraries.
110
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
111
+ #poetry.lock
112
+ #poetry.toml
113
+
114
+ # pdm
115
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
116
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
117
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
118
+ #pdm.lock
119
+ #pdm.toml
120
+ .pdm-python
121
+ .pdm-build/
122
+
123
+ # pixi
124
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
125
+ #pixi.lock
126
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
127
+ # in the .venv directory. It is recommended not to include this directory in version control.
128
+ .pixi
129
+
130
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
131
+ __pypackages__/
132
+
133
+ # Celery stuff
134
+ celerybeat-schedule
135
+ celerybeat.pid
136
+
137
+ # SageMath parsed files
138
+ *.sage.py
139
+
140
+ # Environments
141
+ .env
142
+ .envrc
143
+ .venv
144
+ env/
145
+ venv/
146
+ ENV/
147
+ env.bak/
148
+ venv.bak/
149
+
150
+ # Spyder project settings
151
+ .spyderproject
152
+ .spyproject
153
+
154
+ # Rope project settings
155
+ .ropeproject
156
+
157
+ # mkdocs documentation
158
+ /site
159
+
160
+ # mypy
161
+ .mypy_cache/
162
+ .dmypy.json
163
+ dmypy.json
164
+
165
+ # Pyre type checker
166
+ .pyre/
167
+
168
+ # pytype static type analyzer
169
+ .pytype/
170
+
171
+ # Cython debug symbols
172
+ cython_debug/
173
+
174
+ # PyCharm
175
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
176
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
177
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
178
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
179
+ #.idea/
180
+
181
+ # Abstra
182
+ # Abstra is an AI-powered process automation framework.
183
+ # Ignore directories containing user credentials, local state, and settings.
184
+ # Learn more at https://abstra.io/docs
185
+ .abstra/
186
+
187
+ # Visual Studio Code
188
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
189
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
190
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
191
+ # you could uncomment the following to ignore the entire vscode folder
192
+ # .vscode/
193
+
194
+ # Ruff stuff:
195
+ .ruff_cache/
196
+
197
+ # PyPI configuration file
198
+ .pypirc
199
+
200
+ # Cursor
201
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
202
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
203
+ # refer to https://docs.cursor.com/context/ignore-files
204
+ .cursorignore
205
+ .cursorindexingignore
206
+
207
+ # Marimo
208
+ marimo/_static/
209
+ marimo/_lsp/
210
+ __marimo__/
211
+
212
+ # Claude Code local state
213
+ # .claude/* rather than .claude/ so the one file below can be re-included:
214
+ # git never descends into an excluded DIRECTORY, so a negation inside one is
215
+ # silently dead. Excluding the contents instead leaves the directory readable.
216
+ .claude/*
217
+ # Prawduct install reference. Committed on purpose: it is what enables the
218
+ # plugin for anyone who clones this repo. Without it the governance hooks run
219
+ # only on a machine that already has prawduct installed, and a new developer
220
+ # gets none of them.
221
+ !.claude/settings.json
222
+
223
+ # prawduct session evidence (local governance artifacts, never shipped)
224
+ .prawduct/
225
+
226
+ # macOS folder metadata
227
+ .DS_Store
228
+
229
+
230
+ # Prawduct session files
231
+ .claude/settings.local.json
232
+ .prawduct/.bug-inbox
233
+ .prawduct/.critic-active
234
+ .prawduct/.critic-findings.json
235
+ .prawduct/.critic-partials/
236
+ .prawduct/.critic-partials-archive/
237
+ .prawduct/.governance-ledger.jsonl
238
+ .prawduct/.handoff-notes.md
239
+ .prawduct/.test-evidence.json
240
+ .prawduct/.pr-reviews/
241
+ .prawduct/.session-base-tree
242
+ .prawduct/.session-git-baseline
243
+ .prawduct/.session-handoff.md
244
+ .prawduct/.session-reflected
245
+ .prawduct/.session-start
246
+ .prawduct/.subagent-briefing.md
247
+ .prawduct/.gates-waived
248
+ .prawduct/.advisories.json
249
+ .prawduct/.work-model-index.json
250
+ .prawduct/reflections.md
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mark Pace
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,158 @@
1
+ Metadata-Version: 2.5
2
+ Name: 3tears-search
3
+ Version: 0.34.0
4
+ Summary: Provider-agnostic web and media search for the 3tears family: contracts, adapters, and the staged pipeline
5
+ Project-URL: Repository, https://github.com/pacepace/3tears
6
+ Author: pace
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Framework :: AsyncIO
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Classifier: Typing :: Typed
17
+ Requires-Python: >=3.14
18
+ Requires-Dist: 3tears-media-contracts<0.35.0,>=0.34.0
19
+ Requires-Dist: 3tears-observe<0.35.0,>=0.34.0
20
+ Requires-Dist: pydantic>=2.0
21
+ Provides-Extra: extract
22
+ Requires-Dist: trafilatura>=2.0.0; extra == 'extract'
23
+ Provides-Extra: standalone
24
+ Requires-Dist: httpx>=0.27; extra == 'standalone'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # 3tears-search
28
+
29
+ Provider-agnostic web and media search for the 3tears family.
30
+
31
+ The authority for everything in this package is
32
+ [`docs/search-spec.md`](../../docs/search-spec.md) (decisions D1-D28), with
33
+ requirement IDs (`SR-*`, `G*`, `P*`) defined in
34
+ [`docs/search-requirements.md`](../../docs/search-requirements.md).
35
+
36
+ ## Layout
37
+
38
+ ```
39
+ threetears/search/
40
+ contracts/ # the leaf within the leaf -- types, protocols, errors, keys
41
+ adapters/
42
+ searxng.py # one provider's API, over the injected transport
43
+ call.py # a query → one candidate set, bounded and negotiated
44
+ bind.py # prose for a model + the metadata projection
45
+ standalone.py # bare-httpx transport [standalone] -- the sanctioned path (D19)
46
+ testing/ # the shared provider-conformance suite + declared doubles
47
+ ```
48
+
49
+ Layer names (Adapter, Call, Bind, …) are module vocabulary and never type
50
+ names, so a later re-cut of the layers stays cheap.
51
+
52
+ `contracts/` is the lingua franca every layer and every consumer speaks:
53
+
54
+ - `SearchRequest` and the open criteria vocabulary (typed constructors for
55
+ well-known criteria, namespaced keys for everything else), with per-criterion
56
+ dispositions (`pushdown | local | unsatisfied | ignored-unknown`).
57
+ - `Candidate` -- the carrier-neutral result core: identity, locators,
58
+ provenance, named provenanced scores (never a single `score` field, D1),
59
+ fidelity available/achieved, an optional content slot, and additive facets
60
+ keyed by the `media-contracts` vocabulary.
61
+ - `Spend` -- every resource a call consumed: money (Decimal), wall-clock,
62
+ call count, weighted provider units, bytes.
63
+ - The typed error taxonomy (SR-J1), every error carrying `Spend` (SR-E3).
64
+ Zero results is a success value, not an error (SR-J2).
65
+ - `SearchTransport` -- the injected transport seam (SR-N1, P9). A thin
66
+ host-side adapter over `threetears.core.http_client.TracedHttpClient`
67
+ satisfies it structurally; this package never imports core.
68
+ - `SEARCH_RESULTS_METADATA_KEY` and the versioned metadata projection (D13,
69
+ D22).
70
+ - `ProviderCapabilities` -- what a provider can express, declared and
71
+ queryable so a consumer branches before sending rather than after failing
72
+ (SR-B4), following the `3tears-models` capability-metadata pattern.
73
+ - `SearchProvider` -- the provider seam Call depends on and the conformance
74
+ suite parametrizes over.
75
+ - Canonical serialization of request/parameter types -- one canonical form
76
+ consumed by both the D26 replay key and eval run identity (SR-F1).
77
+
78
+ ## Using it
79
+
80
+ ```python
81
+ import asyncio
82
+
83
+ from threetears.search.adapters.searxng import SearxngAdapter
84
+ from threetears.search.bind import bind_search
85
+ from threetears.search.contracts import Criterion, SearchRequest
86
+ from threetears.search.standalone import StandaloneTransport # or your own
87
+
88
+
89
+ async def main() -> None:
90
+ adapter = SearxngAdapter(
91
+ base_url="https://searx.internal.example", # deployment config, never env
92
+ transport=StandaloneTransport(allow_private_addresses=True),
93
+ provider_instance="searxng-main",
94
+ )
95
+ rendered = await bind_search(
96
+ SearchRequest(query="capybara habitat range", criteria=(Criterion.max_results(5),)),
97
+ provider=adapter,
98
+ )
99
+ print(rendered.content) # prose for a model
100
+ print(rendered.metadata["search_results"]["candidates"]) # structure for a program
101
+
102
+
103
+ asyncio.run(main())
104
+ ```
105
+
106
+ `bind_search` never raises: a typed failure arrives as a failed
107
+ `RenderedSearch` carrying its spend under the same metadata key (D10). Callers
108
+ that want the exception go through `threetears.search.call.search` instead.
109
+
110
+ Budgets and pacing pass through the same entry point: hand `bind_search` (or
111
+ `search`) a `budget=` implementing `BudgetPort`, a `limiter=` such as
112
+ `threetears.search.limiter.InProcessRateLimiter` -- construct **one per
113
+ process** and share it, or pacing paces nothing -- and the `egress=` name your
114
+ transport actually exits by (D8, D20). A budget refusal or pacing denial
115
+ renders as a failed result like any other typed failure; omitting the ports
116
+ means no budget is consulted and no pacing applies.
117
+
118
+ Hosts that already have `threetears.core` should inject a thin adapter over
119
+ `TracedHttpClient` rather than take the `[standalone]` extra -- it brings
120
+ timeouts, retry, circuit-breaking and spans for free.
121
+
122
+ ## Provider conformance
123
+
124
+ `threetears.search.testing` ships the suite every adapter passes -- contract
125
+ shape, spend on failure, error taxonomy, disposition honesty,
126
+ zero-results-is-success (SR-O5). It imports no test framework, so a consumer
127
+ can run it against its own wiring:
128
+
129
+ ```python
130
+ from threetears.search.testing import ProviderConformanceCase, ProviderConformanceSuite
131
+
132
+
133
+ class TestMyProviderConformance(ProviderConformanceSuite):
134
+ case = ProviderConformanceCase(...)
135
+ ```
136
+
137
+ ## Not here yet
138
+
139
+ `aggregate.py`, `extract.py`, `select.py`, `limiter.py` and `replay.py` are
140
+ later phases of `docs/search-spec.md` §7. Budget-port consultation and pacing
141
+ are marked seams inside `call.py`: the port types are Phase 1 PR 2, and a
142
+ placeholder protocol would only be a second vocabulary to migrate off.
143
+
144
+ ## Import-cleanliness
145
+
146
+ Importing `threetears.search.contracts` pulls nothing beyond stdlib, pydantic,
147
+ and `3tears-media-contracts`. Nothing in this package imports
148
+ `threetears.core`, `threetears.agent.*`, langchain, or NATS. Nothing reads
149
+ environment variables -- the host passes base URLs, secret references, and
150
+ transport (SR-K1).
151
+
152
+ `standalone.py` is the only module that imports `httpx`, and nothing in the
153
+ package imports `standalone` at module level: the extra stays opt-in, and a
154
+ host that injects its own transport never installs it. Both facts are pinned
155
+ by `tests/test_package_boundaries.py`, and the module's path is the D19
156
+ widening of the no-bespoke-client norm in
157
+ `tests/enforcement/test_no_bespoke_reuse.py` -- a sanctioned transport, with no
158
+ exemption filed.
@@ -0,0 +1,132 @@
1
+ # 3tears-search
2
+
3
+ Provider-agnostic web and media search for the 3tears family.
4
+
5
+ The authority for everything in this package is
6
+ [`docs/search-spec.md`](../../docs/search-spec.md) (decisions D1-D28), with
7
+ requirement IDs (`SR-*`, `G*`, `P*`) defined in
8
+ [`docs/search-requirements.md`](../../docs/search-requirements.md).
9
+
10
+ ## Layout
11
+
12
+ ```
13
+ threetears/search/
14
+ contracts/ # the leaf within the leaf -- types, protocols, errors, keys
15
+ adapters/
16
+ searxng.py # one provider's API, over the injected transport
17
+ call.py # a query → one candidate set, bounded and negotiated
18
+ bind.py # prose for a model + the metadata projection
19
+ standalone.py # bare-httpx transport [standalone] -- the sanctioned path (D19)
20
+ testing/ # the shared provider-conformance suite + declared doubles
21
+ ```
22
+
23
+ Layer names (Adapter, Call, Bind, …) are module vocabulary and never type
24
+ names, so a later re-cut of the layers stays cheap.
25
+
26
+ `contracts/` is the lingua franca every layer and every consumer speaks:
27
+
28
+ - `SearchRequest` and the open criteria vocabulary (typed constructors for
29
+ well-known criteria, namespaced keys for everything else), with per-criterion
30
+ dispositions (`pushdown | local | unsatisfied | ignored-unknown`).
31
+ - `Candidate` -- the carrier-neutral result core: identity, locators,
32
+ provenance, named provenanced scores (never a single `score` field, D1),
33
+ fidelity available/achieved, an optional content slot, and additive facets
34
+ keyed by the `media-contracts` vocabulary.
35
+ - `Spend` -- every resource a call consumed: money (Decimal), wall-clock,
36
+ call count, weighted provider units, bytes.
37
+ - The typed error taxonomy (SR-J1), every error carrying `Spend` (SR-E3).
38
+ Zero results is a success value, not an error (SR-J2).
39
+ - `SearchTransport` -- the injected transport seam (SR-N1, P9). A thin
40
+ host-side adapter over `threetears.core.http_client.TracedHttpClient`
41
+ satisfies it structurally; this package never imports core.
42
+ - `SEARCH_RESULTS_METADATA_KEY` and the versioned metadata projection (D13,
43
+ D22).
44
+ - `ProviderCapabilities` -- what a provider can express, declared and
45
+ queryable so a consumer branches before sending rather than after failing
46
+ (SR-B4), following the `3tears-models` capability-metadata pattern.
47
+ - `SearchProvider` -- the provider seam Call depends on and the conformance
48
+ suite parametrizes over.
49
+ - Canonical serialization of request/parameter types -- one canonical form
50
+ consumed by both the D26 replay key and eval run identity (SR-F1).
51
+
52
+ ## Using it
53
+
54
+ ```python
55
+ import asyncio
56
+
57
+ from threetears.search.adapters.searxng import SearxngAdapter
58
+ from threetears.search.bind import bind_search
59
+ from threetears.search.contracts import Criterion, SearchRequest
60
+ from threetears.search.standalone import StandaloneTransport # or your own
61
+
62
+
63
+ async def main() -> None:
64
+ adapter = SearxngAdapter(
65
+ base_url="https://searx.internal.example", # deployment config, never env
66
+ transport=StandaloneTransport(allow_private_addresses=True),
67
+ provider_instance="searxng-main",
68
+ )
69
+ rendered = await bind_search(
70
+ SearchRequest(query="capybara habitat range", criteria=(Criterion.max_results(5),)),
71
+ provider=adapter,
72
+ )
73
+ print(rendered.content) # prose for a model
74
+ print(rendered.metadata["search_results"]["candidates"]) # structure for a program
75
+
76
+
77
+ asyncio.run(main())
78
+ ```
79
+
80
+ `bind_search` never raises: a typed failure arrives as a failed
81
+ `RenderedSearch` carrying its spend under the same metadata key (D10). Callers
82
+ that want the exception go through `threetears.search.call.search` instead.
83
+
84
+ Budgets and pacing pass through the same entry point: hand `bind_search` (or
85
+ `search`) a `budget=` implementing `BudgetPort`, a `limiter=` such as
86
+ `threetears.search.limiter.InProcessRateLimiter` -- construct **one per
87
+ process** and share it, or pacing paces nothing -- and the `egress=` name your
88
+ transport actually exits by (D8, D20). A budget refusal or pacing denial
89
+ renders as a failed result like any other typed failure; omitting the ports
90
+ means no budget is consulted and no pacing applies.
91
+
92
+ Hosts that already have `threetears.core` should inject a thin adapter over
93
+ `TracedHttpClient` rather than take the `[standalone]` extra -- it brings
94
+ timeouts, retry, circuit-breaking and spans for free.
95
+
96
+ ## Provider conformance
97
+
98
+ `threetears.search.testing` ships the suite every adapter passes -- contract
99
+ shape, spend on failure, error taxonomy, disposition honesty,
100
+ zero-results-is-success (SR-O5). It imports no test framework, so a consumer
101
+ can run it against its own wiring:
102
+
103
+ ```python
104
+ from threetears.search.testing import ProviderConformanceCase, ProviderConformanceSuite
105
+
106
+
107
+ class TestMyProviderConformance(ProviderConformanceSuite):
108
+ case = ProviderConformanceCase(...)
109
+ ```
110
+
111
+ ## Not here yet
112
+
113
+ `aggregate.py`, `extract.py`, `select.py`, `limiter.py` and `replay.py` are
114
+ later phases of `docs/search-spec.md` §7. Budget-port consultation and pacing
115
+ are marked seams inside `call.py`: the port types are Phase 1 PR 2, and a
116
+ placeholder protocol would only be a second vocabulary to migrate off.
117
+
118
+ ## Import-cleanliness
119
+
120
+ Importing `threetears.search.contracts` pulls nothing beyond stdlib, pydantic,
121
+ and `3tears-media-contracts`. Nothing in this package imports
122
+ `threetears.core`, `threetears.agent.*`, langchain, or NATS. Nothing reads
123
+ environment variables -- the host passes base URLs, secret references, and
124
+ transport (SR-K1).
125
+
126
+ `standalone.py` is the only module that imports `httpx`, and nothing in the
127
+ package imports `standalone` at module level: the extra stays opt-in, and a
128
+ host that injects its own transport never installs it. Both facts are pinned
129
+ by `tests/test_package_boundaries.py`, and the module's path is the D19
130
+ widening of the no-bespoke-client norm in
131
+ `tests/enforcement/test_no_bespoke_reuse.py` -- a sanctioned transport, with no
132
+ exemption filed.
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "3tears-search"
7
+ version = "0.34.0"
8
+ description = "Provider-agnostic web and media search for the 3tears family: contracts, adapters, and the staged pipeline"
9
+ readme = "README.md"
10
+ requires-python = ">=3.14"
11
+ authors = [{name = "pace"}]
12
+ license = "MIT"
13
+ license-files = ["LICENSE"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Framework :: AsyncIO",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.14",
20
+ "Topic :: Internet :: WWW/HTTP :: Indexing/Search",
21
+ "Topic :: Software Development :: Libraries",
22
+ "Typing :: Typed",
23
+ ]
24
+ # D24's permitted leaf floor, exactly: pydantic plus the two dependency-free
25
+ # family leaves. Provider adapters are pure logic over the injected transport
26
+ # and ship in the base package; anything with weight rides an extra.
27
+ dependencies = [
28
+ "3tears-media-contracts>=0.34.0,<0.35.0",
29
+ "3tears-observe>=0.34.0,<0.35.0",
30
+ "pydantic>=2.0",
31
+ ]
32
+
33
+ [project.optional-dependencies]
34
+ # the bare-httpx SearchTransport implementation, for hosts that do not inject
35
+ # their own transport (embedded consumers without core). D24 / D19.
36
+ standalone = ["httpx>=0.27"]
37
+ # Extract's HTML-to-text path. D24.
38
+ extract = ["trafilatura>=2.0.0"]
39
+
40
+ [project.urls]
41
+ Repository = "https://github.com/pacepace/3tears"
42
+
43
+ [tool.hatch.build.targets.wheel]
44
+ packages = ["src/threetears"]
45
+
46
+ [tool.uv.sources]
47
+ 3tears-media-contracts = { workspace = true }
48
+ 3tears-observe = { workspace = true }
@@ -0,0 +1,14 @@
1
+ """Provider-agnostic web and media search for the 3tears family.
2
+
3
+ The buildable authority for this package is ``docs/search-spec.md`` (decisions
4
+ D1-D28); requirement IDs cited in docstrings (``SR-*``, ``G*``, ``P*``) are
5
+ defined in ``docs/search-requirements.md``.
6
+
7
+ The public lingua franca lives in :mod:`threetears.search.contracts` -- the
8
+ leaf within the leaf. This top-level ``__init__`` deliberately imports nothing:
9
+ importing ``threetears.search.contracts`` executes this module first, and the
10
+ contracts module is required to pull nothing beyond stdlib, pydantic, and
11
+ ``3tears-media-contracts`` (search-spec.md section 2).
12
+ """
13
+
14
+ from __future__ import annotations
@@ -0,0 +1,20 @@
1
+ """Provider adapters -- one provider's API each, over the injected transport.
2
+
3
+ Adapters ship in the base package rather than behind extras: they are pure
4
+ logic over an injected
5
+ :class:`~threetears.search.contracts.transport.SearchTransport` and weigh
6
+ nothing (D24). Extras carry *weight*, and an adapter has none -- it opens no
7
+ client, imports no HTTP library, and reads no environment.
8
+
9
+ Importing an adapter module registers its capability declaration
10
+ (:func:`threetears.search.contracts.register_capabilities`), following the
11
+ ``3tears-models`` precedent: a consumer can then ask what SearXNG can
12
+ express without constructing one, which would need a base URL and a
13
+ transport it may not have yet.
14
+
15
+ This ``__init__`` imports nothing. Adapters are chosen by name -- a host
16
+ that speaks to SearXNG should not pay to import Tavily's declaration, and a
17
+ package-level fan-in would make that impossible.
18
+ """
19
+
20
+ from __future__ import annotations