torque-http 0.5.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.
- torque_http-0.5.0/.gitignore +3 -0
- torque_http-0.5.0/LICENSE +21 -0
- torque_http-0.5.0/PKG-INFO +132 -0
- torque_http-0.5.0/README.md +110 -0
- torque_http-0.5.0/pyproject.toml +34 -0
- torque_http-0.5.0/src/torque_http/__init__.py +121 -0
- torque_http-0.5.0/src/torque_http/client.py +1471 -0
- torque_http-0.5.0/src/torque_http/exceptions.py +96 -0
- torque_http-0.5.0/src/torque_http/models.py +302 -0
- torque_http-0.5.0/src/torque_http/py.typed +0 -0
- torque_http-0.5.0/src/torque_http/tcp.py +575 -0
- torque_http-0.5.0/tests/test_client.py +165 -0
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: torque-http
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Official Python client for Torque — Truespar's in-memory search engine with a Typesense v30.1 compatible API. Zero external dependencies.
|
|
5
|
+
Project-URL: Homepage, https://truespar.com/torque/docs
|
|
6
|
+
Project-URL: Documentation, https://truespar.com/torque/docs
|
|
7
|
+
Author: Truespar
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: search,torque,truespar,typesense,vector-search
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Database :: Front-Ends
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# torque-http
|
|
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.
|
|
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
|
|
32
|
+
- Typed search parameters and response models
|
|
33
|
+
- Python 3.10+, MIT licensed
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install torque-http
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from torque_http import TorqueHttpClient, SearchParameters
|
|
45
|
+
|
|
46
|
+
client = TorqueHttpClient("http://localhost:8108", api_key="your-key")
|
|
47
|
+
|
|
48
|
+
# Search
|
|
49
|
+
results = client.search("products", q="laptop", query_by="title")
|
|
50
|
+
for hit in results.hits:
|
|
51
|
+
print(hit.document["title"])
|
|
52
|
+
|
|
53
|
+
# Typed parameters
|
|
54
|
+
params = SearchParameters(
|
|
55
|
+
q="laptop",
|
|
56
|
+
query_by="title,description",
|
|
57
|
+
filter_by="price:>100",
|
|
58
|
+
per_page=20,
|
|
59
|
+
)
|
|
60
|
+
results = client.search("products", params)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Multi-node with failover
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
client = TorqueHttpClient(
|
|
67
|
+
["http://node1:8108", "http://node2:8108"],
|
|
68
|
+
api_key="your-key",
|
|
69
|
+
num_retries=5,
|
|
70
|
+
)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Collection management
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
schema = {
|
|
77
|
+
"name": "products",
|
|
78
|
+
"fields": [
|
|
79
|
+
{"name": "title", "type": "string"},
|
|
80
|
+
{"name": "price", "type": "float", "sort": True},
|
|
81
|
+
{"name": "brand", "type": "string", "facet": True},
|
|
82
|
+
],
|
|
83
|
+
}
|
|
84
|
+
client.create_collection(schema)
|
|
85
|
+
|
|
86
|
+
client.create_document("products", {
|
|
87
|
+
"id": "1", "title": "Laptop Pro", "price": 1299.99, "brand": "Acme",
|
|
88
|
+
})
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## High-throughput TCP ingest
|
|
92
|
+
|
|
93
|
+
For streaming 100K+ documents, use the binary TCP protocol:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from torque_http import TorqueIngestClient, DocumentEncoder
|
|
97
|
+
|
|
98
|
+
schema = {"fields": [
|
|
99
|
+
{"name": "title", "type": "string"},
|
|
100
|
+
{"name": "price", "type": "float"},
|
|
101
|
+
]}
|
|
102
|
+
encoder = DocumentEncoder(schema)
|
|
103
|
+
|
|
104
|
+
with TorqueIngestClient() as tcp:
|
|
105
|
+
tcp.connect("localhost", 8109)
|
|
106
|
+
tcp.start_ingest("products")
|
|
107
|
+
tcp.send_batch(documents, encoder)
|
|
108
|
+
tcp.commit()
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## TQBF bulk file import
|
|
112
|
+
|
|
113
|
+
Pre-encode a compressed binary file for maximum throughput:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from torque_http import TorqueBinaryFileWriter, DocumentEncoder
|
|
117
|
+
|
|
118
|
+
encoder = DocumentEncoder(schema)
|
|
119
|
+
with TorqueBinaryFileWriter("data.tqbf", encoder) as writer:
|
|
120
|
+
for doc in source:
|
|
121
|
+
writer.write(doc)
|
|
122
|
+
|
|
123
|
+
client.import_binary("products", "data.tqbf")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Documentation
|
|
127
|
+
|
|
128
|
+
- [Torque documentation](https://truespar.com/torque/docs)
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +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).
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "torque-http"
|
|
7
|
+
version = "0.5.0"
|
|
8
|
+
description = "Official Python client for Torque — Truespar's in-memory search engine with a Typesense v30.1 compatible API. Zero external dependencies."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "Truespar" }]
|
|
13
|
+
keywords = ["search", "torque", "typesense", "truespar", "vector-search"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Topic :: Database :: Front-Ends",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://truespar.com/torque/docs"
|
|
28
|
+
Documentation = "https://truespar.com/torque/docs"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.wheel]
|
|
31
|
+
packages = ["src/torque_http"]
|
|
32
|
+
|
|
33
|
+
[tool.pytest.ini_options]
|
|
34
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""Torque Python HTTP client — zero external dependencies.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
from torque_http import TorqueHttpClient
|
|
5
|
+
|
|
6
|
+
client = TorqueHttpClient("http://localhost:8108", api_key="your-key")
|
|
7
|
+
results = client.search("products", q="laptop", query_by="title")
|
|
8
|
+
|
|
9
|
+
Multi-node with failover:
|
|
10
|
+
client = TorqueHttpClient(
|
|
11
|
+
["http://node1:8108", "http://node2:8108"],
|
|
12
|
+
api_key="your-key",
|
|
13
|
+
num_retries=5,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
Typed search parameters:
|
|
17
|
+
from torque_http import SearchParameters
|
|
18
|
+
params = SearchParameters(q="laptop", query_by="title", per_page=20)
|
|
19
|
+
results = client.search("products", params)
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from .client import TorqueHttpClient
|
|
23
|
+
from .exceptions import (
|
|
24
|
+
TorqueError,
|
|
25
|
+
TorqueApiError,
|
|
26
|
+
TorqueApiException,
|
|
27
|
+
ObjectNotFound,
|
|
28
|
+
ObjectAlreadyExists,
|
|
29
|
+
RequestUnauthorized,
|
|
30
|
+
RequestForbidden,
|
|
31
|
+
RequestMalformed,
|
|
32
|
+
ServerError,
|
|
33
|
+
ServiceUnavailable,
|
|
34
|
+
RequestTimeout,
|
|
35
|
+
)
|
|
36
|
+
from .models import (
|
|
37
|
+
CollectionAlias,
|
|
38
|
+
CollectionResponse,
|
|
39
|
+
CollectionSchema,
|
|
40
|
+
DeleteResult,
|
|
41
|
+
FieldDefinition,
|
|
42
|
+
HealthResponse,
|
|
43
|
+
ImportResult,
|
|
44
|
+
SearchResult,
|
|
45
|
+
SearchParameters,
|
|
46
|
+
GroupedSearchResult,
|
|
47
|
+
GroupedHit,
|
|
48
|
+
Hit,
|
|
49
|
+
FacetCount,
|
|
50
|
+
FacetResult,
|
|
51
|
+
ApiKey,
|
|
52
|
+
Preset,
|
|
53
|
+
StopwordSet,
|
|
54
|
+
SynonymItem,
|
|
55
|
+
SynonymSet,
|
|
56
|
+
UpdateResult,
|
|
57
|
+
AdminStats,
|
|
58
|
+
)
|
|
59
|
+
from .tcp import (
|
|
60
|
+
DocumentEncoder,
|
|
61
|
+
TorqueIngestClient,
|
|
62
|
+
TorqueBinaryFileWriter,
|
|
63
|
+
BatchAck,
|
|
64
|
+
CommitResult,
|
|
65
|
+
TorqueProtocolError,
|
|
66
|
+
TorqueConnectionError,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
__all__ = [
|
|
70
|
+
# Client
|
|
71
|
+
"TorqueHttpClient",
|
|
72
|
+
# Exceptions
|
|
73
|
+
"TorqueError",
|
|
74
|
+
"TorqueApiError",
|
|
75
|
+
"TorqueApiException",
|
|
76
|
+
"ObjectNotFound",
|
|
77
|
+
"ObjectAlreadyExists",
|
|
78
|
+
"RequestUnauthorized",
|
|
79
|
+
"RequestForbidden",
|
|
80
|
+
"RequestMalformed",
|
|
81
|
+
"ServerError",
|
|
82
|
+
"ServiceUnavailable",
|
|
83
|
+
"RequestTimeout",
|
|
84
|
+
# Models — collections
|
|
85
|
+
"CollectionAlias",
|
|
86
|
+
"CollectionResponse",
|
|
87
|
+
"CollectionSchema",
|
|
88
|
+
"FieldDefinition",
|
|
89
|
+
# Models — documents
|
|
90
|
+
"DeleteResult",
|
|
91
|
+
"ImportResult",
|
|
92
|
+
"UpdateResult",
|
|
93
|
+
# Models — search
|
|
94
|
+
"SearchResult",
|
|
95
|
+
"SearchParameters",
|
|
96
|
+
"GroupedSearchResult",
|
|
97
|
+
"GroupedHit",
|
|
98
|
+
"Hit",
|
|
99
|
+
"FacetCount",
|
|
100
|
+
"FacetResult",
|
|
101
|
+
# Models — API keys
|
|
102
|
+
"ApiKey",
|
|
103
|
+
# Models — config
|
|
104
|
+
"Preset",
|
|
105
|
+
"StopwordSet",
|
|
106
|
+
"SynonymItem",
|
|
107
|
+
"SynonymSet",
|
|
108
|
+
# Models — server
|
|
109
|
+
"HealthResponse",
|
|
110
|
+
"AdminStats",
|
|
111
|
+
# TCP ingest
|
|
112
|
+
"DocumentEncoder",
|
|
113
|
+
"TorqueIngestClient",
|
|
114
|
+
"TorqueBinaryFileWriter",
|
|
115
|
+
"BatchAck",
|
|
116
|
+
"CommitResult",
|
|
117
|
+
"TorqueProtocolError",
|
|
118
|
+
"TorqueConnectionError",
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
__version__ = "0.5.0"
|