crystalbrain (Python)
Python client for the CrystalBrain REST API: read and write the memory of your users from your own app. No dependency (standard library only), Python 3.11 or later. Every input and result is typed (TypedDicts generated from the API's OpenAPI document).
Install
pip install crystalbrain
Usage
Create an API key on the Connections page of your CrystalBrain dashboard and keep it on your server.
import os
from crystalbrain import CrystalBrain, CrystalBrainError
cb = CrystalBrain(os.environ["CRYSTALBRAIN_API_KEY"])
# What CrystalBrain knows about a customer, as a context block for your LLM
result = cb.search(user="cus_123", app="my-app", query="What does this customer prefer?")
print(result["context_block"])
# Save something durable about the customer (an unknown user is created)
cb.save(user="cus_123", app="my-app", type="preference", title="Delivery on Saturdays", content="Prefers deliveries on Saturday mornings.")
# Correct or forget a memory (the previous version is kept)
memory_id = result["entries"][0]["id"]
cb.update_memory(id=memory_id, user="cus_123", app="my-app", content="Prefers deliveries on Sunday mornings.")
cb.archive_memory(id=memory_id, user="cus_123")
# Read everything, page by page
page = cb.list_memories(user="cus_123", limit=100)
while page["next_offset"] is not None:
page = cb.list_memories(user="cus_123", limit=100, offset=page["next_offset"])
# Errors carry a stable code
try:
cb.search(user="cus_123", query="hello")
except CrystalBrainError as err:
if err.code == "RATE_LIMITED":
print(f"retry in {err.retry_after} s")
user is your customer's ID or name in your own app; omit it to work on your own account. Query parameters named like Python keywords go through a dict: cb.get_analytics(user="cus_123", kind="searches", **{"from": "2026-10-01"}).
| Method | API call |
|---|---|
search(**input) |
POST /api/v1/search |
save(**input) |
POST /api/v1/save |
list_brains(user=None) |
GET /api/v1/brains |
create_brain(**input) |
POST /api/v1/brains |
list_users(**input) |
GET /api/v1/users |
add_document(**input) |
POST /api/v1/documents |
list_skills() |
GET /api/v1/skills |
mention_skill(**input) |
POST /api/v1/skills |
log_tool_calls(**input) |
POST /api/v1/tool-calls |
update_memory(**input) |
PATCH /api/v1/memory |
archive_memory(**input) |
POST /api/v1/memory/archive |
delete_user(user) |
DELETE /api/v1/user |
restore_user(user) |
POST /api/v1/user/restore |
get_user(user=None) |
GET /api/v1/user |
get_brain(**input) |
GET /api/v1/brain |
list_memories(**input) |
GET /api/v1/memories |
get_memory(id) |
GET /api/v1/memory |
get_analytics(**input) |
GET /api/v1/analytics |
resolve_contradiction(**input) |
POST /api/v1/contradictions/resolve |
similar_memories(id, limit=None) |
GET /api/v1/memory/similar |
merge_memories(**input) |
POST /api/v1/memories/merge |
undo_merge(id) |
POST /api/v1/memories/unmerge |
Every field and error code: API reference.
Options
CrystalBrain(api_key, base_url="https://crystalbrain.ai", timeout=60, transport=None). transport replaces the HTTP layer (tests): a function (method, url, headers, body) -> (status, headers, body).
Development
- Types:
python scripts/generate_types.pyregeneratessrc/crystalbrain/types.pyfrom../typescript/openapi.json(the API snapshot shared with the TypeScript SDK; update it there withnpm run spec). - Tests:
PYTHONPATH=src python -m unittest discover tests(fake transport, no network). - Publish:
python -m buildthenpython -m twine upload dist/*(needs a PyPI account).
License
MIT
Metadata
Release files for crystalbrain 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| crystalbrain-0.3.0.tar.gz | 12.6 kB | Without provenance | Details for crystalbrain-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| crystalbrain-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for crystalbrain-0.3.0-py3-none-any.whl |
Total release size: 23.3 kB
Release files / crystalbrain-0.3.0.tar.gz
| Download URL | crystalbrain-0.3.0.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
386e947c2a641e1673d0464d2ab8f1f0e8cadf93540026942e18fc8e6c162721
|
|
BLAKE2b-256 checksum How to use checksums |
d0b70f621adf805e7004f1de19047fbae6c5ccd9b34b0ffa195a56fc2f5885ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Release files / crystalbrain-0.3.0-py3-none-any.whl
| Download URL | crystalbrain-0.3.0-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6c1c3ba7bf075829f9c0c549d6113c855e31300cbcaf5733dbe6e7230993c339
|
|
BLAKE2b-256 checksum How to use checksums |
d1160c0a27284926971ead81c8b2b73bab8a70e78a985ec02287d0e2326030aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Security for crystalbrain 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.