Python · recipe
Browse an OPC UA address space in Python
Start at the Objects folder and walk children. Read each node's BrowseName and NodeClass as you go, because a folder of tags and a typed machine object look identical until you check. Filter by reference type rather than pulling everything.
| Stack | asyncua (FreeOpcUa/opcua-asyncio) |
|---|---|
| Version | 2.0.1 |
The code
import asyncio
from asyncua import Client, ua
async def walk(node, depth=0, limit=2):
for child in await node.get_children():
bn = await child.read_browse_name()
nc = await child.read_node_class()
print(" " * depth + f"{bn.NamespaceIndex}:{bn.Name} [{nc.name}] {child.nodeid.to_string()}")
if depth < limit:
await walk(child, depth + 1, limit)
async def main():
async with Client(url="opc.tcp://opcua.umati.app:4840") as client:
await walk(client.nodes.objects)
asyncio.run(main())
What it prints
0:Server [Object] i=85
0:ServerStatus [Variable] i=2256
3:Machines [Object] ns=3;i=1001
4:MachineTool_1 [Object] ns=4;i=5001
2:Identification [Object] ns=2;i=6001
4:Production [Object] ns=4;i=6100
Notes
- `client.nodes.objects` is the Objects folder. There is also `client.nodes.root`, `types` and `server`.
- Check `read_type_definition()` on anything that looks like a machine. If it returns MachineToolType or a PackML type, your integration is a mapping job rather than a tag hunt.
- Do not browse recursively on every startup in production. Browse once, store namespace URI plus identifier, and use browse paths afterwards.
- The `uals` CLI does this without any code: `uals -u opc.tcp://opcua.umati.app:4840 -l 3`.
What breaks first
A recursive browse on a large server runs for minutes or exhausts the server's continuation points
Limit depth, filter on reference type and NodeClass, and prefer TranslateBrowsePathsToNodeIds once you know the model.
BadNoContinuationPointsLimit depth, filter on reference type and NodeClass, and prefer TranslateBrowsePathsToNodeIds once you know the model.
Other recipes in this stack
Concepts on this page
Last verified 7 September 2026 against OPC UA 1.05.07. OPC UA Connect is an educational resource and is not affiliated with the OPC Foundation.