Working with contexts
A context is a running instance of an application with its own state,
belonging to a group. This guide covers the context lifecycle and calling into
an app. Every method returns a plain Python value (usually a dict or list).
Creating a context
Section titled “Creating a context”A context is created inside a group, so you need a group_id (from a namespace
or group — see namespaces and groups) and an
installed application (see applications and blobs):
result = client.create_context( application_id="<application-id>", group_id="<group-id>", params='{"init": true}', # optional: initialization params (a string) service_name=None, # optional)params and service_name are optional. params is passed through as the
application’s initialization payload.
To create a fresh identity for use in a context:
identity = client.generate_context_identity()Inspecting contexts
Section titled “Inspecting contexts”client.list_contexts() # all contexts on the nodeclient.get_context("<context-id>") # one context's metadataclient.get_context_storage("<context-id>") # storage/state infoclient.get_context_identities("<context-id>") # identities in the contextclient.get_context_client_keys("<context-id>") # client keysContext IDs are validated: an invalid ID raises ValueError.
Joining and leaving
Section titled “Joining and leaving”client.join_context("<context-id>") # join via group membershipclient.leave_context("<context-id>") # local leave — stops sync, reversibleleave_context is a local operation: it stops syncing the context on this
node and disarms auto-follow, without publishing anything. Calling
join_context again reverses it.
To remove a context entirely:
client.delete_context("<context-id>") # requester optionalclient.delete_context("<context-id>", requester="<public-key>")Syncing state
Section titled “Syncing state”client.sync_context("<context-id>") # sync one contextclient.sync_all_contexts() # sync every context on the nodeFor a context that can no longer replay its history (for example a missing
bytecode blob), resync_context adopts a peer’s full-state snapshot. It is
destructive — pass force=True when the context still holds local heads:
client.resync_context("<context-id>", force=True)Executing application functions
Section titled “Executing application functions”Call a method on the app running in a context over JSON-RPC. Arguments are a JSON string:
result = client.execute_function( context_id="<context-id>", method="set", args='{"key": "greeting", "value": "hello"}',)The trailing executor_public_key argument is accepted for backward
compatibility but ignored — the node auto-resolves the context’s owned identity.
Invalid JSON in args raises ValueError.
To point a context at a different application version:
client.update_context_application( context_id="<context-id>", application_id="<new-application-id>", executor_public_key="<public-key>",)Context aliases
Section titled “Context aliases”Give a context (or a context identity) a human-friendly alias:
client.create_context_alias("my-context", "<context-id>")client.create_context_identity_alias("<context-id>", "alice", "<public-key>")
client.lookup_context_alias("my-context") # resolve without side effectsclient.resolve_context_alias("my-context") # resolve to the valueclient.list_context_aliases() # all context aliasesclient.delete_context_alias("my-context")The API reference lists the full alias surface,
including the identity- and application-scoped variants. There is also a
backward-compatible create_alias_generic(alias, value, scope=None) helper that
treats value as a context id — prefer the typed methods above for new code.