Skip to content

Session

Canonical path: o6.server.Session

Root shortcut: o6.Session

Session

A safe proxy for a server session, resolved by NodeId on every use.

Handed to the AccessControl hooks and to server-side read and write callbacks. Nothing native is retained, so holding on to a Session past the session's lifetime is safe: the next operation raises StatusCodeError with BAD_SESSION_ID_INVALID instead of using freed memory.

Session attributes are the OPC UA per-session key/value store, readable by the client through the SessionDiagnostics object.

See The Session proxy.

Attributes

id instance-attribute

id = NodeId(sessionId)

context instance-attribute

context = context

roles property writable

roles

The roles currently granted to this session.

Assigning replaces the whole set, and accepts Role objects or role NodeIds.

Functions

__init__

__init__(server, sessionId, context=None)

Wrap an existing session id. The server creates these, not users.

Parameters:

Name Type Description Default
server Server

The server that owns the session.

required
sessionId NodeId

NodeId of the session.

required
context Any

The context returned by AccessControl.activateSession.

None

get

get(key)

Read one session attribute.

Parameters:

Name Type Description Default
key QualifiedName | str

Attribute name. A plain string is read as namespace 0.

required

Raises:

Type Description
StatusCodeError

The session is gone, or the attribute is not set.

set

set(key, value)

Set one session attribute.

Parameters:

Name Type Description Default
key QualifiedName | str

Attribute name. A plain string is read as namespace 0.

required
value Any

Any value of a registered OPC UA type.

required

Raises:

Type Description
StatusCodeError

The session is gone.

delete

delete(key)

Remove one session attribute.

Parameters:

Name Type Description Default
key QualifiedName | str

Attribute name. A plain string is read as namespace 0.

required

Raises:

Type Description
StatusCodeError

The session is gone, or the attribute is not set.

close

close()

Close this session, cancelling its subscriptions.

Raises:

Type Description
StatusCodeError

The session is already gone.