Skip to main content
A Session (returned as NSPSession) is the workhorse object in any NSP agent. You get one by calling client.attach() with an app name, and from that point on you never pass PIDs or app IDs around — the session carries that context internally. It caches the app’s state locally, gives you typed accessors for individual keys, enforces action reversibility rules before requests leave Python, and exposes a WebSocket stream so you can react to changes in real time.

Creating a session

Call client.attach() with the app’s name. Fuzzy matching is on by default, so partial names work.

Session properties

Reading state

Typed accessors

The typed helpers (get_str, get_int, get_bool) read from the locally cached state. They never raise on a missing key — they return the default value you provide (or None if you omit it).

Accessing the full state object

For bulk reads or when you need metadata about the snapshot itself, use session.state directly.

Refreshing state

State is cached locally from the last probe cycle. Call refresh() to pull the latest cached snapshot from the daemon (~1ms), or pass fresh_probe=True to force a new probe cycle.

Iterating available actions

session.actions is a dict[str, ActionSchema]. Iterate it to inspect what operations the app supports before deciding which one to call.
A typical output for Gmail looks like:

Executing actions

session.execute(action, parameters, verify, verify_expression, verify_timeout_ms)

Call execute() to invoke any action the app exposes. The SDK checks the action’s reversibility tier and enforces safety rules before sending the request to the daemon. Reversible action — no verification required:
Irreversible actionverify=True and a verify_expression are required. The expression is evaluated against the post-action state; the call fails if it does not evaluate to true within verify_timeout_ms.
The ActionResponse object returned by execute() has these key fields:
Calling execute() on an irreversible_write action without verify=True raises NSPIrreversibleNotConfirmedError immediately, before any network request is made. This is a client-side safety check — it cannot be silenced.

Real-time streaming

Call session.watch() to open a WebSocket stream and receive a StateChangeNotification on every probe cycle that detects a change. See the Streaming page for full details.

Complete example

email_responder.py