Python API
Everything here is importable from sssn, as in from sssn import LocalStore. The guide pages explain how the pieces fit; come here for exact parameters and defaults.
Channels and records
Channel
Bases: BaseModel
A named semantic data interface.
Literal
Literal(self, *parameters)
Special typing form to define literal types (a.k.a. value types).
This form can be used to indicate to type checkers that the corresponding variable or function parameter has a value equivalent to the provided literal (or one of several literals)::
def validate_simple(data: Any) -> Literal[True]: # always returns True
...
MODE = Literal['r', 'rb', 'w', 'wb']
def open_helper(file: str, mode: MODE) -> str:
...
open_helper('/some/path', 'r') # Passes type check
open_helper('/other/path', 'typo') # Error in type checker
Literal[...] cannot be subclassed. At runtime, an arbitrary value is allowed as type argument to Literal[...], but type checkers may impose restrictions.
Event
Bases: BaseModel
Timestamped semantic record in a channel.
Artifact
Bases: BaseModel
Larger payload stored by reference.
Snapshot
Bases: BaseModel
Latest state or materialized view.
Subscription
Bases: BaseModel
Consumer cursor over one channel.
Stores
LocalStore
LocalStore(root: str | Path = '.lllm/network')
Boring local SQLite/filesystem backend.
put_snapshot
put_snapshot(snapshot: Snapshot | Mapping[str, Any] | str | None = None, value: Any = None, *, name: str | None = None, channel: str | None = None, timestamp: float | None = None, schema: str | None = None, source_event_id: str | None = None, metadata: dict[str, Any] | None = None) -> Snapshot
Write a snapshot given as a model, a dict, or a name and value.
put_snapshot(snapshot) takes a Snapshot or a dict of snapshot
fields; put_snapshot(name, value, ...) stores value exactly as
given, unless it is a Snapshot whose fields are used under that
name. snapshot= and name= also work as keywords. Field
arguments that are not None override, and None fields are unset.
The remote clients take the same arguments.
Serving a store
create_app
create_app(store: Any = None, *, custom_endpoints: Sequence[Callable[..., Any]] = ())
Create a FastAPI app exposing a store's portable API.
store is any store, synchronous or async: a LocalStore (without
one, the app opens LocalStore()), an AsyncRemoteStore in front of
another server, or another object with the store methods. Synchronous
store methods and custom endpoint handlers run in a thread pool,
possibly at the same time, so they must be thread-safe; async ones are
awaited on the event loop.
endpoint
Decorator namespace for custom SSSN store/channel endpoints.
create_app binds handler parameters by name: store receives the
store, body the parsed JSON body (None for GET, DELETE, or a body
that is not JSON), and any other parameter the path parameter of the same
name. A params parameter that is not a path parameter receives the
query parameters as a dict of strings (the last value wins for
repeated keys).
StoreEndpointSpec
dataclass
StoreEndpointSpec(method: HttpMethod, path: str, name: str, scope: EndpointScope = 'store', description: str = '', tags: tuple[str, ...] = tuple())
Literal
Literal(self, *parameters)
Special typing form to define literal types (a.k.a. value types).
This form can be used to indicate to type checkers that the corresponding variable or function parameter has a value equivalent to the provided literal (or one of several literals)::
def validate_simple(data: Any) -> Literal[True]: # always returns True
...
MODE = Literal['r', 'rb', 'w', 'wb']
def open_helper(file: str, mode: MODE) -> str:
...
open_helper('/some/path', 'r') # Passes type check
open_helper('/other/path', 'typo') # Error in type checker
Literal[...] cannot be subclassed. At runtime, an arbitrary value is allowed as type argument to Literal[...], but type checkers may impose restrictions.
Remote stores
RemoteStore
RemoteStore(base_url: str, *, timeout: float | None = 30.0, transport: Any = None, headers: Mapping[str, str] | None = None, auth: Any = None)
Synchronous HTTP client for the portable SSSN API.
headers are sent with every request, such as
{"Authorization": "Bearer ..."} for a server behind a token check,
and auth takes an httpx authentication, such as httpx.BasicAuth.
transport is a synchronous httpx transport, such as
httpx.MockTransport or one that forwards to a TestClient in
tests (httpx.ASGITransport is async, for AsyncRemoteStore).
put_snapshot
put_snapshot(snapshot: Snapshot | Mapping[str, Any] | str | None = None, value: Any = None, *, name: str | None = None, channel: str | None = None, timestamp: float | None = None, schema: str | None = None, source_event_id: str | None = None, metadata: dict[str, Any] | None = None) -> Snapshot
Write a snapshot given as a model, a dict, or a name and value.
Takes the same arguments as LocalStore.put_snapshot:
put_snapshot(snapshot) with a Snapshot or a dict of snapshot
fields, or put_snapshot(name, value, ...), which stores value
exactly as given unless it is a Snapshot whose fields are used
under that name. snapshot= and name= also work as keywords.
Field arguments that are not None override, and None fields are
unset.
AsyncRemoteStore
AsyncRemoteStore(base_url: str, *, timeout: float | None = 30.0, transport: Any = None, headers: Mapping[str, str] | None = None, auth: Any = None)
Async HTTP client for the portable SSSN API.
headers are sent with every request, such as
{"Authorization": "Bearer ..."} for a server behind a token check,
and auth takes an httpx authentication, such as httpx.BasicAuth.
transport is an async httpx transport, such as
httpx.ASGITransport in tests.
put_snapshot
async
put_snapshot(snapshot: Snapshot | Mapping[str, Any] | str | None = None, value: Any = None, *, name: str | None = None, channel: str | None = None, timestamp: float | None = None, schema: str | None = None, source_event_id: str | None = None, metadata: dict[str, Any] | None = None) -> Snapshot
Write a snapshot given as a model, a dict, or a name and value.
Takes the same arguments as LocalStore.put_snapshot:
put_snapshot(snapshot) with a Snapshot or a dict of snapshot
fields, or put_snapshot(name, value, ...), which stores value
exactly as given unless it is a Snapshot whose fields are used
under that name. snapshot= and name= also work as keywords.
Field arguments that are not None override, and None fields are
unset.
RemoteStoreError
RemoteStoreError(status_code: int, *, error_type: str | None = None, message: str | None = None, detail: Any = None)
Bases: NetworkError
Raised when an SSSN HTTP server returns an error.
When the server reports one of the store errors, such as
ChannelNotFoundError, the error is also an instance of that class, so
except ChannelNotFoundError catches it from a remote store as it does
from a LocalStore.
Processing
TacticProcessor
TacticProcessor(tactic: Tactic[Any, Any], store: Any, *, source: str, sink: str | None = None, consumer: str | None = None, kind: str | None = None, output_kind: str = 'result', errors: Literal['raise', 'record'] = 'raise')
Feed a channel's events through a tactic.
source events are read through a named subscription, so a processor
resumes where it stopped across restarts. consumer names that
subscription and defaults to "<tactic name>-<source>-processor", or
"<tactic name>-<source>-<kind>-processor" with a kind filter, so
one tactic can process several channels. If those names contain
whitespace, pass consumer explicitly.
Events are processed one at a time and at least once: the tactic runs on
an event and its output is appended to sink before the event is
acknowledged (the subscription cursor moves past it). errors decides
what a failure in the tactic or in writing its output does. With
errors="raise" the failing event stays unacknowledged and the
exception propagates, so the next call runs that same event again before
any event behind it. With errors="record" the failure is written to
sink as a kind="error" event, the event is acknowledged, and
processing continues; without a sink it acts like "raise". A
tactic can see an event more than once (after a failure or an interrupted
run), so it should tolerate repeats, and sink can then hold more than
one output for that event.
Run one worker per consumer; the guarantees above assume it. Workers
sharing a consumer can process the same event twice, and can lose one:
when another worker acknowledges the event this processor ran, this
processor's acknowledgement covers the next pending event instead, which
it runs right away, even past limit. That event is already
acknowledged, so with errors="raise" a failure loses it.
process
process(limit: int | None = None) -> list[Event | Any]
Process pending events; return sink events (or raw outputs without a sink).
Each event is peeked at the subscription cursor, run through the
tactic, written to sink, and only then acknowledged. limit caps
the number of results, outputs and recorded errors alike. This method
needs a synchronous store; use :meth:aprocess with async stores such
as :class:~sssn.AsyncRemoteStore.
aprocess
async
aprocess(limit: int | None = None) -> list[Event | Any]
Async variant of :meth:process using tactic.arun.
It works with synchronous and asynchronous stores, with the same at-least-once semantics.
Packages and refs
channel_resource
channel_resource(channel: Channel, *, custom_endpoints: Sequence[Callable[..., Any]] = ()) -> dict[str, Any]
Return manifest/card-friendly metadata for a channel.
snapshot_resource
snapshot_resource(snapshot: Snapshot, *, description: str = '', custom_endpoints: Sequence[Callable[..., Any]] = ()) -> dict[str, Any]
Return manifest/card-friendly metadata for a snapshot.
ChannelRef
dataclass
ChannelRef(value: str)
A stable lllm://org/package/channels/name or snapshots ref.
ChannelResolver
ChannelResolver(*, root: str | Path = '.')
Resolve channel refs to local stores or HTTP clients.
from_text
classmethod
from_text(text: str, *, root: str | Path | None = None) -> 'ChannelResolver'
Parse config text in memory; relative paths resolve against root.
ResolvedChannelRef
dataclass
ResolvedChannelRef(ref: str, resource_kind: str, name: str, url: str | None = None, store: str | None = None, path: str | None = None, metadata: dict[str, Any] = dict())
A concrete local binding for a channel ref.
ChannelRefError
Bases: NetworkError, ValueError
Raised when an SSSN lllm:// ref or binding is invalid.
Errors
NetworkError
Bases: RuntimeError
Base SSSN error.
ChannelExistsError
Bases: NetworkError
Raised when creating a duplicate channel.
ChannelNotFoundError
Bases: NetworkError
Raised when a channel does not exist.
EventExistsError
Bases: NetworkError
Raised when appending an event whose id already exists.
EventNotFoundError
Bases: NetworkError
Raised when an event does not exist.
ArtifactNotFoundError
Bases: NetworkError
Raised when an artifact does not exist.
SnapshotNotFoundError
Bases: NetworkError
Raised when a snapshot does not exist.
SubscriptionExistsError
Bases: NetworkError
Raised when creating a conflicting duplicate subscription.
SubscriptionNotFoundError
Bases: NetworkError
Raised when a subscription does not exist.
InvalidPayloadError
Bases: NetworkError
Raised when payloads, cursors, or request values are invalid.
StoreBusyError
Bases: NetworkError
Raised when another connection holds the store's lock for too long.
The call did nothing, so it is safe to try again.