Skip to main content

Programmatic CRUD for AI project knowledge bases (Claude Projects, Gemini Gems)

Project description

aikb

Programmatic CRUD for AI project knowledge bases (Claude Projects, Gemini Gems).

Dict-like access to knowledge files — store['notes.md'] = content — backed by local files, Claude Projects (via ClaudeSync), or any custom provider.

To install: pip install aikb

Quick start

from aikb import LocalKb

store = LocalKb()  # ~/.local/share/aikb/localkb_files/default/
store['ideas.md'] = '# Ideas\nFirst idea'
print(store['ideas.md'])
list(store)          # ['ideas.md']
del store['ideas.md']

Every store is a standard Python MutableMapping (dict-like), so len(), in, .keys(), .values(), .items(), and .update() all work.

Override the default directory with a path or the AIKB_LOCAL_DIR env var:

store = LocalKb('/path/to/my/knowledge')
store = LocalKb(project_id='research')  # subfolder under default dir

Claude Projects

Manage knowledge files in Claude.ai Projects programmatically:

pip install aikb[claude]

Browse all your projects

from aikb import ClaudeProjects

projects = ClaudeProjects()
list(projects)                  # ['My Project', 'Another Project', ...]
files = projects['My Project']  # returns a dict-like store
list(files)                     # ['context.md', 'notes.md']
print(files['context.md'])

Direct access by project UUID

from aikb import ClaudeProject

store = ClaudeProject('your-project-uuid')
store['context.md'] = '# Project context\n...'
print(store['context.md'])
del store['context.md']

Getting your session key

aikb automatically looks for a Claude session key in this order:

  1. Explicit session_key parameter
  2. CLAUDE_SESSION_KEY environment variable
  3. ClaudeSync stored credentials (~/.claudesync/)
  4. Browser cookies (requires pip install aikb[cookies])

If none are found, you'll get a helpful error with instructions.

To get your session key manually:

  1. Open https://claude.ai and log in
  2. Open Developer Tools (F12) → Application → Cookies
  3. Copy the value of the sessionKey cookie (starts with sk-ant-)
  4. Set it:
export CLAUDE_SESSION_KEY='sk-ant-sid01-...'

Or use ClaudeSync to store credentials:

pip install claudesync
claudesync auth login

Syncing stores

aikb includes a sync engine that works with any two MutableMapping stores — plain dicts, LocalKb, ClaudeProject, or any custom store.

Push / Pull (one-directional)

from aikb import LocalKb, ClaudeProject, push, pull

local = LocalKb('/path/to/docs')
remote = ClaudeProject('project-uuid')

push(local, remote)                # local → remote (source wins)
push(local, remote, delete=True)   # also remove remote files not in local
pull(local, remote)                # remote → local

Bidirectional sync (three-way reconciliation)

from aikb import sync, clone

# First time: clone to establish a manifest (baseline)
clone(local, remote, manifest_path='.aikb/manifest.json')

# Later: bidirectional sync detects who changed what
sync(local, remote, manifest_path='.aikb/manifest.json')

Status (dry run)

from aikb import status

for action in status(local, remote):
    print(f"{action.action.value:8s} {action.direction:10s} {action.filename}")

Conflict resolution

from aikb import sync, ConflictPolicy

sync(a, b, manifest=m, on_conflict=ConflictPolicy.A_WINS)   # local wins
sync(a, b, manifest=m, on_conflict=ConflictPolicy.SKIP)     # skip conflicts
sync(a, b, manifest=m, on_conflict=my_resolver_function)    # custom callable

Works with plain dicts too — no aikb stores required:

from aikb import push
src = {"readme.md": "# Hello", "notes.md": "..."}
tgt = {}
push(src, tgt)  # tgt is now a copy of src

Custom providers

Implement the KnowledgeBaseProvider protocol to add new backends:

from aikb import KnowledgeFiles, KnowledgeBaseProvider

class MyProvider:  # no inheritance needed — just implement the methods
    def list_files(self, project_id: str): ...
    def read_file(self, project_id: str, filename: str) -> str: ...
    def upsert_file(self, project_id: str, filename: str, content: str): ...
    def delete_file(self, project_id: str, filename: str): ...

store = KnowledgeFiles(MyProvider(), project_id='my-project')

MCP server

Expose knowledge base CRUD as MCP tools for Claude Desktop, Claude Code, or any MCP-compatible client:

pip install aikb[mcp]
python -m aikb.mcp_server

Tools exposed: list_files, read_file, write_file, delete_file — each taking platform ("local" or "claude"), project, and file parameters.

dol compatibility

aikb stores implement collections.abc.MutableMapping, making them natively compatible with dol:

pip install aikb[dol]
from dol import wrap_kvs
from aikb import LocalKb

store = wrap_kvs(
    LocalKb('/tmp/kb'),
    obj_of_data=lambda s: s.upper(),  # transforms on read
)

Optional dependencies

Extra Install Provides
claude pip install aikb[claude] Claude Projects via ClaudeSync
cookies pip install aikb[cookies] Auto-extract session keys from browser
mcp pip install aikb[mcp] FastMCP server
dol pip install aikb[dol] dol store transforms
all pip install aikb[all] Everything

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

aikb-0.0.4.tar.gz (42.0 kB view details)

Uploaded Source

Built Distribution

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

aikb-0.0.4-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file aikb-0.0.4.tar.gz.

File metadata

  • Download URL: aikb-0.0.4.tar.gz
  • Upload date:
  • Size: 42.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aikb-0.0.4.tar.gz
Algorithm Hash digest
SHA256 31065a6f5de1c436e6ef1f77db9f752e9dc3d93a7de164657738fc4c71f58aa0
MD5 f07073ca359bb9cd8f116b5da8107e35
BLAKE2b-256 1746f8403b977559cfbf7863a500baf9f12b16bd6ea446007ccddf42c1c80a3b

See more details on using hashes here.

File details

Details for the file aikb-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: aikb-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aikb-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 444c6093d35ebb05c376e5cf6cc469d8ece5702837b6d2e103b350a6f383f734
MD5 30b0fe428d4ae93faaa3addf84980b88
BLAKE2b-256 9f63c9eb41e0a34e1663fd3e335d9d2af0303af8ee973bf19723b33ce80c219f

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