Skip to main content

Minimal Python client for the TogoLM API

Project description

togolm

Minimal Python client for the TogoLM API.

Requires Python 3.9+. Built on httpx.

Install

pip install togolm

Get an API key

from togolm import TogoLM

client = TogoLM()  # no key needed for this call
result = client.register_key(email="you@example.com", name="Your Name")
api_key = result["api_key"]

You can also call client.query(...) without a key — public access is rate-limited (see rate limits).

Usage

from togolm import TogoLM

client = TogoLM(api_key="your_api_key")

result = client.query("Comment créer une entreprise au Togo ?")
print(result["answer"], result["sources"])

Streaming

for event in client.query_stream("Comment créer une entreprise au Togo ?"):
    if event["type"] == "chunk":
        print(event["text"], end="")
    if event["type"] == "sources":
        print("Sources:", event["sources"])

Local development

Point at a local API instead of production:

client = TogoLM(base_url="http://localhost:8000/v1")

Error handling

Non-2xx responses raise TogoLMError (status and body attributes):

from togolm import TogoLM, TogoLMError

try:
    client.query("...")
except TogoLMError as err:
    print(err.status, err.body)

Context manager

TogoLM holds an httpx.Client; use it as a context manager to close it automatically:

with TogoLM(api_key="your_api_key") as client:
    result = client.query("...")

All methods

Method Description
query(question, category=None, language=None) RAG query, full response
query_stream(question, category=None, language=None) RAG query, SSE stream (generator)
embed(text) Generate an embedding vector
search(q) Full-text search over the corpus
categories() List available corpus categories
stats() Public corpus statistics
documents(page=None, limit=None, category=None) Paginated document list
document(doc_id) Document detail, including chunks
register_key(email=None, name=None) Request a free API key
me() Current API key info and usage
close() Close the underlying HTTP client

Full request/response shapes: API reference.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

togolm-0.1.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

togolm-0.1.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file togolm-0.1.1.tar.gz.

File metadata

  • Download URL: togolm-0.1.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for togolm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 05a666e0c801bd249b5b048c37e52afe08ce7b8568b07e7dac2d89811888aaa0
MD5 eeb2e97c8e02db90c8370d1ef3d5b0ab
BLAKE2b-256 3c48d269e97ec698e3e162b225bc41d5f7fd59f50287614f68f4dba2c2dbc71b

See more details on using hashes here.

File details

Details for the file togolm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: togolm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for togolm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f55942d85700d32ebd312873f96ef9fc61e68d0d0f85f4a379bcd7cdbef9930
MD5 dfae75866ea5da1c13ac94f729c40fcd
BLAKE2b-256 dc3fcb3e3d948d5c951bd2a33fd0ee95e98087daf64449ba833d215419f78f0e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page