Skip to main content

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("SUPERMEMORY_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 to http://localhost:8000)

Memories Resource

client.memories.add(...)

Add a memory to the Cortefy API.

Parameters:

  • content (str, required): The text content to store
  • container_tags (List[str] or str, optional): Container tag(s) - uses first if multiple
  • metadata (dict, optional): Optional metadata dictionary
  • chunk_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 text
  • container_tag (str, optional): Container tag to filter by
  • limit (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 errors
  • AuthenticationError: Raised when API key authentication fails
  • APIError: Raised when API returns an error response
  • ValidationError: 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

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

cortefy-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cortefy-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file cortefy-0.1.0.tar.gz.

File metadata

  • Download URL: cortefy-0.1.0.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

Hashes for cortefy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 be25efc2f00480ff85dd57f34f49da4985d8ee22db68eca6be9f3bf26481a38d
MD5 f0ad606672f9e263532f44f4237e3658
BLAKE2b-256 b81a3dde4c006b0088436e4c4bb7d44724f7c73b8cc373dc28e2af105731a22f

See more details on using hashes here.

File details

Details for the file cortefy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cortefy-0.1.0-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

Hashes for cortefy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec498fdcd958b941071797c66f1e340901f692569b0d48407884a1b014f447bb
MD5 d72711f5e46f686904a8eb760593af4d
BLAKE2b-256 6511813d0d5543df6bcf73bad6b7f87804933151fe092b01d94cdf85e2d3cde3

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