statejar (Python)
The Python client for the hosted StateJar memory API.
StateJar keeps conversational memory as structured, versioned state on the
StateJar service. This package sends a message to the service, gets back the
fields a question needs as memory_context, and hands that to your own
model call. It never calls a language model and never sees your provider key.
What this package includes — and what it does not
| Included | Not included |
|---|---|
StateJar, an HTTP client for /memory/ingest and /memory/query |
Any memory engine: extraction, canonicalization, handles and versioning all run on the StateJar service |
Typed exceptions (StateJarError, StateJarAuthError, StateJarConnectionError) |
Any LLM client or provider integration |
py.typed type information |
The StateJar backend, frontend or database code |
The only runtime dependency is httpx. Until 0.4.1 this distribution also
carried an embedded engine (statejar.LocalMemory); it was removed in 0.5.0
— see CHANGELOG.md.
Licence
Free to use with the StateJar service, under the StateJar SDK License in the LICENSE file included with this package. It is a proprietary licence, not an open-source one: you may install and use the unmodified package to access the service and redistribute unmodified copies; you may not distribute modified versions, use the package to build a competing service, or reverse engineer the service. Use of the service itself is governed by the terms at https://statejar.com/terms.
Install
pip install statejar
Requires Python 3.10+. No --pre and no version pin are needed. The one
dependency, httpx, is capped below 1.0, so --pre (which applies to every
dependency) cannot pull an httpx pre-release either.
Sign in from the terminal
pip install statejar # or: pip install "statejar[keyring]" for the OS keychain
statejar login # opens statejar.com/device; approve once
statejar whoami # which account the stored key belongs to
statejar logout # forget the key on this machine
statejar login works like gh auth login: the terminal shows a code, you
approve it in the signed-in browser (two-factor included), and a one-year
developer key is stored locally — in the OS keychain when keyring is
installed, else in ~/.config/statejar/credentials.json with mode 0600
(%APPDATA%\statejar on Windows). Your password never passes through the
terminal and the key is never shown in the browser.
StateJar() with no api_key then uses STATEJAR_API_KEY when it is set
(a server, CI), else the stored key. STATEJAR_BASE_URL points the client at
staging or a self-hosted server. The key reaches the memory API only; revoke
it on the API Keys page.
Memory from the terminal
statejar init --scope my-project # sign in if needed; my-project becomes the default scope
statejar add "I'm Kavya, I live in Bengaluru and my laptop budget is 80000 rupees."
statejar search "what is my budget?" # only the fields the question needs, its handle, the audit id
statejar list # every fact in the scope's current state
statejar forget budget # a new version without it; history keeps it
statejar export --out memory.json # every version, oldest first, with handles (mode 0600)
statejar status # the key's account, the scope, its newest handle
A scope is one session tag in your account (a project, an agent, a chat); the
integrations each use their own (claude-code, codex, opencode, hermes,
openclaw), and --scope reads any of them. Without --scope, the commands
use STATEJAR_SCOPE, then the scope init saved, then default. add says
what each fact became (stored, held until said again, or declined with its
reason); --json on add, search, list and forget prints the API's
answer as it came. Nothing prints the key.
Status and limits
- Tested: the client's unit tests (HTTP mocked with respx), clean
installs of the wheel on CPython 3.10 and 3.12 / Linux (with and without
--pre), and end-to-end runs of the installed 0.7.0 wheel — the client and everystatejarcommand — against a StateJar server run locally (rules tier, SQLite). The hosted API (api.statejar.com) is not exercised by this package's automated tests. - What the service extracts is the service's behaviour, not this client's. Extraction can misread a sentence. The service's measured figures, with their set sizes and limits, are on https://statejar.com/about; no accuracy figure is claimed in this package.
Quickstart
Get a key on the API Keys page of the console
(keys look like sj_live_…). Then:
from statejar import StateJar
sj = StateJar(api_key="sj_live_...", session_tag="my-app")
turn = sj.turn("My name is Meera Nair and I prefer email")
turn["memory_context"] # prompt-ready system message for YOUR model
memory_context goes into your own LLM call as the system message, with
the user's text as the user message. With OpenAI, for example:
from openai import OpenAI
client = OpenAI() # reads OPENAI_API_KEY — never sent to StateJar
reply = client.chat.completions.create(
model="gpt-4o-mini", # the example defaults to this via OPENAI_MODEL
messages=[
{"role": "system", "content": turn["memory_context"]},
{"role": "user", "content": "Book my delivery"},
],
)
print(reply.choices[0].message.content)
That is the whole integration.
Statements without questions
For a message that needs no answer, skip retrieval entirely:
turn = sj.turn("Budget is under 25000 and the deadline is 20 September", ask=False)
# one request made; turn["memory_context"] is None
Working with the turn payload
turn["handle"] # the state handle this turn produced
turn["declined"] # values extraction refused, with reasons (e.g. a
# quantity offered to a money field) — never guessed
turn["subset_keys"] # exactly which fields were disclosed, e.g. ["facts.name"]
turn["retrieval_mode"] # field_match | intent_map | full_state | …
turn["audit_id"] # the disclosure is audited; replay it from the console
Lower-level access
stored = sj.ingest("I'm from Pune") # full ingest response
got = sj.recall("Where am I from?", audit=False) # subset + metadata;
# audit=True pins the
# disclosure to the trail
recall(audit=True) writes the disclosure to the server-side audit trail, so
you can prove later what was sent — the same trail the console's Audit page
shows. turn() audits by default; turn(text, audit=False) skips it.
API
| Method | Endpoint | Returns |
|---|---|---|
ingest(text, *, review=False, wait=True, wait_timeout=600, poll_interval=2, background=False) |
POST /memory/ingest |
handle, parent_handle, stored, state, conflicts, extraction_*, confirmations, and extraction from an extraction-v3 server; the job (job_id, status, status_url) with wait=False on a long message or with background=True |
ingest_job(job_id) |
GET /memory/ingest/jobs/{job_id} |
status (queued, running, done, failed) and, when done, result |
wait_for_job(job_id, *, wait_timeout=600, poll_interval=2) |
the same, polled | the job's result: the body a direct ingest returns |
confirm(confirmation_id, accept=True) |
POST /memory/confirm |
status (confirmed or rejected), stored, and the new version's handle when accepted |
recall(query, audit=False) |
POST /memory/query |
memory_context, subset, handle_used, metadata, audit_id |
turn(text, ask=True, audit=True, background=False) |
both, ingest first (recall first with background=True) |
all of the above, plus declined, subset_keys, retrieval_mode, extraction; with background=True, ingest_job and pending_ingest |
A long message (over 3,000 characters on an extraction-v3 server) is read in
the background: ingest waits for it and returns the same body a short
message gets, or raises StateJarJobTimeout (its job_id names the job, which
keeps running) after wait_timeout seconds.
handle and handle_used are None while a session has no stored facts.
Auth is sent as X-API-Key; use one session_tag per conversation thread.
The client holds a connection pool — close it, or use it as a context manager:
with StateJar(api_key="sj_live_...", base_url="http://localhost:8000/api/v1") as sj:
sj.turn("I prefer email")
How it works
Every turn is two API calls, in this order, then yours:
- Ingest —
POST /memory/ingestcommits the message's facts: extracted, canonicalized, sealed into SHA-256 content-addressed state. - Recall —
POST /memory/queryreturns the stored fields the question needs, formatted asmemory_context. While a session's state is small (under the service's threshold) the whole state is returned instead —metadata.retrieval_modesays which. - Your LLM call —
memory_contextas the system message. Your provider, your key, your code; StateJar is not in it.
Two guarantees live in that ordering:
- BYOK — your key stays yours. The provider key is used inside your process, in step 3, and is never sent to StateJar. No transcript is stored either: the server sees one message at a time and keeps the facts it extracts, not the message.
- Ingest commits before recall runs, so the context you send already
contains the turn that asked the question. Reversing the order retrieves
state from before that message existed — and the failure is invisible,
because you still get a fluent answer, just one built on stale memory.
turn()gets the order right by construction; callingest()andrecall()yourself only when you have a reason to.
Reply first, update memory right after
On a server that reads messages with its own model (extraction v3), reading a
message takes seconds to minutes on a CPU, and in the order above every reply
waits for it. turn(text, background=True) turns the order around:
- Recall for
text— the server first waits, a few seconds at most, for the session's previous message to be stored. - Ingest in the background — the message is sent with
"async": trueand read after this returns;ingest_jobnames the job. - Your LLM call at once. Your model reads
textitself, so a fact stated in it is used in this reply; the next turn's recall finds it stored.
When the previous message was still being read after the wait, the context
comes from the version before it and says so: pending_ingest is True. A
session's messages are always stored in the order they were sent.
Confirm before store
When a message carries a value the server is unsure of — "i have 5000 rs"
(money with no stated purpose), "under 50000" (no currency), "my slary was
80000rs" (a concept that exists only because a typo was corrected) — nothing is
stored for it. A server on the rules tier returns a question at once. A server
running extraction v3 (the hosted service) asks no question unless you pass
review=True: a fact it is unsure of is held until it is said again
(extraction["pending"]) or declined with its reason, and review=True turns
the held ones into questions. A rules-tier server accepts review and ignores
it. The answer below is the rules tier's:
r = jar.ingest("go goa i have 5000rs ruppes", review=True)
r["confirmations"]
# [{"id": 12, "path": "constraints.budget.max",
# "value": {"value": 5000, "currency": "INR"},
# "reason": "funds_on_hand", "question": "Is ₹5,000 your budget?"}]
jar.confirm(12) # yes: a new version with the budget; jar.confirm(12, accept=False) discards it
A pending value is never part of a handle and never sent to a model.
Errors
Everything raised is a StateJarError:
from statejar import (StateJar, StateJarError,
StateJarAuthError, StateJarConnectionError)
try:
turn = sj.turn("hi")
except StateJarAuthError: # HTTP 401 — bad/revoked key
...
except StateJarConnectionError: # unreachable host or timeout — nothing was
... # stored, so retrying ingest is safe
except StateJarError as e: # anything else; e.status_code, e.body
print(e.status_code, e.body) # (decoded JSON or text) and e.response_text
StateJarJobTimeout (a StateJarError) is raised when a long message is
still being read after wait_timeout; e.job_id names the job, which keeps
running — read it later with ingest_job(). A background reading that failed
raises StateJarError with the job as e.body.
A missing api_key raises at construction as a StateJarAuthError that is
also a ValueError, so code written against either earlier client still
catches it.
Pointing at a local instance
sj = StateJar(api_key="sj_live_...", base_url="http://localhost:8000/api/v1")
Development
cd sdk && pip install -e ".[dev]" && pytest # ".[test]" is the same set
The tests mock HTTP with respx at the httpx client seam — no network, no server needed.
Copyright (c) 2026 StateJar. All rights reserved. Rights not granted by the licence are reserved; see section 3 of LICENSE.
Metadata
Release files for statejar 0.7.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 |
|---|---|---|---|---|
| statejar-0.7.0.tar.gz | 34.3 kB | With provenance | Details for statejar-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| statejar-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for statejar-0.7.0-py3-none-any.whl |
Total release size: 61.3 kB
Release files / statejar-0.7.0.tar.gz
| Download URL | statejar-0.7.0.tar.gz |
|---|---|
| Size | 34.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8bc56a4d52c39d4cdad7b2dc7a898f71b0971850529e286ba46a6c77d435de8a
|
|
BLAKE2b-256 checksum How to use checksums |
6baf38971668506ba43865f2c279fd70526779e5406a25d61c970e2e1695ca6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logRelease files / statejar-0.7.0-py3-none-any.whl
| Download URL | statejar-0.7.0-py3-none-any.whl |
|---|---|
| Size | 26.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0e370d6a3003b58af4a31d0d41ea59b56da2db1de249e4ee185a4c7c6cf5804
|
|
BLAKE2b-256 checksum How to use checksums |
f5af9b21ec7564fa23ee5c641da7cbc0a60f5139ae6abea60fd501ce42867d48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logSecurity for statejar 0.7.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for statejar-0.7.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logA 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.