Official Python client for Torque — Truespar's in-memory search engine with a Typesense v30.1 compatible API. Zero external dependencies.
Project description
torque-http
Official Python client for Torque — Truespar's in-memory search engine with a Typesense v30.1 compatible API.
- Zero external dependencies — uses only the Python standard library
- HTTP API for search, collection management, and document CRUD
- TCP binary ingest for high-throughput streaming from databases
- TQBF file upload for bulk import
- Multi-node failover with automatic retry
- Typed search parameters and response models
- Python 3.10+, MIT licensed
Installation
pip install torque-http
Quick Start
from torque_http import TorqueHttpClient, SearchParameters
client = TorqueHttpClient("http://localhost:8108", api_key="your-key")
# Search
results = client.search("products", q="laptop", query_by="title")
for hit in results.hits:
print(hit.document["title"])
# Typed parameters
params = SearchParameters(
q="laptop",
query_by="title,description",
filter_by="price:>100",
per_page=20,
)
results = client.search("products", params)
Multi-node with failover
client = TorqueHttpClient(
["http://node1:8108", "http://node2:8108"],
api_key="your-key",
num_retries=5,
)
Collection management
schema = {
"name": "products",
"fields": [
{"name": "title", "type": "string"},
{"name": "price", "type": "float", "sort": True},
{"name": "brand", "type": "string", "facet": True},
],
}
client.create_collection(schema)
client.create_document("products", {
"id": "1", "title": "Laptop Pro", "price": 1299.99, "brand": "Acme",
})
High-throughput TCP ingest
For streaming 100K+ documents, use the binary TCP protocol:
from torque_http import TorqueIngestClient, DocumentEncoder
schema = {"fields": [
{"name": "title", "type": "string"},
{"name": "price", "type": "float"},
]}
encoder = DocumentEncoder(schema)
with TorqueIngestClient() as tcp:
tcp.connect("localhost", 8109)
tcp.start_ingest("products")
tcp.send_batch(documents, encoder)
tcp.commit()
TQBF bulk file import
Pre-encode a compressed binary file for maximum throughput:
from torque_http import TorqueBinaryFileWriter, DocumentEncoder
encoder = DocumentEncoder(schema)
with TorqueBinaryFileWriter("data.tqbf", encoder) as writer:
for doc in source:
writer.write(doc)
client.import_binary("products", "data.tqbf")
Documentation
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torque_http-0.5.0.tar.gz.
File metadata
- Download URL: torque_http-0.5.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d891bd63d60375f5cd959e63d71b01b9a60139feb791887be5f0030fc4bfcc03
|
|
| MD5 |
5b9276ca128d2ba015a1b1a2d8808c2c
|
|
| BLAKE2b-256 |
9961a0c6c4594dc9a093d8b09b866520202546d020c11d8a153f69bbe44ac7de
|
File details
Details for the file torque_http-0.5.0-py3-none-any.whl.
File metadata
- Download URL: torque_http-0.5.0-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df0eb5eef319ff81737a95c428a41b09479a7edbfc84018c82d5deee62330a52
|
|
| MD5 |
1707be52e5598cc5b77320cde6409f1e
|
|
| BLAKE2b-256 |
f631d582143b815e46d657882d8448c7617f05c6c4eaa56cea99ff5f3ef5ef4a
|