Python SDK
The Papr Python SDK provides a Pythonic interface for interacting with the Papr API, with full type hints and modern Python features.
Installation
Install the SDK using pip:
pip install papr
Requirements
- HTTPS: The endpoint requires HTTPS protocol. HTTP connections will fail.
- Environment Variable: Set
PAPR_MEMORY_API_KEY
in your environment before running. - X-Client-Type Header: This is automatically included by the SDK but can be customized if needed.
- Authentication: Only use one auth method (X-API-Key takes precedence over Bearer token).
Quick Start
from papr import Papr
# Initialize the client
client = Papr(api_key="your_api_key")
# Add a memory
memory = client.memory.add(
content="Important meeting notes from today's discussion",
metadata={
"topics": ["meetings", "notes"],
"created_at": "2024-01-01T12:00:00Z"
}
)
# Search memories
results = client.memory.search(
query="meeting notes from today"
)
Documentation
For complete documentation, examples, and API reference, visit our Python SDK repository.
Features
- Full type hints support
- Automatic retries with exponential backoff
- Comprehensive error handling
- Async support
- Extensive documentation and examples
Error Handling
The SDK provides typed exceptions for different error cases:
from papr import Papr, APIError, NetworkError
client = Papr()
try:
client.memory.add(...)
except APIError as e:
print(f"API error: {e.status_code}")
except NetworkError as e:
print(f"Network error: {e}")
Advanced Usage
Async Support
from papr import AsyncPapr
async with AsyncPapr() as client:
memory = await client.memory.add(
content="Async memory creation"
)
Batch Operations
memories = client.memory.add_batch([
{"content": "Memory 1"},
{"content": "Memory 2"}
])