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.
| Project | asyncua (FreeOpcUa/opcua-asyncio) |
|---|---|
| Version | 2.0.1 |
| Licence | LGPL-3 |
| Install | pip 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.
| Task | What it does |
|---|---|
| Connect to an OPC UA server in Python | Use 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 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 |
| Read a value from an OPC UA server in Python | Read 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 Python | Match 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 Python | Create a subscription with the publishing interval your consumer actually needs, then add monitored items with their own sampling |
| Call an OPC UA method in Python | Call 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 Python | Generate 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 Python | Ask 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 Python | Check 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 Python | Subscribe 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 Python | asyncua 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 Python | Wrap 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.