Python client library for the Cortefy API
Project description
Cortefy Python Client
Python client library for the Cortefy API - a semantic memory and search system.
Installation
pip install cortefy
Quick Start
from cortefy import Cortefy
import os
# Initialize the client
client = Cortefy(
api_key=os.environ.get("CORTEFY_API_KEY"),
base_url="https://api.cortefy.com" # Optional, defaults to localhost
)
# Add a memory
result = client.memories.add(
content="Machine learning enables computers to learn from data",
container_tags=["ai-research"],
metadata={"priority": "high"}
)
# Search memories
results = client.search.memories(
q="machine learning accuracy",
limit=5,
container_tag="ai-research"
)
API Reference
Cortefy Client
client = Cortefy(api_key: str, base_url: Optional[str] = None)
api_key: Your Cortefy API key (required)base_url: Base URL for the API (defaults tohttp://localhost:8000)
Memories Resource
client.memories.add(...)
Add a memory to the Cortefy API.
Parameters:
content(str, required): The text content to storecontainer_tags(List[str] or str, optional): Container tag(s) - uses first if multiplemetadata(dict, optional): Optional metadata dictionarychunk_method(str, optional): Chunking method ('tokens' or 'sentences', default: 'tokens')chunk_size(int, optional): Size of chunks (default: 1000)chunk_overlap(int, optional): Overlap between chunks (default: 200)
Returns: Response dict with status, chunks, memory_ids, container, and timing
Search Resource
client.search.memories(...)
Search memories using semantic search.
Parameters:
q(str, required): Search query textcontainer_tag(str, optional): Container tag to filter bylimit(int, optional): Maximum number of results (default: 5)min_similarity(float, optional): Minimum similarity score 0.0-1.0 (default: 0.0)
Returns: Response dict with results, timing, and total
Error Handling
The client raises custom exceptions:
CortefyException: Base exception for all Cortefy errorsAuthenticationError: Raised when API key authentication failsAPIError: Raised when API returns an error responseValidationError: Raised when request validation fails
from cortefy import Cortefy
from cortefy.exceptions import AuthenticationError, APIError
try:
client = Cortefy(api_key="invalid-key")
result = client.memories.add(content="test")
except AuthenticationError as e:
print(f"Auth failed: {e}")
except APIError as e:
print(f"API error: {e} (status: {e.status_code})")
License
MIT
Links
- Homepage: https://cortefy.com
- API Documentation: https://cortefy.com/docs
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
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 cortefy-0.1.1.tar.gz.
File metadata
- Download URL: cortefy-0.1.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d6718a03973e4061a115abe38a7be0cfa0fec79a7a340acab319679f053f013
|
|
| MD5 |
2a153cc1c7c7ec5ca208cb51989c0692
|
|
| BLAKE2b-256 |
861cce9bd4e498659463195ac75a43c3fb0572d178f7ecc2fe6882ea76067d54
|
File details
Details for the file cortefy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cortefy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dff3002885885366c6d35aab942a7c44bcd18011f8d5031069ff55c640ab6ba3
|
|
| MD5 |
6efeb81f61f4680e47eadbdd804fafb6
|
|
| BLAKE2b-256 |
3c2cbbfb72e9fa83a8a3570a34d5685029f293da0a89dacab93c4fffefb430d0
|