Skip to content

Stores

A store keeps channels and everything recorded in them: events, subscription cursors, artifacts, and snapshots. Every store has the same methods, so code written against one store runs against any other. SSSN ships one storage backend, LocalStore: a SQLite file and a folder of artifact files, with no server to run and nothing to configure.

local_store.py
from sssn import LocalStore

store = LocalStore(".lllm/network")  # (1)!
store.create_channel({"name": "readings"})
store.append_event({"channel": "readings", "payload": {"celsius": 21.5}})
store.create_subscription("readings", subscription_id="dashboard")
print(len(store.pull_subscription("dashboard")))
#> 1
print(sorted(path.name for path in store.root.iterdir()))  # (2)!
#> ['artifacts', 'network.sqlite']

restarted = LocalStore(".lllm/network")  # (3)!
print([channel.name for channel in restarted.list_channels()])
#> ['readings']
print(restarted.get_subscription("dashboard").cursor)
#> 1
  1. The folder is created if it does not exist. LocalStore() with no argument uses .lllm/network in the working directory, the folder the sssn and lllm network commands use by default.
  2. network.sqlite holds channels, events, subscriptions, snapshots, and artifact records. artifacts/ holds the artifact bytes.
  3. A second store object on the same folder, in this process or another, sees the same data, subscription cursor included. Nothing is kept in the object: every call opens its own SQLite connection and commits before it returns.

Because all state is in the folder, a worker can stop and start again, a command-line tool can inspect what a program wrote, and a test can create a store in a temporary folder and throw it away.

Where the data lives

.lllm/network/
├── network.sqlite        # channels, events, subscriptions, snapshots,
│                         # and artifact records
└── artifacts/
    └── 2cf24dba5fb0a...  # artifact bytes, named by their SHA-256

LocalStore(root=".lllm/network") takes one argument, the folder. A relative path is relative to the working directory, and ~ is expanded. A root that is empty or padded with spaces raises ValueError.

Attribute Value
root The store folder, as an absolute path
db_path root / "network.sqlite"
artifacts_dir root / "artifacts"

To start over, delete the folder. To back up or move a store, copy the folder while no process is writing to it.

An event's cursor is its row number in the SQLite file. Cursors increase across the whole store, so within one channel they are ordered but can have gaps; resume from the last cursor you read instead of adding one (Reading events). Artifact files are named by the SHA-256 of their bytes, so writing the same bytes twice makes two artifact records that share one file (Artifacts and snapshots).

How values are stored

Payloads, metadata, and snapshot values are stored as JSON. Pydantic models are dumped, tuples become lists, dates become strings, and dict keys are sorted:

stored_values.py
from datetime import date

from pydantic import BaseModel

from sssn import LocalStore


class Reading(BaseModel):
    sensor: str
    celsius: float


store = LocalStore(".lllm/network")
store.create_channel({"name": "readings"})
event = store.append_event(
    {
        "channel": "readings",
        "payload": Reading(sensor="boiler", celsius=64.0),
        "metadata": {"day": date(2026, 11, 18), "tags": ("hot", "east")},
    }
)
print(event.payload)  # (1)!
#> {'celsius': 64.0, 'sensor': 'boiler'}
print(event.metadata)
#> {'day': '2026-11-18', 'tags': ['hot', 'east']}
print(store.get_event(event.id) == event)
#> True
  1. append_event returns the event as it was stored, which is what get_event and other processes get. Every write returns its record that way, a snapshot's value and every record's metadata included.

What is stored is exactly the JSON that Pydantic writes for the value. A value Pydantic cannot write, such as an arbitrary object, raises InvalidPayloadError and nothing is written. So does a NaN or an infinite number in a plain value, at the top level or in a dict, list, tuple, or set, since JSON cannot represent it. Inside a Pydantic model, the model's own JSON serialization decides: Pydantic writes NaN and infinity as null by default, and a model can choose otherwise with ser_json_inf_nan="strings" (Pydantic 2.8+), a validator, or a serializer. A string value holding a lone surrogate, such as a file name decoded with surrogateescape, is stored as a JSON escape and read back intact, with four exceptions. A dict key holding one is refused, as in sssn 0.2.0. Pydantic replaces each one in a model's typed dict key with three U+FFFD characters, one per UTF-8 byte. A high surrogate directly followed by a low one comes back as the single character the pair encodes (U+D83D U+DE00 becomes U+1F600), as in 0.2.0. And a value holding one is written the way 0.2.0 wrote it. There, inside a model, a NaN or infinity that Pydantic writes as a float (a float field, or the values of a list[float] or dict[str, float] field) is refused, while one it infers (an Any field, or a field typed as a bare dict or list or with Any values) is written as null; in a model that writes NaN as strings, both are refused. A NaN in a plain value is refused as always. Remote stores send values in the same JSON form and raise the same error before sending. Readers get plain JSON data, so validate it back into your model where you need one, as a tactic does with its input model.

