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"]  # shown once — save it

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"])

Multi-turn conversations

history = []
for question in ["Comment créer une entreprise au Togo ?", "Et pour les impôts ?"]:
    result = client.query(question, history=history)
    history.append({"role": "user", "content": question})
    history.append({"role": "assistant", "content": result["answer"]})

history is capped at 20 messages server-side; oldest first. max_tokens (default 3000, 50–4096) caps the generated answer length.

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, max_tokens=None, history=None) RAG query, full response
query_stream(question, category=None, language=None, max_tokens=None, history=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, page_size=None, category=None, source=None, language=None) Paginated document list
document(doc_id) Document detail, including chunks
register_key(email, name, use_case=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.2.tar.gz (3.6 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.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: togolm-0.1.2.tar.gz
  • Upload date:
  • Size: 3.6 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.2.tar.gz
Algorithm Hash digest
SHA256 68973bfa60649d08dc8fb8d4f0b86d6b74457689f02d86df2a15c75d658e2a10
MD5 b9bd44754555a95e81303a93f350c59e
BLAKE2b-256 b0be88289c452193fd58e90a7125815cf132df0ef02c34daf1f1ba1e3b8000c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: togolm-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b98112e8f272864f516397c587ce8cfc6d25ceb2a2849f3da50382ee0aad5d4d
MD5 d9b5919e07916cb467b7f276675b6524
BLAKE2b-256 69dabf90297852cb35fd870e7d389fdc89f84f44d71a7687a16ceae3a78ced0b

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