srxy 1.0.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.
srxy-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daniel Illescas Romero
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.
srxy-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,235 @@
1
+ Metadata-Version: 2.4
2
+ Name: srxy
3
+ Version: 1.0.0
4
+ Summary: Composable Python search with per-field match strategies and a Q expression DSL
5
+ License: MIT
6
+ Requires-Python: >=3.11
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: jellyfish>=1.2
10
+ Requires-Dist: openpyxl>=3.1
11
+ Requires-Dist: pypdf>=6.0
12
+ Requires-Dist: python-docx>=1.2
13
+ Requires-Dist: python-pptx>=1.0
14
+ Requires-Dist: rapidfuzz>=3.14
15
+ Provides-Extra: semantic
16
+ Requires-Dist: sentence-transformers>=5.0; extra == "semantic"
17
+ Provides-Extra: dev
18
+ Requires-Dist: basedpyright>=1.39; extra == "dev"
19
+ Requires-Dist: pytest>=9.0; extra == "dev"
20
+ Requires-Dist: pytest-cov>=7.0; extra == "dev"
21
+ Requires-Dist: ruff>=0.15; extra == "dev"
22
+ Provides-Extra: uploader
23
+ Requires-Dist: build>=1.5; extra == "uploader"
24
+ Requires-Dist: twine>=6.0; extra == "uploader"
25
+ Dynamic: license-file
26
+
27
+ # Srxy
28
+
29
+ **Smart, composable search for Python — and your filesystem.**
30
+
31
+ Pass any list of objects (dicts, dataclasses, Pydantic models) and find what you mean, not just what you typed. Fuzzy, phonetic, and composite matching out of the box. Search files by name or content from Python or the terminal.
32
+
33
+ ```bash
34
+ pip install srxy
35
+ ```
36
+
37
+ ---
38
+
39
+ ## Why Srxy?
40
+
41
+ | | |
42
+ |---|---|
43
+ | **Magic search** | One function call. Auto-discovers fields, blends matchers, ranks by score. |
44
+ | **Field search + AND/OR** | Per-field strategies with a fluent `Q` DSL — combine conditions with `&` and `\|`. |
45
+ | **File search + CLI** | Search paths by file name and/or content. Same smart matching, plus a `srxy` command. |
46
+
47
+ ---
48
+
49
+ ## Magic search
50
+
51
+ The fastest path to good results. `magic_search` auto-discovers fields from your items, runs composite matching on each, and keeps the best score (OR semantics). Typos, phonetic near-misses, and partial matches are handled for you.
52
+
53
+ ```python
54
+ from srxy import magic_search
55
+
56
+ items = [
57
+ {"name": "salt"},
58
+ {"name": "salty"},
59
+ {"name": "salad"},
60
+ ]
61
+
62
+ # Match across specific fields
63
+ results = magic_search(items, "salat", fields=["name"])
64
+ print(results[0].item["name"]) # salad
65
+ print(results[0].score)
66
+
67
+ # Or search every discoverable field (default)
68
+ results = magic_search(items, "salat")
69
+ ```
70
+
71
+ Works with dicts, dataclasses, and Pydantic models. Default threshold is `0.25`; tune it when you need stricter or looser matches.
72
+
73
+ ---
74
+
75
+ ## Field search with AND / OR
76
+
77
+ When you need precision, use `search` with the `Q` expression DSL. Pick a match strategy per field, then wire them together with boolean logic.
78
+
79
+ ```python
80
+ from srxy import search, Q, FieldConfig, MatchType
81
+
82
+ # OR — match if any field scores well
83
+ search(items, "salat", where=Q.composite("name") | Q.contains("tags"))
84
+
85
+ # AND — every branch must clear the threshold
86
+ search(items, "spatial", where=Q.all(Q.composite("name"), Q.exact("status")))
87
+
88
+ # Nested — (sku OR barcode) AND label
89
+ search(
90
+ items,
91
+ "ABC-123",
92
+ where=Q.any(Q.exact("sku"), Q.exact("barcode")) & Q.exact("label"),
93
+ )
94
+ ```
95
+
96
+ Boolean scoring: `OR` uses `max(child scores)`, `AND` uses `min(child scores)`.
97
+
98
+ Prefer explicit config over the DSL? Pass a list of `FieldConfig` instead:
99
+
100
+ ```python
101
+ search(
102
+ people,
103
+ "engineer",
104
+ fields=[
105
+ FieldConfig("role", MatchType.EXACT, weight=2.0),
106
+ FieldConfig("name", MatchType.CONTAINS, weight=1.0),
107
+ ],
108
+ threshold=0.5,
109
+ )
110
+ ```
111
+
112
+ ---
113
+
114
+ ## File search
115
+
116
+ Search filesystem paths by **file name**, **file content**, or both — no ML required. Directories are walked recursively. By default, dot-prefixed hidden entries and noise folders (`__pycache__`, `node_modules`) are skipped. Content search scores each line and returns matching line numbers.
117
+
118
+ Supported content formats: plain text, `.pdf`, `.docx`, `.xlsx`, and `.pptx` (text extracted automatically).
119
+
120
+ ```python
121
+ from pathlib import Path
122
+ from srxy import magic_file_search
123
+
124
+ results = magic_file_search(Path("./src"), "registry", threshold=0.3)
125
+ for result in results:
126
+ print(result.path, result.score, result.breakdown)
127
+ for line in result.lines:
128
+ print(f" line {line.line_number}: {line.text}")
129
+
130
+ # Include hidden directories and files (e.g. .git)
131
+ results = magic_file_search(Path("."), "token", skip_hidden_folders=False)
132
+
133
+ # Include noise directories (e.g. __pycache__, node_modules)
134
+ results = magic_file_search(Path("."), "token", skip_noise_folders=False)
135
+
136
+ # Search everywhere — disable both skip flags
137
+ results = magic_file_search(
138
+ Path("."),
139
+ "token",
140
+ skip_hidden_folders=False,
141
+ skip_noise_folders=False,
142
+ )
143
+ ```
144
+
145
+ ### CLI
146
+
147
+ Search from the terminal after install:
148
+
149
+ ```bash
150
+ # Search names and contents (grouped output)
151
+ srxy registry ./src
152
+
153
+ # Content only — shows line numbers
154
+ srxy revenue ./docs --content-only
155
+
156
+ # Flat, pipe-friendly output
157
+ srxy token ./src --format flat
158
+
159
+ # JSON for scripting
160
+ srxy budget . --json
161
+
162
+ # Search hidden directories and files (e.g. .git)
163
+ srxy token . --include-hidden
164
+
165
+ # Search noise directories (e.g. __pycache__, node_modules)
166
+ srxy token . --include-noise
167
+
168
+ # Search everywhere
169
+ srxy token . --include-hidden --include-noise
170
+ ```
171
+
172
+ Options: `--names-only`, `--content-only`, `--include-hidden`, `--include-noise`, `--threshold`, `--max-file-size`, `--max-line-matches`, `--semantic` (opt-in ML). Exit codes: `0` matches found, `1` no matches, `2` usage/path error.
173
+
174
+ ---
175
+
176
+ ## Match types
177
+
178
+ | Type | Behavior |
179
+ |------|----------|
180
+ | `EXACT` | Case-insensitive full string equality |
181
+ | `CONTAINS` | Substring match |
182
+ | `PARTIAL` | Prefix or suffix match |
183
+ | `FUZZY` | Character-level similarity (rapidfuzz) |
184
+ | `PHONETIC` | Sounds-alike (metaphone, soundex, NYSIIS with graduated scoring) |
185
+ | `SEMANTIC` | Meaning similarity (optional; see below) |
186
+ | `COMPOSITE` | Weighted blend of available atomic matchers (default smart mode) |
187
+
188
+ Default composite weights: fuzzy 35%, semantic 20%, partial 15%, phonetic 12%, contains 10%, exact 8%. When semantic is disabled, composite skips it and renormalizes the remaining weights. Override per field via `composite_weights` on `Q.composite(...)` or `FieldConfig`.
189
+
190
+ ---
191
+
192
+ ## Semantic matching (optional)
193
+
194
+ Semantic search is **off by default**. Opt in when you need meaning-based similarity:
195
+
196
+ ```bash
197
+ export SRXY_SEMANTIC=1
198
+ pip install 'srxy[semantic]'
199
+ ```
200
+
201
+ With `SRXY_SEMANTIC=1`, composite matching includes semantic similarity. Explicit `Q.semantic(...)` or `MatchType.SEMANTIC` raises a clear error if semantic is not enabled.
202
+
203
+ Default model: `sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2` (downloaded from Hugging Face on first use). For a local cache:
204
+
205
+ ```bash
206
+ ./scripts/download_semantic_model.sh
207
+ export SRXY_SEMANTIC_MODEL_PATH=~/.cache/srxy/semantic-model
208
+ ```
209
+
210
+ Core dependencies (always installed): `rapidfuzz` and `jellyfish` (phonetic matching).
211
+
212
+ ---
213
+
214
+ ## Development
215
+
216
+ ```bash
217
+ python -m venv .venv
218
+ source .venv/bin/activate
219
+ pip install -e ".[dev,semantic]"
220
+ ./scripts/quality/checks.sh --fix
221
+ ./scripts/quality/checks.sh
222
+ ```
223
+
224
+ Quality gate: Ruff → ShellCheck/shfmt → basedpyright → pip-audit → build → pytest.
225
+
226
+ - **Local** (`./scripts/quality/checks.sh`): runs all tests (unit + integration).
227
+ - **CI**: runs only `pytest -m unit` (fast tests; no semantic model required).
228
+
229
+ Integration tests (requires `pip install -e ".[semantic]"` and `SRXY_SEMANTIC=1`, set automatically in `tests/integration/conftest.py`):
230
+
231
+ ```bash
232
+ pytest -m integration
233
+ ```
234
+
235
+ Integration tests load a curated news-style corpus from `tests/fixtures/search_corpus.json` and measure top-k hit rates.
srxy-1.0.0/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # Srxy
2
+
3
+ **Smart, composable search for Python — and your filesystem.**
4
+
5
+ Pass any list of objects (dicts, dataclasses, Pydantic models) and find what you mean, not just what you typed. Fuzzy, phonetic, and composite matching out of the box. Search files by name or content from Python or the terminal.
6
+
7
+ ```bash
8
+ pip install srxy
9
+ ```
10
+
11
+ ---
12
+
13
+ ## Why Srxy?
14
+
15
+ | | |
16
+ |---|---|
17
+ | **Magic search** | One function call. Auto-discovers fields, blends matchers, ranks by score. |
18
+ | **Field search + AND/OR** | Per-field strategies with a fluent `Q` DSL — combine conditions with `&` and `\|`. |
19
+ | **File search + CLI** | Search paths by file name and/or content. Same smart matching, plus a `srxy` command. |
20
+
21
+ ---
22
+
23
+ ## Magic search
24
+
25
+ The fastest path to good results. `magic_search` auto-discovers fields from your items, runs composite matching on each, and keeps the best score (OR semantics). Typos, phonetic near-misses, and partial matches are handled for you.
26
+
27
+ ```python
28
+ from srxy import magic_search
29
+
30
+ items = [
31
+ {"name": "salt"},
32
+ {"name": "salty"},
33
+ {"name": "salad"},
34
+ ]
35
+
36
+ # Match across specific fields
37
+ results = magic_search(items, "salat", fields=["name"])
38
+ print(results[0].item["name"]) # salad
39
+ print(results[0].score)
40
+
41
+ # Or search every discoverable field (default)
42
+ results = magic_search(items, "salat")
43
+ ```
44
+
45
+ Works with dicts, dataclasses, and Pydantic models. Default threshold is `0.25`; tune it when you need stricter or looser matches.
46
+
47
+ ---
48
+
49
+ ## Field search with AND / OR
50
+
51
+ When you need precision, use `search` with the `Q` expression DSL. Pick a match strategy per field, then wire them together with boolean logic.
52
+
53
+ ```python
54
+ from srxy import search, Q, FieldConfig, MatchType
55
+
56
+ # OR — match if any field scores well
57
+ search(items, "salat", where=Q.composite("name") | Q.contains("tags"))
58
+
59
+ # AND — every branch must clear the threshold
60
+ search(items, "spatial", where=Q.all(Q.composite("name"), Q.exact("status")))
61
+
62
+ # Nested — (sku OR barcode) AND label
63
+ search(
64
+ items,
65
+ "ABC-123",
66
+ where=Q.any(Q.exact("sku"), Q.exact("barcode")) & Q.exact("label"),
67
+ )
68
+ ```
69
+
70
+ Boolean scoring: `OR` uses `max(child scores)`, `AND` uses `min(child scores)`.
71
+
72
+ Prefer explicit config over the DSL? Pass a list of `FieldConfig` instead:
73
+
74
+ ```python
75
+ search(
76
+ people,
77
+ "engineer",
78
+ fields=[
79
+ FieldConfig("role", MatchType.EXACT, weight=2.0),
80
+ FieldConfig("name", MatchType.CONTAINS, weight=1.0),
81
+ ],
82
+ threshold=0.5,
83
+ )
84
+ ```
85
+
86
+ ---
87
+
88
+ ## File search
89
+
90
+ Search filesystem paths by **file name**, **file content**, or both — no ML required. Directories are walked recursively. By default, dot-prefixed hidden entries and noise folders (`__pycache__`, `node_modules`) are skipped. Content search scores each line and returns matching line numbers.
91
+
92
+ Supported content formats: plain text, `.pdf`, `.docx`, `.xlsx`, and `.pptx` (text extracted automatically).
93
+
94
+ ```python
95
+ from pathlib import Path
96
+ from srxy import magic_file_search
97
+
98
+ results = magic_file_search(Path("./src"), "registry", threshold=0.3)
99
+ for result in results:
100
+ print(result.path, result.score, result.breakdown)
101
+ for line in result.lines:
102
+ print(f" line {line.line_number}: {line.text}")
103
+
104
+ # Include hidden directories and files (e.g. .git)
105
+ results = magic_file_search(Path("."), "token", skip_hidden_folders=False)
106
+
107
+ # Include noise directories (e.g. __pycache__, node_modules)
108
+ results = magic_file_search(Path("."), "token", skip_noise_folders=False)
109
+
110
+ # Search everywhere — disable both skip flags
111
+ results = magic_file_search(
112
+ Path("."),
113
+ "token",
114
+ skip_hidden_folders=False,
115
+ skip_noise_folders=False,
116
+ )
117
+ ```
118
+
119
+ ### CLI
120
+
121
+ Search from the terminal after install:
122
+
123
+ ```bash
124
+ # Search names and contents (grouped output)
125
+ srxy registry ./src
126
+
127
+ # Content only — shows line numbers
128
+ srxy revenue ./docs --content-only
129
+
130
+ # Flat, pipe-friendly output
131
+ srxy token ./src --format flat
132
+
133
+ # JSON for scripting
134
+ srxy budget . --json
135
+
136
+ # Search hidden directories and files (e.g. .git)
137
+ srxy token . --include-hidden
138
+
139
+ # Search noise directories (e.g. __pycache__, node_modules)
140
+ srxy token . --include-noise
141
+
142
+ # Search everywhere
143
+ srxy token . --include-hidden --include-noise
144
+ ```
145
+
146
+ Options: `--names-only`, `--content-only`, `--include-hidden`, `--include-noise`, `--threshold`, `--max-file-size`, `--max-line-matches`, `--semantic` (opt-in ML). Exit codes: `0` matches found, `1` no matches, `2` usage/path error.
147
+
148
+ ---
149
+
150
+ ## Match types
151
+
152
+ | Type | Behavior |
153
+ |------|----------|
154
+ | `EXACT` | Case-insensitive full string equality |
155
+ | `CONTAINS` | Substring match |
156
+ | `PARTIAL` | Prefix or suffix match |
157
+ | `FUZZY` | Character-level similarity (rapidfuzz) |
158
+ | `PHONETIC` | Sounds-alike (metaphone, soundex, NYSIIS with graduated scoring) |
159
+ | `SEMANTIC` | Meaning similarity (optional; see below) |
160
+ | `COMPOSITE` | Weighted blend of available atomic matchers (default smart mode) |
161
+
162
+ Default composite weights: fuzzy 35%, semantic 20%, partial 15%, phonetic 12%, contains 10%, exact 8%. When semantic is disabled, composite skips it and renormalizes the remaining weights. Override per field via `composite_weights` on `Q.composite(...)` or `FieldConfig`.
163
+
164
+ ---
165
+
166
+ ## Semantic matching (optional)
167
+
168
+ Semantic search is **off by default**. Opt in when you need meaning-based similarity:
169
+
170
+ ```bash
171
+ export SRXY_SEMANTIC=1
172
+ pip install 'srxy[semantic]'
173
+ ```
174
+
175
+ With `SRXY_SEMANTIC=1`, composite matching includes semantic similarity. Explicit `Q.semantic(...)` or `MatchType.SEMANTIC` raises a clear error if semantic is not enabled.
176
+
177
+ Default model: `sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2` (downloaded from Hugging Face on first use). For a local cache:
178
+
179
+ ```bash
180
+ ./scripts/download_semantic_model.sh
181
+ export SRXY_SEMANTIC_MODEL_PATH=~/.cache/srxy/semantic-model
182
+ ```
183
+
184
+ Core dependencies (always installed): `rapidfuzz` and `jellyfish` (phonetic matching).
185
+
186
+ ---
187
+
188
+ ## Development
189
+
190
+ ```bash
191
+ python -m venv .venv
192
+ source .venv/bin/activate
193
+ pip install -e ".[dev,semantic]"
194
+ ./scripts/quality/checks.sh --fix
195
+ ./scripts/quality/checks.sh
196
+ ```
197
+
198
+ Quality gate: Ruff → ShellCheck/shfmt → basedpyright → pip-audit → build → pytest.
199
+
200
+ - **Local** (`./scripts/quality/checks.sh`): runs all tests (unit + integration).
201
+ - **CI**: runs only `pytest -m unit` (fast tests; no semantic model required).
202
+
203
+ Integration tests (requires `pip install -e ".[semantic]"` and `SRXY_SEMANTIC=1`, set automatically in `tests/integration/conftest.py`):
204
+
205
+ ```bash
206
+ pytest -m integration
207
+ ```
208
+
209
+ Integration tests load a curated news-style corpus from `tests/fixtures/search_corpus.json` and measure top-k hit rates.
@@ -0,0 +1,93 @@
1
+ [project]
2
+ name = "srxy"
3
+ version = "1.0.0"
4
+ description = "Composable Python search with per-field match strategies and a Q expression DSL"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = { text = "MIT" }
8
+ dependencies = [
9
+ "jellyfish>=1.2",
10
+ "openpyxl>=3.1",
11
+ "pypdf>=6.0",
12
+ "python-docx>=1.2",
13
+ "python-pptx>=1.0",
14
+ "rapidfuzz>=3.14",
15
+ ]
16
+
17
+ [project.optional-dependencies]
18
+ semantic = [
19
+ "sentence-transformers>=5.0",
20
+ ]
21
+ dev = [
22
+ "basedpyright>=1.39",
23
+ "pytest>=9.0",
24
+ "pytest-cov>=7.0",
25
+ "ruff>=0.15",
26
+ ]
27
+ uploader = [
28
+ "build>=1.5",
29
+ "twine>=6.0",
30
+ ]
31
+
32
+ [build-system]
33
+ requires = ["setuptools>=82"]
34
+ build-backend = "setuptools.build_meta"
35
+
36
+ [project.scripts]
37
+ srxy = "srxy.cli:main"
38
+
39
+ [tool.setuptools.packages.find]
40
+ where = ["src"]
41
+
42
+ [tool.pytest.ini_options]
43
+ testpaths = ["tests"]
44
+ addopts = "-v --tb=short"
45
+ pythonpath = ["."]
46
+ markers = [
47
+ "unit: fast isolated tests",
48
+ "integration: tests using real models and fixture datasets",
49
+ ]
50
+
51
+ [tool.ruff]
52
+ line-length = 120
53
+ target-version = "py311"
54
+ src = ["src", "tests"]
55
+
56
+ [tool.ruff.format]
57
+ indent-style = "tab"
58
+
59
+ [tool.ruff.lint]
60
+ select = ["F", "I", "E", "S", "B"]
61
+ fixable = ["ALL"]
62
+ ignore = ["E501"]
63
+
64
+ [tool.ruff.lint.isort]
65
+ combine-as-imports = true
66
+ lines-after-imports = 2
67
+
68
+ [tool.ruff.lint.per-file-ignores]
69
+ "scripts/**" = ["S603", "S607"]
70
+ "tests/**" = ["S101"]
71
+
72
+ [tool.basedpyright]
73
+ typeCheckingMode = "strict"
74
+ include = ["src", "tests"]
75
+ pythonVersion = "3.11"
76
+ venvPath = "."
77
+ venv = ".venv"
78
+ extraPaths = ["src"]
79
+ reportMissingTypeStubs = false
80
+ reportUnknownMemberType = false
81
+ reportUnknownLambdaType = false
82
+ reportUnknownVariableType = false
83
+ reportUnknownArgumentType = false
84
+ reportUnknownParameterType = false
85
+ reportAttributeAccessIssue = false
86
+ executionEnvironments = [
87
+ { root = "src" },
88
+ { root = "tests", extraPaths = ["src", "."] },
89
+ ]
90
+
91
+ [tool.coverage.run]
92
+ source = ["srxy"]
93
+ omit = ["tests/*"]
srxy-1.0.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,15 @@
1
+ from srxy.core import magic_search, search
2
+ from srxy.dsl import Q
3
+ from srxy.file_search import magic_file_search
4
+ from srxy.models import FieldConfig, MatchType, SearchResult
5
+
6
+
7
+ __all__ = [
8
+ "FieldConfig",
9
+ "MatchType",
10
+ "magic_file_search",
11
+ "magic_search",
12
+ "Q",
13
+ "SearchResult",
14
+ "search",
15
+ ]