SDK · Python

OPC UA in Python

asyncua is the maintained Python OPC UA stack: asyncio-native, client and server, with a synchronous wrapper for scripts. It is the fastest way to get data out of an OPC UA server and the right choice for tooling, tests and data engineering. It is not for hard real-time.

Projectasyncua (FreeOpcUa/opcua-asyncio)
Version2.0.1
LicenceLGPL-3
Installpip install asyncua

What to know before you start

  • Python 3.10 or newer. The async API is primary; `asyncua.sync` wraps it for scripts and notebooks.
  • Ships CLI tools that save you writing code at all: uals, uaread, uawrite, uacall, uasubscribe, uadiscover, uahistoryread.
  • LGPL-3, which matters if you are linking it into a closed-source product: check with whoever owns that decision.
  • Tested against Prosys, Kepware, Beckhoff, WinCC and B&R, so interoperability is generally good.
  • The older FreeOpcUa/python-opcua package (import name `opcua`) is deprecated. If you find a tutorial using it, the tutorial is out of date.

Command-line tools it ships

uals  uaread  uawrite  uacall  uasubscribe  uadiscover  uahistoryread

Recipes

The same twelve tasks, in this stack, pinned to the version above. Each one runs against a free public server.

TaskWhat it does
Connect to an OPC UA server in PythonUse asyncua's Client as an async context manager. The context manager opens the secure channel and session on entry and closes bot
Browse an OPC UA address space in PythonStart at the Objects folder and walk children. Read each node's BrowseName and NodeClass as you go, because a folder of tags and a
Read a value from an OPC UA server in PythonRead the whole DataValue, not just the number. It carries a status code and two timestamps, and code that discards them cannot lat
Write a value to an OPC UA server in PythonMatch the node's DataType exactly or the write fails. Read the DataType attribute first, build a Variant of that type, and check t
Subscribe to data changes in PythonCreate a subscription with the publishing interval your consumer actually needs, then add monitored items with their own sampling
Call an OPC UA method in PythonCall the method on its parent object, passing input arguments positionally. Output arguments come back as a list. A method that fa
Set up OPC UA certificates in PythonGenerate a certificate whose SAN contains both the DNS name you will dial and your ApplicationUri as a URI entry, then point the c
Decode custom structures in PythonAsk the client to load the server's type definitions before reading a structured value. With them loaded, asyncua returns a Python
Read historical data in PythonCheck the server claims historical access, then read a bounded time range. Ask for aggregates rather than raw values when you want
Subscribe to alarms and events in PythonSubscribe to the server's event notifier and select the fields you need. Filtering server-side keeps the noise off the wire, and C
Work with OPC UA PubSub in Pythonasyncua is a client-server stack and does not implement PubSub. In Python the practical pattern is to subscribe over client-server
Handle errors and reconnect in PythonWrap the session in a loop that reconnects with backoff, and let asyncua try to transfer your subscriptions rather than rebuilding

Last verified 7 September 2026 against OPC UA 1.05.07. Version read from the project release tags. OPC UA Connect is an educational resource and is not affiliated with the OPC Foundation.

Free download
OPC UA Troubleshooting & Integration Checklist
The field-tested checklist engineers use to diagnose certificates, ports and namespace problems fast, plus a Python (asyncua) client template.
Get the free checklist →
Free, no course, no login