Minimal Python client for https://api.context.llm7.io
Project description
py-context-llm7
py-context-llm7 is a minimal Python client for the https://api.context.llm7.io service.
It lets you authenticate, manage projects and contexts, and search (retrieve relevant context for a query) with a tiny, dependency‑light API (built on requests).
Installation
pip install py-context-llm7
Quickstart
Authenticate with a personal token
import os
import time
from py_context_llm7 import ContextClient
client = ContextClient(bearer=os.environ["CONTEXT_TOKEN"])
print(client.me())
# {'user_id': '...', 'email': '...'}
pid = client.create_project_and_fetch_id("My project")
client.add_context(pid, "The capital of France is Paris.")
client.add_context(pid, "The capital of Germany is Berlin.")
client.add_context(pid, "The capital of Italy is Rome.")
client.add_context(pid, "The capital of Spain is Madrid.")
client.add_context(pid, "The capital of Portugal is Lisbon.")
client.add_context(pid, "The capital of the Netherlands is Amsterdam.")
client.add_context(pid, "The capital of Belgium is Brussels.")
client.add_context(pid, "The capital of Greece is Athens.")
client.add_context(pid, "The capital of Sweden is Stockholm.")
print(client.list_projects())
print(client.list_contexts(pid))
print(f"pid: {pid}")
time.sleep(5) # allow a short delay for vector indexing
print(client.search(pid, "What is the capital of Italy?"))
# Example:
# {'context': 'The capital of Portugal is Lisbon.\nThe capital of Germany is Berlin.\nThe capital of Spain is Madrid.\nThe capital of Italy is Rome.\nThe capital of France is Paris.', 'query': 'What is the capital of Italy?'}
First‑time setup via Google ID token → app JWT → personal token
Visit https://context.llm7.io/ and log in with your Google account. This will create an app JWT for you.
Then, you will be able to create a free token for API.
Features
- Simple auth: Use a personal token directly or exchange a Google ID token for an app JWT.
- Project management: List, create, and delete projects.
- Context management: Add, list, and delete contexts (with a helper to delete by
vector_id). - Search: Query for relevant context across your stored items.
- Minimal deps: Only
requests. - Clear errors: Raises
ContextAPIError(status, message)on non‑2xx responses.
API Overview
from py_context_llm7 import ContextClient, ContextAPIError
Construction
ContextClient(base_url="https://api.context.llm7.io", bearer=None, timeout=30)
Auth
-
set_bearer(token: str) -> NoneSet an app JWT or personal token. -
verify_google_id_token(id_token: str) -> dictGET/verify?token=...→ returns{"email": str, "token": "<app_jwt>"}and sets bearer. -
list_tokens() -> list[dict](requires app JWT) -
create_personal_token(set_as_current: bool = True) -> dict(requires app JWT) -
delete_token(token_id: int) -> dict(requires app JWT)
User
me() -> dictGET/me→{"user_id": str, "email": str}.
Projects
list_projects() -> list[dict]create_project(name: str) -> dictcreate_project_and_fetch_id(name: str) -> int(create then re‑list; newest id)delete_project(project_id: int) -> dict
Contexts
-
list_contexts(project_id: int) -> list[dict]Returns items like{"id": int, "source": str, "vector_id": str}. -
add_context(project_id: int, source: str) -> dictReturns{"status": "added", "vector_id": "..."}. -
delete_context(project_id: int, context_id: int) -> dict -
delete_context_by_vector_id(project_id: int, vector_id: str) -> dict
Search
search(project_id: int, query: str) -> dictReturns{"context": "<joined sources>", "query": "..."}.
Error Handling
try:
client.add_context(pid, "Some text")
except ContextAPIError as e:
print(e.status, e.message)
Tips
- Indexing delay: after adding contexts, wait briefly (e.g., 2–5 seconds) before searching so the vectors are indexed.
- Base URL: override
base_urlif you run a self‑hosted deployment. - Security: keep both app JWTs and personal tokens secret.
Contributing
Issues and PRs are welcome. Please open them on the repo:
- Issues: https://github.com/chigwell/py-context-llm7/issues
- Source: https://github.com/chigwell/py-context-llm7
License
py-context-llm7 is released under the MIT License.
Support
Email: support@llm7.io
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 py_context_llm7-0.1.0.tar.gz.
File metadata
- Download URL: py_context_llm7-0.1.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8ac4d173ba12a1bb9f16a0df689cad32676fc4fb0037b60bb49abc0cd821a5a
|
|
| MD5 |
bdac620818f82ec1d179f1021689d614
|
|
| BLAKE2b-256 |
b410ca4f5f866a8eaa170069290af31ef395271416baebaed0cf63784b73f85b
|
File details
Details for the file py_context_llm7-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_context_llm7-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
714cec78c33c35ce7a171fbcfd28b486db6db8db1cbc4f098637c46ea21d0016
|
|
| MD5 |
f44ce3155b393322bd4821db75736402
|
|
| BLAKE2b-256 |
90ffd1357bc609c5fc94789a60d3ffad88e3d3971a16d1a6d3cb132b5c020090
|