Skip to content

o6.namespaces

o6.namespaces

Classes

RemoteNamespaces

Discovered server-side namespaces accessible after :meth:discover.

Call :meth:discover on a connected client to browse and build types for every namespace on the remote server that is not already loaded locally. Each discovered :class:Namespace is then stored as an attribute keyed by its short_name.

Functions
get_namespace
get_namespace(key)

Look up a discovered Namespace by short name, URI, or namespace index.

Raises KeyError if no matching Namespace is found.

discover
discover()

Discover and register custom DataTypes from a connected server.

Browses the server's DataType hierarchy, reads DataTypeDefinition attributes, and builds Python type classes for every namespace that is not already loaded in this context.

Must be called on a client that is already connected. Returns a list of newly created Namespaces (one per discovered namespace).

Namespaces

Manages custom OPC UA DataType namespaces for a client, server, or standalone (ownerless) context. Used it to register pre-built custom DataType namespaces or load NodeSet2 XML files before the client connects.

Type sharing semantics

  • Clients share pre-built Namespaces directly — append(namespace) links the same Namespace object (and its Python type classes) into the client. Multiple clients that append() the same pre-built Namespace will share a single set of type objects.
  • Servers always get their own copy — append(namespace) rebuilds types from the saved original NodeIds with the server's actual namespace indices, producing a distinct Namespace.
  • Types built for a client are therefore not interchangeable with types built for a server (different namespace index spaces).
Important

All append() calls on a client must happen before connect(); attempting to load after the client is connected raises RuntimeError.

Use pre-built namespaces when available:

client.ns.append(o6.ns.di) # or
server.ns.append(o6.ns.di)

This links the global prebuilt o6.ns.di namespace and reuses the same type objects across clients.

For custom or external nodesets, load XML definitions first:

client.ns.load("path/to/custom_nodeset2.xml", short_name="MyTypes")

This parses the nodeset XML, builds Python type classes, and registers the namespace URI in the client's local table.

Functions
get_namespace
get_namespace(key)

Look up a loaded Namespace by short name, URI, or namespace index.

Raises KeyError if no matching Namespace is found.

append
append(ns, short_name=None)

Append a namespace to the array (give it an index) and make it available under the shortname.

On a client Registers the Namespace's canonical namespace URIs in the client's local table and links the pre-built capsules. The same Namespace (and type objects) is reused — no rebuild. All append() calls must precede any manual client.add_namespace() calls; otherwise the canonical index slots may already be occupied and a ValueError is raised.

On a server Creates a copy of the Namespace, restores its original (pre-remap) NodeIds, remaps them to the server's actual namespace indices, rebuilds the types, and links the new capsules. The returned Namespace is distinct from the input.

Raises ValueError if the namespace URI is already loaded in this context.

load
load(nodeset2xml, short_name=None)

Load a nodeset from an XML file path. Returns the list of previously unknown namespaces from the nodeset that have been appended. Note that loading a nodeset might also add nodes to existing namespaces.

Parse the NodeSet2 XML, build Python type classes, and (if an owner is set) register them with the owner. The returned Namespace stores the built capsules and original NodeIds so it can later be passed to other clients/servers via append(namespace).

Raises ValueError if the namespace URI is already loaded in this context.