NSPSession is the high-level interface for interacting with a single attached application. It bundles the process ID and app identifier together so you never have to pass them around manually. Every state read, action call, and streaming subscription goes through a session.
Creating a Session
You create a session by calling one of theattach methods on NSPClient:
Session Properties
Reading State
Typed Accessor Methods
Use the typed getters to read individual values from the cached state. These methods never raise — they return the provided default (orNone) when a key is missing:
Prefix Query
Retrieve all state keys that share a common prefix as a flat dictionary:Accessing the Raw State Object
For operations not covered by the typed helpers, work directly with theSubstrateState object:
Cached State vs. Fresh State
session.state holds the last snapshot received from the daemon. It does not automatically update. You have two ways to get newer data:
session.refresh()
Fetches the latest cached snapshot from the daemon (~1 ms). Use this after an action or when you need a more recent read without triggering a full probe.
session.refresh(fresh_probe=True)
Forces the daemon to run a new probe cycle before returning (50 ms–90 s). Use this only when you need a guaranteed up-to-date reading.
Executing Actions
execute() Method
The action name, as it appears in
session.actions.Key-value pairs matching the action’s parameter schema.
Enable post-action verification. Automatically set to
True for IrreversibleWrite actions — you cannot set this to False for irreversible actions without raising NSPIrreversibleNotConfirmedError.A JavaScript expression evaluated against the post-action state. If it returns falsy, the action is marked as failed.
How long (in milliseconds) to poll for state settlement after the action runs. Range: 100–30000.
When
True, refreshes session.state automatically after the action completes.Usage Examples
ActionResponse Fields
True if the action ran and (when enabled) verification passed.Total round-trip time from dispatch to response, in milliseconds.
The raw return value of the action as reported by the runtime.
null for actions that return nothing (UI interactions, void methods).Present when
verify=True. Contains satisfied: bool, actual_value, expression, evaluated_at, and latency_ms. See VerificationResult.Human-readable failure description when
success is False.