torque-http 0.5.0__tar.gz → 0.7.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.
@@ -0,0 +1,230 @@
1
+ This package is dual-licensed: you may use it under either the MIT license or the Apache
2
+ License 2.0, at your option. Both texts follow.
3
+
4
+ -------------------------------------------------------------------------------
5
+
6
+ MIT License
7
+
8
+ Copyright (c) 2025-2026 The Intelligence Company AB (publ)
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ -------------------------------------------------------------------------------
29
+
30
+ Apache License
31
+ Version 2.0, January 2004
32
+ http://www.apache.org/licenses/
33
+
34
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
35
+
36
+ 1. Definitions.
37
+
38
+ "License" shall mean the terms and conditions for use, reproduction,
39
+ and distribution as defined by Sections 1 through 9 of this document.
40
+
41
+ "Licensor" shall mean the copyright owner or entity authorized by
42
+ the copyright owner that is granting the License.
43
+
44
+ "Legal Entity" shall mean the union of the acting entity and all
45
+ other entities that control, are controlled by, or are under common
46
+ control with that entity. For the purposes of this definition,
47
+ "control" means (i) the power, direct or indirect, to cause the
48
+ direction or management of such entity, whether by contract or
49
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
50
+ outstanding shares, or (iii) beneficial ownership of such entity.
51
+
52
+ "You" (or "Your") shall mean an individual or Legal Entity
53
+ exercising permissions granted by this License.
54
+
55
+ "Source" form shall mean the preferred form for making modifications,
56
+ including but not limited to software source code, documentation
57
+ source, and configuration files.
58
+
59
+ "Object" form shall mean any form resulting from mechanical
60
+ transformation or translation of a Source form, including but
61
+ not limited to compiled object code, generated documentation,
62
+ and conversions to other media types.
63
+
64
+ "Work" shall mean the work of authorship, whether in Source or
65
+ Object form, made available under the License, as indicated by a
66
+ copyright notice that is included in or attached to the work
67
+ (an example is provided in the Appendix below).
68
+
69
+ "Derivative Works" shall mean any work, whether in Source or Object
70
+ form, that is based on (or derived from) the Work and for which the
71
+ editorial revisions, annotations, elaborations, or other modifications
72
+ represent, as a whole, an original work of authorship. For the purposes
73
+ of this License, Derivative Works shall not include works that remain
74
+ separable from, or merely link (or bind by name) to the interfaces of,
75
+ the Work and Derivative Works thereof.
76
+
77
+ "Contribution" shall mean any work of authorship, including
78
+ the original version of the Work and any modifications or additions
79
+ to that Work or Derivative Works thereof, that is intentionally
80
+ submitted to Licensor for inclusion in the Work by the copyright owner
81
+ or by an individual or Legal Entity authorized to submit on behalf of
82
+ the copyright owner. For the purposes of this definition, "submitted"
83
+ means any form of electronic, verbal, or written communication sent
84
+ to the Licensor or its representatives, including but not limited to
85
+ communication on electronic mailing lists, source code control systems,
86
+ and issue tracking systems that are managed by, or on behalf of, the
87
+ Licensor for the purpose of discussing and improving the Work, but
88
+ excluding communication that is conspicuously marked or otherwise
89
+ designated in writing by the copyright owner as "Not a Contribution."
90
+
91
+ "Contributor" shall mean Licensor and any individual or Legal Entity
92
+ on behalf of whom a Contribution has been received by Licensor and
93
+ subsequently incorporated within the Work.
94
+
95
+ 2. Grant of Copyright License. Subject to the terms and conditions of
96
+ this License, each Contributor hereby grants to You a perpetual,
97
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
98
+ copyright license to reproduce, prepare Derivative Works of,
99
+ publicly display, publicly perform, sublicense, and distribute the
100
+ Work and such Derivative Works in Source or Object form.
101
+
102
+ 3. Grant of Patent License. Subject to the terms and conditions of
103
+ this License, each Contributor hereby grants to You a perpetual,
104
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
105
+ (except as stated in this section) patent license to make, have made,
106
+ use, offer to sell, sell, import, and otherwise transfer the Work,
107
+ where such license applies only to those patent claims licensable
108
+ by such Contributor that are necessarily infringed by their
109
+ Contribution(s) alone or by combination of their Contribution(s)
110
+ with the Work to which such Contribution(s) was submitted. If You
111
+ institute patent litigation against any entity (including a
112
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
113
+ or a Contribution incorporated within the Work constitutes direct
114
+ or contributory patent infringement, then any patent licenses
115
+ granted to You under this License for that Work shall terminate
116
+ as of the date such litigation is filed.
117
+
118
+ 4. Redistribution. You may reproduce and distribute copies of the
119
+ Work or Derivative Works thereof in any medium, with or without
120
+ modifications, and in Source or Object form, provided that You
121
+ meet the following conditions:
122
+
123
+ (a) You must give any other recipients of the Work or
124
+ Derivative Works a copy of this License; and
125
+
126
+ (b) You must cause any modified files to carry prominent notices
127
+ stating that You changed the files; and
128
+
129
+ (c) You must retain, in the Source form of any Derivative Works
130
+ that You distribute, all copyright, patent, trademark, and
131
+ attribution notices from the Source form of the Work,
132
+ excluding those notices that do not pertain to any part of
133
+ the Derivative Works; and
134
+
135
+ (d) If the Work includes a "NOTICE" text file as part of its
136
+ distribution, then any Derivative Works that You distribute must
137
+ include a readable copy of the attribution notices contained
138
+ within such NOTICE file, excluding those notices that do not
139
+ pertain to any part of the Derivative Works, in at least one
140
+ of the following places: within a NOTICE text file distributed
141
+ as part of the Derivative Works; within the Source form or
142
+ documentation, if provided along with the Derivative Works; or,
143
+ within a display generated by the Derivative Works, if and
144
+ wherever such third-party notices normally appear. The contents
145
+ of the NOTICE file are for informational purposes only and
146
+ do not modify the License. You may add Your own attribution
147
+ notices within Derivative Works that You distribute, alongside
148
+ or as an addendum to the NOTICE text from the Work, provided
149
+ that such additional attribution notices cannot be construed
150
+ as modifying the License.
151
+
152
+ You may add Your own copyright statement to Your modifications and
153
+ may provide additional or different license terms and conditions
154
+ for use, reproduction, or distribution of Your modifications, or
155
+ for any such Derivative Works as a whole, provided Your use,
156
+ reproduction, and distribution of the Work otherwise complies with
157
+ the conditions stated in this License.
158
+
159
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
160
+ any Contribution intentionally submitted for inclusion in the Work
161
+ by You to the Licensor shall be under the terms and conditions of
162
+ this License, without any additional terms or conditions.
163
+ Notwithstanding the above, nothing herein shall supersede or modify
164
+ the terms of any separate license agreement you may have executed
165
+ with Licensor regarding such Contributions.
166
+
167
+ 6. Trademarks. This License does not grant permission to use the trade
168
+ names, trademarks, service marks, or product names of the Licensor,
169
+ except as required for reasonable and customary use in describing the
170
+ origin of the Work and reproducing the content of the NOTICE file.
171
+
172
+ 7. Disclaimer of Warranty. Unless required by applicable law or
173
+ agreed to in writing, Licensor provides the Work (and each
174
+ Contributor provides its Contributions) on an "AS IS" BASIS,
175
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
176
+ implied, including, without limitation, any warranties or conditions
177
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
178
+ PARTICULAR PURPOSE. You are solely responsible for determining the
179
+ appropriateness of using or redistributing the Work and assume any
180
+ risks associated with Your exercise of permissions under this License.
181
+
182
+ 8. Limitation of Liability. In no event and under no legal theory,
183
+ whether in tort (including negligence), contract, or otherwise,
184
+ unless required by applicable law (such as deliberate and grossly
185
+ negligent acts) or agreed to in writing, shall any Contributor be
186
+ liable to You for damages, including any direct, indirect, special,
187
+ incidental, or consequential damages of any character arising as a
188
+ result of this License or out of the use or inability to use the
189
+ Work (including but not limited to damages for loss of goodwill,
190
+ work stoppage, computer failure or malfunction, or any and all
191
+ other commercial damages or losses), even if such Contributor
192
+ has been advised of the possibility of such damages.
193
+
194
+ 9. Accepting Warranty or Additional Liability. While redistributing
195
+ the Work or Derivative Works thereof, You may choose to offer,
196
+ and charge a fee for, acceptance of support, warranty, indemnity,
197
+ or other liability obligations and/or rights consistent with this
198
+ License. However, in accepting such obligations, You may act only
199
+ on Your own behalf and on Your sole responsibility, not on behalf
200
+ of any other Contributor, and only if You agree to indemnify,
201
+ defend, and hold each Contributor harmless for any liability
202
+ incurred by, or claims asserted against, such Contributor by reason
203
+ of your accepting any such warranty or additional liability.
204
+
205
+ END OF TERMS AND CONDITIONS
206
+
207
+ APPENDIX: How to apply the Apache License to your work.
208
+
209
+ To apply the Apache License to your work, attach the following
210
+ boilerplate notice, with the fields enclosed by brackets "[]"
211
+ replaced with your own identifying information. (Don't include
212
+ the brackets!) The text should be enclosed in the appropriate
213
+ comment syntax for the file format. We also recommend that a
214
+ file or class name and description of purpose be included on the
215
+ same "printed page" as the copyright notice for easier
216
+ identification within third-party archives.
217
+
218
+ Copyright 2025-2026 The Intelligence Company AB (publ)
219
+
220
+ Licensed under the Apache License, Version 2.0 (the "License");
221
+ you may not use this file except in compliance with the License.
222
+ You may obtain a copy of the License at
223
+
224
+ http://www.apache.org/licenses/LICENSE-2.0
225
+
226
+ Unless required by applicable law or agreed to in writing, software
227
+ distributed under the License is distributed on an "AS IS" BASIS,
228
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
229
+ See the License for the specific language governing permissions and
230
+ limitations under the License.
@@ -1,16 +1,16 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: torque-http
3
- Version: 0.5.0
3
+ Version: 0.7.0
4
4
  Summary: Official Python client for Torque — Truespar's in-memory search engine with a Typesense v30.1 compatible API. Zero external dependencies.
5
5
  Project-URL: Homepage, https://truespar.com/torque/docs
6
6
  Project-URL: Documentation, https://truespar.com/torque/docs
7
+ Project-URL: Repository, https://github.com/truespar/torque
7
8
  Author: Truespar
8
- License-Expression: MIT
9
+ License-Expression: MIT OR Apache-2.0
9
10
  License-File: LICENSE
10
11
  Keywords: search,torque,truespar,typesense,vector-search
11
12
  Classifier: Development Status :: 4 - Beta
12
13
  Classifier: Intended Audience :: Developers
13
- Classifier: License :: OSI Approved :: MIT License
14
14
  Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
@@ -22,15 +22,15 @@ Description-Content-Type: text/markdown
22
22
 
23
23
  # torque-http
24
24
 
25
- Official Python client for [Torque](https://truespar.com/torque/docs) — Truespar's in-memory search engine with a Typesense v30.1 compatible API.
25
+ The Python client for [Torque](https://truespar.com/torque/docs), an in-memory search engine with a Typesense-compatible API.
26
26
 
27
- - **Zero external dependencies** — uses only the Python standard library
28
- - **HTTP API** for search, collection management, and document CRUD
29
- - **TCP binary ingest** for high-throughput streaming from databases
30
- - **TQBF file upload** for bulk import
31
- - Multi-node failover with automatic retry
27
+ - Standard library only, no dependencies
28
+ - **HTTP API**: search, collections, documents, keys, aliases
29
+ - **TCP ingest** (`TorqueIngestClient`) for streaming documents
30
+ - **Binary import files** (`TorqueBinaryFileWriter`) for bulk loads
31
+ - Several nodes, with failover and retries
32
32
  - Typed search parameters and response models
33
- - Python 3.10+, MIT licensed
33
+ - Python 3.10+
34
34
 
35
35
  ## Installation
36
36
 
@@ -38,7 +38,7 @@ Official Python client for [Torque](https://truespar.com/torque/docs) — Truesp
38
38
  pip install torque-http
39
39
  ```
40
40
 
41
- ## Quick Start
41
+ ## Quick start
42
42
 
43
43
  ```python
44
44
  from torque_http import TorqueHttpClient, SearchParameters
@@ -60,7 +60,7 @@ params = SearchParameters(
60
60
  results = client.search("products", params)
61
61
  ```
62
62
 
63
- ## Multi-node with failover
63
+ ## Several nodes
64
64
 
65
65
  ```python
66
66
  client = TorqueHttpClient(
@@ -70,7 +70,7 @@ client = TorqueHttpClient(
70
70
  )
71
71
  ```
72
72
 
73
- ## Collection management
73
+ ## Collections and documents
74
74
 
75
75
  ```python
76
76
  schema = {
@@ -88,9 +88,9 @@ client.create_document("products", {
88
88
  })
89
89
  ```
90
90
 
91
- ## High-throughput TCP ingest
91
+ ## TCP ingest
92
92
 
93
- For streaming 100K+ documents, use the binary TCP protocol:
93
+ For large loads, stream over the TCP ingest protocol:
94
94
 
95
95
  ```python
96
96
  from torque_http import TorqueIngestClient, DocumentEncoder
@@ -108,9 +108,9 @@ with TorqueIngestClient() as tcp:
108
108
  tcp.commit()
109
109
  ```
110
110
 
111
- ## TQBF bulk file import
111
+ ## Binary import file
112
112
 
113
- Pre-encode a compressed binary file for maximum throughput:
113
+ Write the documents to a compressed file, then upload it in one request:
114
114
 
115
115
  ```python
116
116
  from torque_http import TorqueBinaryFileWriter, DocumentEncoder
@@ -129,4 +129,4 @@ client.import_binary("products", "data.tqbf")
129
129
 
130
130
  ## License
131
131
 
132
- MIT — see [LICENSE](LICENSE).
132
+ MIT OR Apache-2.0, at your option. See [LICENSE](LICENSE). Copyright 2025-2026 The Intelligence Company AB (publ).
@@ -1,110 +1,110 @@
1
- # torque-http
2
-
3
- Official Python client for [Torque](https://truespar.com/torque/docs) — Truespar's in-memory search engine with a Typesense v30.1 compatible API.
4
-
5
- - **Zero external dependencies** — uses only the Python standard library
6
- - **HTTP API** for search, collection management, and document CRUD
7
- - **TCP binary ingest** for high-throughput streaming from databases
8
- - **TQBF file upload** for bulk import
9
- - Multi-node failover with automatic retry
10
- - Typed search parameters and response models
11
- - Python 3.10+, MIT licensed
12
-
13
- ## Installation
14
-
15
- ```bash
16
- pip install torque-http
17
- ```
18
-
19
- ## Quick Start
20
-
21
- ```python
22
- from torque_http import TorqueHttpClient, SearchParameters
23
-
24
- client = TorqueHttpClient("http://localhost:8108", api_key="your-key")
25
-
26
- # Search
27
- results = client.search("products", q="laptop", query_by="title")
28
- for hit in results.hits:
29
- print(hit.document["title"])
30
-
31
- # Typed parameters
32
- params = SearchParameters(
33
- q="laptop",
34
- query_by="title,description",
35
- filter_by="price:>100",
36
- per_page=20,
37
- )
38
- results = client.search("products", params)
39
- ```
40
-
41
- ## Multi-node with failover
42
-
43
- ```python
44
- client = TorqueHttpClient(
45
- ["http://node1:8108", "http://node2:8108"],
46
- api_key="your-key",
47
- num_retries=5,
48
- )
49
- ```
50
-
51
- ## Collection management
52
-
53
- ```python
54
- schema = {
55
- "name": "products",
56
- "fields": [
57
- {"name": "title", "type": "string"},
58
- {"name": "price", "type": "float", "sort": True},
59
- {"name": "brand", "type": "string", "facet": True},
60
- ],
61
- }
62
- client.create_collection(schema)
63
-
64
- client.create_document("products", {
65
- "id": "1", "title": "Laptop Pro", "price": 1299.99, "brand": "Acme",
66
- })
67
- ```
68
-
69
- ## High-throughput TCP ingest
70
-
71
- For streaming 100K+ documents, use the binary TCP protocol:
72
-
73
- ```python
74
- from torque_http import TorqueIngestClient, DocumentEncoder
75
-
76
- schema = {"fields": [
77
- {"name": "title", "type": "string"},
78
- {"name": "price", "type": "float"},
79
- ]}
80
- encoder = DocumentEncoder(schema)
81
-
82
- with TorqueIngestClient() as tcp:
83
- tcp.connect("localhost", 8109)
84
- tcp.start_ingest("products")
85
- tcp.send_batch(documents, encoder)
86
- tcp.commit()
87
- ```
88
-
89
- ## TQBF bulk file import
90
-
91
- Pre-encode a compressed binary file for maximum throughput:
92
-
93
- ```python
94
- from torque_http import TorqueBinaryFileWriter, DocumentEncoder
95
-
96
- encoder = DocumentEncoder(schema)
97
- with TorqueBinaryFileWriter("data.tqbf", encoder) as writer:
98
- for doc in source:
99
- writer.write(doc)
100
-
101
- client.import_binary("products", "data.tqbf")
102
- ```
103
-
104
- ## Documentation
105
-
106
- - [Torque documentation](https://truespar.com/torque/docs)
107
-
108
- ## License
109
-
110
- MIT — see [LICENSE](LICENSE).
1
+ # torque-http
2
+
3
+ The Python client for [Torque](https://truespar.com/torque/docs), an in-memory search engine with a Typesense-compatible API.
4
+
5
+ - Standard library only, no dependencies
6
+ - **HTTP API**: search, collections, documents, keys, aliases
7
+ - **TCP ingest** (`TorqueIngestClient`) for streaming documents
8
+ - **Binary import files** (`TorqueBinaryFileWriter`) for bulk loads
9
+ - Several nodes, with failover and retries
10
+ - Typed search parameters and response models
11
+ - Python 3.10+
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pip install torque-http
17
+ ```
18
+
19
+ ## Quick start
20
+
21
+ ```python
22
+ from torque_http import TorqueHttpClient, SearchParameters
23
+
24
+ client = TorqueHttpClient("http://localhost:8108", api_key="your-key")
25
+
26
+ # Search
27
+ results = client.search("products", q="laptop", query_by="title")
28
+ for hit in results.hits:
29
+ print(hit.document["title"])
30
+
31
+ # Typed parameters
32
+ params = SearchParameters(
33
+ q="laptop",
34
+ query_by="title,description",
35
+ filter_by="price:>100",
36
+ per_page=20,
37
+ )
38
+ results = client.search("products", params)
39
+ ```
40
+
41
+ ## Several nodes
42
+
43
+ ```python
44
+ client = TorqueHttpClient(
45
+ ["http://node1:8108", "http://node2:8108"],
46
+ api_key="your-key",
47
+ num_retries=5,
48
+ )
49
+ ```
50
+
51
+ ## Collections and documents
52
+
53
+ ```python
54
+ schema = {
55
+ "name": "products",
56
+ "fields": [
57
+ {"name": "title", "type": "string"},
58
+ {"name": "price", "type": "float", "sort": True},
59
+ {"name": "brand", "type": "string", "facet": True},
60
+ ],
61
+ }
62
+ client.create_collection(schema)
63
+
64
+ client.create_document("products", {
65
+ "id": "1", "title": "Laptop Pro", "price": 1299.99, "brand": "Acme",
66
+ })
67
+ ```
68
+
69
+ ## TCP ingest
70
+
71
+ For large loads, stream over the TCP ingest protocol:
72
+
73
+ ```python
74
+ from torque_http import TorqueIngestClient, DocumentEncoder
75
+
76
+ schema = {"fields": [
77
+ {"name": "title", "type": "string"},
78
+ {"name": "price", "type": "float"},
79
+ ]}
80
+ encoder = DocumentEncoder(schema)
81
+
82
+ with TorqueIngestClient() as tcp:
83
+ tcp.connect("localhost", 8109)
84
+ tcp.start_ingest("products")
85
+ tcp.send_batch(documents, encoder)
86
+ tcp.commit()
87
+ ```
88
+
89
+ ## Binary import file
90
+
91
+ Write the documents to a compressed file, then upload it in one request:
92
+
93
+ ```python
94
+ from torque_http import TorqueBinaryFileWriter, DocumentEncoder
95
+
96
+ encoder = DocumentEncoder(schema)
97
+ with TorqueBinaryFileWriter("data.tqbf", encoder) as writer:
98
+ for doc in source:
99
+ writer.write(doc)
100
+
101
+ client.import_binary("products", "data.tqbf")
102
+ ```
103
+
104
+ ## Documentation
105
+
106
+ - [Torque documentation](https://truespar.com/torque/docs)
107
+
108
+ ## License
109
+
110
+ MIT OR Apache-2.0, at your option. See [LICENSE](LICENSE). Copyright 2025-2026 The Intelligence Company AB (publ).
@@ -4,17 +4,17 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "torque-http"
7
- version = "0.5.0"
7
+ version = "0.7.0"
8
8
  description = "Official Python client for Torque — Truespar's in-memory search engine with a Typesense v30.1 compatible API. Zero external dependencies."
9
9
  readme = "README.md"
10
- license = "MIT"
10
+ license = "MIT OR Apache-2.0"
11
+ license-files = ["LICENSE"]
11
12
  requires-python = ">=3.10"
12
13
  authors = [{ name = "Truespar" }]
13
14
  keywords = ["search", "torque", "typesense", "truespar", "vector-search"]
14
15
  classifiers = [
15
16
  "Development Status :: 4 - Beta",
16
17
  "Intended Audience :: Developers",
17
- "License :: OSI Approved :: MIT License",
18
18
  "Programming Language :: Python :: 3.10",
19
19
  "Programming Language :: Python :: 3.11",
20
20
  "Programming Language :: Python :: 3.12",
@@ -26,6 +26,7 @@ classifiers = [
26
26
  [project.urls]
27
27
  Homepage = "https://truespar.com/torque/docs"
28
28
  Documentation = "https://truespar.com/torque/docs"
29
+ Repository = "https://github.com/truespar/torque"
29
30
 
30
31
  [tool.hatch.build.targets.wheel]
31
32
  packages = ["src/torque_http"]
@@ -118,4 +118,4 @@ __all__ = [
118
118
  "TorqueConnectionError",
119
119
  ]
120
120
 
121
- __version__ = "0.5.0"
121
+ __version__ = "0.7.0"
@@ -1,6 +1,6 @@
1
1
  """Torque Python HTTP client — zero external dependencies.
2
2
 
3
- Uses only Python 3.13+ stdlib: http.client, json, ssl, threading.
3
+ Uses only Python 3.10+ stdlib: http.client, json, ssl, threading.
4
4
  Features: connection pooling with keep-alive, multi-node round-robin,
5
5
  configurable retry with exponential backoff, typed error hierarchy.
6
6
  """
@@ -301,14 +301,12 @@ class TorqueHttpClient:
301
301
  """Get server health status.
302
302
 
303
303
  Returns:
304
- HealthResponse with server version and license info.
304
+ HealthResponse with server version.
305
305
  """
306
306
  d = self._get("/health")
307
307
  return HealthResponse(
308
308
  ok=d.get("ok", False),
309
309
  version=d.get("version", ""),
310
- license=d.get("license", {}),
311
- update=d.get("update"),
312
310
  )
313
311
 
314
312
  def stats(self) -> AdminStats:
@@ -813,7 +811,7 @@ class TorqueHttpClient:
813
811
  if params is not None:
814
812
  merged.update(params)
815
813
  merged.update(kwargs)
816
- qs = urlencode({k: v for k, v in merged.items() if v is not None})
814
+ qs = _encode_search_params(merged)
817
815
  d = self._get(f"/collections/{_enc(collection)}/documents/search?{qs}")
818
816
  return _parse_search(d)
819
817
 
@@ -837,7 +835,7 @@ class TorqueHttpClient:
837
835
  if params is not None:
838
836
  merged.update(params)
839
837
  merged.update(kwargs)
840
- qs = urlencode({k: v for k, v in merged.items() if v is not None})
838
+ qs = _encode_search_params(merged)
841
839
  d = self._get(f"/collections/{_enc(collection)}/documents/search?{qs}")
842
840
  return _parse_grouped_search(d)
843
841
 
@@ -866,6 +864,44 @@ class TorqueHttpClient:
866
864
  d = self._post("/multi_search", {"searches": searches})
867
865
  return [_parse_search(r) for r in d.get("results", [])]
868
866
 
867
+ def multi_search_union(
868
+ self,
869
+ searches: list[dict[str, Any]],
870
+ common_params: dict[str, Any] | None = None,
871
+ *,
872
+ page: int | None = None,
873
+ per_page: int | None = None,
874
+ ) -> SearchResult:
875
+ """Execute multiple searches merged into one ranked result set.
876
+
877
+ Uses Typesense v30.1 ``union: true`` — hits from all searches are
878
+ merged and ranked by text_match. Not compatible with ``group_by``
879
+ searches.
880
+
881
+ Args:
882
+ searches: List of search parameter dicts, each with at least
883
+ ``collection`` and ``q`` keys.
884
+ common_params: Optional dict of parameters merged into every
885
+ search. Per-search values override common values.
886
+ page: Page number for the merged result set (1-based).
887
+ per_page: Results per page for the merged result set.
888
+
889
+ Returns:
890
+ A single SearchResult with the merged, ranked hits.
891
+ """
892
+ if common_params:
893
+ searches = [{**common_params, **s} for s in searches]
894
+ path = "/multi_search"
895
+ query: list[str] = []
896
+ if page is not None:
897
+ query.append(f"page={page}")
898
+ if per_page is not None:
899
+ query.append(f"per_page={per_page}")
900
+ if query:
901
+ path += "?" + "&".join(query)
902
+ d = self._post(path, {"searches": searches, "union": True})
903
+ return _parse_search(d)
904
+
869
905
  # ── Aliases ────────────────────────────────────────────────────────
870
906
 
871
907
  def upsert_alias(self, name: str, collection_name: str) -> CollectionAlias:
@@ -1413,6 +1449,15 @@ def _enc(s: str) -> str:
1413
1449
  return quote(s, safe="")
1414
1450
 
1415
1451
 
1452
+ def _encode_search_params(params: dict[str, Any]) -> str:
1453
+ """URL-encode search params, serializing Python bools as true/false."""
1454
+ return urlencode({
1455
+ k: ("true" if v is True else "false" if v is False else v)
1456
+ for k, v in params.items()
1457
+ if v is not None
1458
+ })
1459
+
1460
+
1416
1461
  def _parse_collection(d: dict) -> CollectionResponse:
1417
1462
  return CollectionResponse(
1418
1463
  name=d.get("name", ""),
@@ -171,10 +171,15 @@ class SearchParameters(TypedDict, total=False):
171
171
  facet_by: str
172
172
  max_facet_values: int
173
173
  facet_query: str
174
+ facet_strategy: str
175
+ facet_sample_percent: int
176
+ facet_sample_threshold: int
177
+ facet_return_parent: str
174
178
 
175
179
  # ── Grouping ──────────────────────────────────────────────────────
176
180
  group_by: str
177
181
  group_limit: int
182
+ group_missing_values: bool
178
183
 
179
184
  # ── Pagination ────────────────────────────────────────────────────
180
185
  per_page: int
@@ -191,6 +196,7 @@ class SearchParameters(TypedDict, total=False):
191
196
  highlight_full_fields: str
192
197
  highlight_start_tag: str
193
198
  highlight_end_tag: str
199
+ highlight_affix_num_tokens: int
194
200
  snippet_threshold: int
195
201
 
196
202
  # ── Pinning / hiding ──────────────────────────────────────────────
@@ -200,17 +206,41 @@ class SearchParameters(TypedDict, total=False):
200
206
 
201
207
  # ── Token dropping ────────────────────────────────────────────────
202
208
  drop_tokens_threshold: int
209
+ drop_tokens_mode: str
203
210
  typo_tokens_threshold: int
204
211
 
212
+ # ── Typo tolerance ────────────────────────────────────────────────
213
+ min_len_1typo: int
214
+ min_len_2typo: int
215
+ split_join_tokens: str
216
+ synonym_num_typos: int
217
+ enable_typos_for_numerical_tokens: bool
218
+ enable_typos_for_alpha_numerical_tokens: bool
219
+
220
+ # ── Infix search ──────────────────────────────────────────────────
221
+ infix: str
222
+ max_extra_prefix: int
223
+ max_extra_suffix: int
224
+
205
225
  # ── Performance ───────────────────────────────────────────────────
206
226
  exhaustive_search: bool
207
227
  search_cutoff_ms: int
228
+ max_candidates: int
229
+
230
+ # ── Caching ───────────────────────────────────────────────────────
231
+ use_cache: bool
232
+ cache_ttl: int
233
+
234
+ # ── Validation & toggles ──────────────────────────────────────────
235
+ validate_field_names: bool
236
+ enable_synonyms: bool
208
237
 
209
238
  # ── Preset ────────────────────────────────────────────────────────
210
239
  preset: str
211
240
 
212
- # ── Stopwords ─────────────────────────────────────────────────────
241
+ # ── Stopwords & synonyms ──────────────────────────────────────────
213
242
  stopwords: str
243
+ synonym_sets: str
214
244
 
215
245
  # ── Vector search ─────────────────────────────────────────────────
216
246
  vector_query: str
@@ -289,8 +319,6 @@ class HealthResponse:
289
319
  """Server health response."""
290
320
  ok: bool = False
291
321
  version: str = ""
292
- license: dict[str, Any] = field(default_factory=dict)
293
- update: dict[str, Any] | None = None
294
322
 
295
323
 
296
324
  # ── Admin ────────────────────────────────────────────────────────────────
@@ -15,7 +15,6 @@ from io import BytesIO
15
15
  from dataclasses import dataclass
16
16
  from typing import Any
17
17
 
18
-
19
18
  # ── Protocol Constants ──────────────────────────────────────────────────
20
19
 
21
20
  # Client -> Server message types
@@ -30,7 +29,6 @@ RESP_COMMIT_RESULT = 0x11
30
29
  RESP_ERROR = 0x12
31
30
  RESP_BACKPRESSURE = 0x13
32
31
 
33
-
34
32
  # ── Response Models ─────────────────────────────────────────────────────
35
33
 
36
34
  @dataclass
@@ -38,14 +36,12 @@ class BatchAck:
38
36
  batch_seq: int
39
37
  docs_received: int
40
38
 
41
-
42
39
  @dataclass
43
40
  class CommitResult:
44
41
  success: bool
45
42
  docs_indexed: int
46
43
  build_ms: int
47
44
 
48
-
49
45
  # ── Exceptions ──────────────────────────────────────────────────────────
50
46
 
51
47
  class TorqueProtocolError(Exception):
@@ -53,18 +49,15 @@ class TorqueProtocolError(Exception):
53
49
  super().__init__(f"[code={code}] {message}")
54
50
  self.code = code
55
51
 
56
-
57
52
  class TorqueConnectionError(Exception):
58
53
  pass
59
54
 
60
-
61
55
  # ── Frame Codec ─────────────────────────────────────────────────────────
62
56
 
63
57
  def _write_frame(sock: socket.socket, payload: bytes) -> None:
64
58
  header = struct.pack("!I", len(payload))
65
59
  sock.sendall(header + payload)
66
60
 
67
-
68
61
  def _read_exact(sock: socket.socket, n: int) -> bytes:
69
62
  buf = bytearray()
70
63
  while len(buf) < n:
@@ -74,7 +67,6 @@ def _read_exact(sock: socket.socket, n: int) -> bytes:
74
67
  buf.extend(chunk)
75
68
  return bytes(buf)
76
69
 
77
-
78
70
  def _read_frame(sock: socket.socket) -> bytes:
79
71
  header = _read_exact(sock, 4)
80
72
  length = struct.unpack("!I", header)[0]
@@ -82,7 +74,6 @@ def _read_frame(sock: socket.socket) -> bytes:
82
74
  return b""
83
75
  return _read_exact(sock, length)
84
76
 
85
-
86
77
  # ── Response Decoder ────────────────────────────────────────────────────
87
78
 
88
79
  def _decode_response(data: bytes) -> BatchAck | CommitResult:
@@ -126,7 +117,6 @@ def _decode_response(data: bytes) -> BatchAck | CommitResult:
126
117
  else:
127
118
  raise TorqueProtocolError(0, f"Unknown server message type: 0x{msg_type:02X}")
128
119
 
129
-
130
120
  # ── Document Flattener ─────────────────────────────────────────────────
131
121
 
132
122
  def flatten_document(doc: dict[str, Any]) -> dict[str, Any]:
@@ -140,7 +130,6 @@ def flatten_document(doc: dict[str, Any]) -> dict[str, Any]:
140
130
  """
141
131
  return _flatten_inner(doc, 0)
142
132
 
143
-
144
133
  def _flatten_inner(obj: dict[str, Any], depth: int) -> dict[str, Any]:
145
134
 
146
135
  result: dict[str, Any] = {}
@@ -178,7 +167,6 @@ def _flatten_inner(obj: dict[str, Any], depth: int) -> dict[str, Any]:
178
167
 
179
168
  return result
180
169
 
181
-
182
170
  # ── Document Encoder ────────────────────────────────────────────────────
183
171
 
184
172
  # Type name -> encoder key mapping
@@ -195,7 +183,6 @@ _TYPE_MAP = {
195
183
  "float[]": "float[]",
196
184
  }
197
185
 
198
-
199
186
  class DocumentEncoder:
200
187
  """Encodes Python dicts into Torque binary wire format.
201
188
 
@@ -365,7 +352,6 @@ class DocumentEncoder:
365
352
  for item in arr:
366
353
  buf.write(struct.pack("!f", float(item)))
367
354
 
368
-
369
355
  # ── TCP Ingest Client ───────────────────────────────────────────────────
370
356
 
371
357
  class TorqueIngestClient:
@@ -495,7 +481,6 @@ class TorqueIngestClient:
495
481
  if self._sock is None:
496
482
  raise RuntimeError("Not connected. Call connect() first.")
497
483
 
498
-
499
484
  # ── TQBF Binary File Writer ────────────────────────────────────────────
500
485
 
501
486
  class TorqueBinaryFileWriter:
@@ -512,9 +497,8 @@ class TorqueBinaryFileWriter:
512
497
  [8 bytes] uncompressed_size: u64 (LE) ← v2 only
513
498
  [N bytes] payload: ZLib-compressed concatenated binary documents
514
499
 
515
- The uncompressed_size field lets the server pre-size its decompression
516
- Vec exactly, avoiding doubling-realloc fragmentation that breaks the
517
- silicon unikernel's contiguous bitmap allocator on large imports.
500
+ The uncompressed_size field lets the server size its decompression
501
+ buffer exactly once.
518
502
 
519
503
  The torque server still accepts v1 files (16-byte header, no size field)
520
504
  via the read_to_end fallback, so older clients keep working.
torque_http-0.5.0/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Truespar
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.
File without changes