Official Python SDK for Mantr - Deterministic Semantic Memory
Project description
Mantr Python SDK
Official Python client for Mantr - Deterministic Semantic Memory for AI.
Installation
pip install mantr
Quick Start
from mantr import MantrClient
# Initialize with your API key
client = MantrClient(api_key='vak_live_...')
# Walk the semantic graph
result = client.walk(phonemes=['dharma', 'karma', 'yoga'])
# Access results
for path in result.paths:
print(f"{' → '.join(path.nodes)} (score: {path.score})")
Features
- ✅ Type-safe - Full Pydantic model validation
- ✅ Async support - Built-in retry logic with exponential backoff
- ✅ Error handling - Detailed exception types
- ✅ Context manager - Automatic cleanup
- ✅ No dependencies - Only
requestsandpydantic
API Reference
MantrClient
client = MantrClient(
api_key: str, # Your Mantr API key (required)
base_url: str = "https://api.mantr.net", # API endpoint
timeout: int = 30 # Request timeout in seconds
)
walk()
Traverse the semantic graph to discover connections.
result = client.walk(
phonemes: List[str], # Sanskrit concepts to explore
pod: Optional[str] = None, # Context pod (coming soon)
depth: int = 3, # Traversal depth (1-10)
limit: int = 100 # Max results (1-1000)
)
Returns: WalkResponse with:
paths- List of discovered pathslatency_us- Execution time in microsecondscredits_used- Credits consumed
Examples
Chatbot with Memory
from mantr import MantrClient
client = MantrClient(api_key='vak_live_...')
# Store conversation context
user_message = "How do I implement OAuth?"
context = client.walk(phonemes=['authentication', 'security'])
# Pass to your LLM
response = openai.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": f"Context: {context}"},
{"role": "user", "content": user_message}
]
)
Document Q&A
# Query your knowledge base
answer = client.walk(
phonemes=['pricing', 'policy'],
depth=5,
limit=10
)
for path in answer.paths:
print(f"Relevance: {path.score:.2%} - {path.nodes}")
Error Handling
from mantr import (
MantrClient,
AuthenticationError,
InsufficientCreditsError,
RateLimitError
)
try:
result = client.walk(['test'])
except AuthenticationError:
print("Invalid API key")
except InsufficientCreditsError:
print("Out of credits - upgrade your plan")
except RateLimitError as e:
print(f"Rate limit exceeded - retry after {e.retry_after}s")
Context Manager
with MantrClient(api_key='vak_live_...') as client:
result = client.walk(['dharma'])
# Session automatically closed
Get API Key
- Sign up at mantr.net/signup
- Get 5,000 free walks/month
- No credit card required
Documentation
- API Docs: https://docs.mantr.net
- Examples: /examples
- Changelog: CHANGELOG.md
Support
- Issues: GitHub Issues
- Email: sdk@mantr.net
- Discord: https://discord.gg/mantr
License
MIT License - see LICENSE for details.
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
mantr-1.0.0.tar.gz
(6.0 kB
view details)
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
mantr-1.0.0-py3-none-any.whl
(6.3 kB
view details)
File details
Details for the file mantr-1.0.0.tar.gz.
File metadata
- Download URL: mantr-1.0.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eaa60c12537a977202f8ce259949f25485a90f1ed053cd6434c42932f68967ff
|
|
| MD5 |
198924de2b3acc0aabb932fabf4481cc
|
|
| BLAKE2b-256 |
93c225b5d43c6199d9501681b906f1cdceaae168ed27400b3e7397b2b725c84f
|
File details
Details for the file mantr-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mantr-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8abea9f38c024f646bd48998f5081afb5fbe9e093e707c113746847f28ff0f7
|
|
| MD5 |
8c99f2b6e1e32ce442f9b05c1fddaa13
|
|
| BLAKE2b-256 |
d2feb2ab077f2e80b268eae127a656c306144b55603c5474a2b7f50c722346ab
|