Skip to main content

Tex Python SDK — SuperMemory-compatible memory API

Project description

Tex Python SDK

SuperMemory-compatible memory SDK for Python.

Installation

pip install tex-sdk

Optional HTTP/2 support:

pip install "tex-sdk[http2]"

Requires Python 3.9+.

Quick Start

API key

from tex import Tex

client = Tex(api_key="sk-...", base_url="http://localhost:8000")

client.add("The quick brown fox jumps over the lazy dog.")
results = client.search.documents("fox")

Environment variables

Set TEX_API_KEY and TEX_BASE_URL, then:

from tex import Tex

client = Tex()

Org + user login

from tex import Tex

client = Tex(base_url="http://localhost:8000", org_id="org1", user_id="user1")

Documents

Add, retrieve, update, delete, list, and batch-manage documents.

# Top-level shortcut
resp = client.add("Document content", container_tag="notes")

# Equivalent resource call
resp = client.documents.add("Document content", container_tag="notes")

# Get by ID
doc = client.documents.get("doc_abc123")

# Update
client.documents.update("doc_abc123", content="Updated content")

# Delete
client.documents.delete("doc_abc123")

# List with filters
docs = client.documents.list(container_tags=["notes"], limit=20)

# Batch add
client.documents.batch_add(
    ["First document", "Second document"],
    container_tag="batch-import",
)

# Bulk delete
client.documents.delete_bulk(container_tags=["old-tag"])

Search

Document search

results = client.search.documents("quarterly revenue", limit=10)

# Alias
results = client.search.execute("quarterly revenue", limit=10)

Memory search

results = client.search.memories("user preferences", container_tag="user1")

Memories

# Add memories
client.memories.add(
    [{"content": "User prefers dark mode"}],
    container_tag="prefs",
)

# Forget a memory
client.memories.forget("prefs", id="mem_abc123")

# Update a memory
client.memories.update_memory("prefs", "User prefers light mode", id="mem_abc123")

Profile

profile = client.profile("user-container-tag")
print(profile.profile)

Tex-Unique Features

NLQ (Natural Language Query)

result = client.nlq.execute("What meetings did I have last week?")
print(result.text)
print(result.evidence)

Episodes

# Store a conversation
client.episodes.store(
    [
        {"role": "user", "content": "Book a table for two"},
        {"role": "assistant", "content": "Which restaurant?"},
    ],
    episode_id="ep_001",
)

# List episodes
episodes = client.episodes.list(limit=10)

Preferences

client.preferences.store([
    {"key": "drink", "value": "espresso", "confidence": 0.9},
])

DB

result = client.db.query("MATCH (n) RETURN n LIMIT $limit", params={"limit": 5})
schema = client.db.schema()

Auth

info = client.auth.whoami()

Jobs

status = client.jobs.get("job_abc123")

Error Handling

The SDK provides a detailed error hierarchy:

TexError
  APIError
    APIConnectionError
      APITimeoutError
    APIStatusError
      BadRequestError          (400)
      AuthenticationError      (401)
      PermissionDeniedError    (403)
      NotFoundError            (404)
      ConflictError            (409)
      UnprocessableEntityError (422)
      RateLimitError           (429)
      InternalServerError      (500+)
    APIResponseValidationError
from tex import Tex, NotFoundError, AuthenticationError, APIStatusError

client = Tex(api_key="sk-...", base_url="http://localhost:8000")

try:
    doc = client.documents.get("nonexistent")
except NotFoundError as e:
    print(f"Not found: {e}")
except AuthenticationError as e:
    print(f"Auth failed: {e}")
except APIStatusError as e:
    print(f"HTTP {e.status_code}: {e.message}")
    print(f"Request ID: {e.request_id}")

Configuration

Use TexConfig and TexEndpoints for advanced configuration:

from tex import Tex, TexConfig, TexEndpoints

config = TexConfig(
    base_url="https://api.example.com",
    api_key="sk-...",
    timeout_s=30.0,
    max_retries=3,
    http2=True,
    endpoints=TexEndpoints(
        db_query="/custom/db/query",
        db_schema="/custom/db/schema",
    ),
)

client = Tex(config=config)

Default timeout is 60 seconds. Default max retries is 2.

Migration from SuperMemory

SuperMemory Tex SDK
client.add(content) client.add(content) or client.documents.add(content)
client.documents.get(id) client.documents.get(id)
client.documents.update(id) client.documents.update(id)
client.documents.delete(id) client.documents.delete(id)
client.documents.list() client.documents.list()
client.documents.batch_add(docs) client.documents.batch_add(docs)
client.search.execute(q) client.search.execute(q) or client.search.documents(q)
client.search.memories(q) client.search.memories(q)
client.memories.add(memories) client.memories.add(memories)
client.memories.forget(tag) client.memories.forget(tag)
client.profile(tag) client.profile(tag)

Tex extends SuperMemory with additional resources: nlq, episodes, preferences, db, auth, and jobs.

HTTP/2

HTTP/2 is enabled by default. If the h2 package is not installed, the SDK falls back to HTTP/1.1 automatically. To install with HTTP/2 support:

pip install "tex-sdk[http2]"

To explicitly disable HTTP/2:

client = Tex(api_key="sk-...", base_url="http://localhost:8000", http2=False)

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

tex_sdk-1.1.0.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

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

tex_sdk-1.1.0-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file tex_sdk-1.1.0.tar.gz.

File metadata

  • Download URL: tex_sdk-1.1.0.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for tex_sdk-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b7b3a76988a0d3035210fff3f3e1389176ed4dbbcea27c545b14dd9f03718edd
MD5 5cea8f100b2035cf4d226071231ae539
BLAKE2b-256 d3245d194ec59c7e9b8754ac619597e9a81eaec0d09c2a3ef9914091e2c3c0a5

See more details on using hashes here.

File details

Details for the file tex_sdk-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: tex_sdk-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for tex_sdk-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91ff1ac8d84a95350907225c5ea9bf6f9c360be7d9f6709aa697b7e807bdd89a
MD5 69740ad6847d367bcd3eb24d12ae10eb
BLAKE2b-256 dab3be882a93135c8294e3dd54ff392d3b123a6ee8fa9f28de6128037a807696

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