Skip to main content

Python SDK for Synapsor, the agent-native database for auditable AI applications

Project description

Synapsor Python SDK

The Synapsor Python SDK connects applications to hosted or local Synapsor databases. Use it for SQL, branch workflows, agent contexts, capabilities, evidence, memory, and safe write proposals from Python applications.

Local Usage

from synapsor import Synapsor

db = Synapsor("app.db", auto_start=True)
db.set_session({
    "tenant_id": "acme",
    "principal": "support_agent_17",
    "session_id": "agent_run_1",
})

db.execute("CREATE TABLE messages (id INT, body VARCHAR);")
db.execute("INSERT INTO messages VALUES (1, 'hello');")
rows = db.query("SELECT * FROM messages;")

proposal = db.propose_memory_fact(
    scope=("tenant", "acme"),
    subject=("preference", "answer_style"),
    claim="The operator prefers concise answers.",
    source=("turn", "msg_1"),
    trust="verified",
    approval="approved",
    reason="stable preference extracted from chat",
)
db.approve_memory_proposal(proposal["proposal"]["proposal_id"], "operator approved")
memory = db.recall_memory(scope=("tenant", "acme"), subject=("preference", "answer_style"))

db.close()

Hosted Usage

Install from PyPI:

python -m pip install synapsor
import os
from synapsor import Synapsor

db = Synapsor("https://dev-api.synapsor.ai", api_key=os.environ["SYNAPSOR_API_KEY"])
db.set_session({
    "tenant_id": "acme",
    "principal": "app_user_1",
    "session_id": "first_hosted_run",
})

print(db.query("SELECT 1;"))

ctx = db.invoke_agent_capability("chat.prepare_llm_context", {"question": "..."})
proposal = db.invoke_agent_capability(
    "support.propose_late_fee_waiver",
    {"fee_id": "FEE_3001", "reason": "card_update_failure"},
    mode="propose_only",
    auto_branch=True,
    response_envelope=True,
)

Use database-scoped API keys from the Synapsor control panel for hosted projects.

API Surface

  • execute(sql) and query(sql)
  • set_session({...})
  • invoke_agent_capability(name, arguments, mode=None, auto_branch=None, response_envelope=None, include_audit_trail=None, settlement_policy=None)
  • list_capabilities(query="...")
  • remember_fact(...)
  • propose_memory_fact(...)
  • approve_memory_proposal(id, reason)
  • reject_memory_proposal(id, reason)
  • list_memory_proposals(...)
  • recall_memory(...)
  • retire_fact(...) and forget_fact(...)
  • check_fact_for_action(...)
  • branch helpers: create_branch, use_branch, diff_branch, merge_branch, drop_branch
  • write lifecycle helpers: preview_write, approve_write, commit_write, reject_write, settle_write
  • read_resource(uri)

Errors from Synapsor become SynapsorError with status and payload.

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

synapsor-0.1.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

synapsor-0.1.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file synapsor-0.1.1.tar.gz.

File metadata

  • Download URL: synapsor-0.1.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for synapsor-0.1.1.tar.gz
Algorithm Hash digest
SHA256 208cc9fcd5d49faf482f168353cf889d8416c8b0ea5a02ca74b53e97c870f0a4
MD5 cdddf7a66185aa149323b1a1a3996b0a
BLAKE2b-256 40a8d724ce9c8f635a0c455ec0a1697ecc1fe542553c4bffc40ef5638afb2b4f

See more details on using hashes here.

File details

Details for the file synapsor-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: synapsor-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for synapsor-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 53721bea679e5d78e486a9856d034848644850f96de760be6a96f7014262ca48
MD5 1a838765a480193ee549724c9fb335a0
BLAKE2b-256 57128cfb97d29f84760f1f5ab70a8dcd2992d4616b865860fc79e4ebe6f9689d

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