The store interface

These are all the methods of a store. LocalStore and RemoteStore have all of them with the same arguments, and AsyncRemoteStore has them as coroutines:

Resource Methods Guide
Channels create_channel, list_channels, get_channel Channels and events
Events append_event, query_events, get_event Channels and events
Subscriptions create_subscription, get_subscription, pull_subscription Subscriptions
Artifacts write_artifact, read_artifact, get_artifact Artifacts and snapshots
Snapshots put_snapshot, get_snapshot Artifacts and snapshots

SSSN has no base class for stores. Everything that takes a store, such as TacticProcessor, the HTTP server, and your own functions, calls only these methods, so a function written and tested against a LocalStore works on a store served from another machine. The store server is built the same way: create_app turns each method into a route, and RemoteStore turns each route back into the method (Over HTTP). The server calls a synchronous store's methods from a thread pool, possibly in several threads at once, so a store you write must be thread-safe, as LocalStore is, or async.

Errors are the same on every store too. A remote store raises the error the server reported, so except ChannelExistsError catches a taken name from a LocalStore and from a served store alike:

any_store.py
import asyncio

import httpx

from sssn import (
    AsyncRemoteStore,
    ChannelExistsError,
    LocalStore,
    RemoteStoreError,
    create_app,
)

store = LocalStore(".lllm/network")
store.create_channel({"name": "readings"})
remote = AsyncRemoteStore(
    "http://store.internal:7700",
    transport=httpx.ASGITransport(app=create_app(store)),  # (1)!
)

try:
    store.create_channel({"name": "readings"})
except ChannelExistsError as error:
    print("local:", error)
    #> local: Channel already exists: readings


async def main():
    try:
        await remote.create_channel({"name": "readings"})
    except ChannelExistsError as error:  # (2)!
        print("remote:", error.status_code, error.message)
        #> remote: 409 Channel already exists: readings
        print(isinstance(error, RemoteStoreError))
        #> True


asyncio.run(main())
  1. Only for this example: requests go to an app in this process that serves store. Against a running server, pass the URL alone (Over HTTP).
  2. The server answers 409 with the error's name, and the remote store raises it as a ChannelExistsError. It is also a RemoteStoreError, with the HTTP status_code and the server's message.

Concurrency

Several processes can share one store folder, such as a store server and a worker on the same machine. Each call opens its own SQLite connection, so one LocalStore object can also be shared between threads.

  • Writes are serialized. SQLite lets one writer commit at a time, and each write is one short transaction. A call that waits more than SQLite's 5-second busy timeout for another process raises StoreBusyError, a NetworkError, and changes nothing, so it is safe to retry. From a LocalStore it is also the sqlite3.OperationalError that earlier versions raised. A served store answers it with a 503.
  • Pulls never share or skip events. pull_subscription reads and builds its events, then moves the cursor past them only if no other pull has moved it meanwhile, and reads again if one has. Processes pulling the same subscription at once get different events. On a LocalStore, a pull that fails before it returns leaves its events pending. Over HTTP the server moves the cursor before the response arrives, so a pull whose response is lost does not: plain pulls are at most once. Reading ahead with query_events and acknowledging with a pull are two steps, so a worker that does that needs a subscription of its own (Several consumers).
  • Share over HTTP, not over a network drive. SQLite's file locking is unreliable on network file systems. To share a store between machines, serve it and point the others at its URL.

Durability

  • A write that returned is on disk. Every method commits before it returns, so once append_event returns, the event survives a crash of the process that wrote it.
  • An artifact record always has its bytes. write_artifact writes the file first and then commits the record, so a process that stops midway can leave a file without a record, never a record without its file. A file appears whole, in one step, and bytes the store already holds are not written again, so a reader never gets part of a file.
  • Nothing is deleted. A store has no delete methods. put_snapshot replaces a snapshot, but events, artifacts, channels, and subscriptions stay until you delete the folder.

Next steps