Registry / http-networking / asyncua

asyncua

JSON →
library2.0.1pypypi✓ verified 23d ago

asyncua is a comprehensive, pure Python library providing both OPC-UA client and server capabilities, designed for asynchronous operations. It enables Python applications to communicate with industrial automation systems using the OPC-UA protocol. Currently at version 1.1.8, the library maintains an active development pace, with frequent bug fixes and feature enhancements, including recent beta releases for upcoming major versions.

pip install asyncua
INSTALL
IMPORT
SIG · ASYNCUA
A
asyncua
http-networkingpythonv2.0.1
Install
4.8s avg
Import
1785ms
Disk
74MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 1.861s · 72MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 4.8s · import 1.709s · 72MB
74MB installed
● package 74MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
from asyncua import Client
Server
from asyncua import Server
ua
from asyncua import ua
import asyncua.ua
Import `ua` directly for convenient access to OPC-UA data types like Variant, NodeId, etc.
Node
from asyncua.common.node import Node
While Node objects are common, they are usually obtained from Client/Server methods rather than instantiated directly. Direct import is for type hinting or advanced scenarios.

This quickstart demonstrates how to establish a basic OPC-UA client connection, retrieve the root node, and gracefully disconnect. It uses an environment variable for the server URL, which is a common practice for flexible deployment. Remember that `asyncua` is built on `asyncio`, so all client/server operations must be `await`ed within an `async` function.

import asyncio from asyncua import Client, ua import os async def main(): # Replace with your OPC-UA server endpoint server_url = os.environ.get('OPCUA_SERVER_URL', 'opc.tcp://localhost:4840/freeopcua/server/') # Client connection example client = Client(url=server_url) try: await client.connect() print(f"Connected to OPC-UA server at {server_url}") # Get the root node root = client.get_root_node() print(f"Root node: {root}") # Example: Read a variable (replace with actual node ID) # For example, to read a variable under Objects/MyObject/MyVariable # node_id_str = "ns=2;i=1001" # Example NodeId # my_variable = await client.get_node(node_id_str) # value = await my_variable.read_value() # print(f"Value of {node_id_str}: {value}") # You can browse nodes, subscribe to data changes, write values, etc. except Exception as e: print(f"Error connecting or interacting with server: {e}") finally: print("Disconnecting from OPC-UA server...") await client.disconnect() if __name__ == '__main__': asyncio.run(main())
Debug
Known issues
breakingStarting with version 1.2.0 (currently in beta), asyncua removes support for Python versions older than 3.10. Users on Python 3.9 or earlier must upgrade their Python environment before migrating to asyncua 1.2.x or later.
fix
Upgrade your Python environment to 3.10 or newer. For projects requiring older Python versions, stick to asyncua version 1.1.x or earlier.
affects: >=1.2.0
gotchaasyncua is an asyncio-based library. All network operations (connect, read, write, subscribe, disconnect, etc.) are coroutines and must be properly `await`ed within an `async` function. Forgetting `await` will result in coroutine objects not being run, leading to unexpected behavior or resource leaks.
fix
Ensure all asyncua methods are called with `await`. For example, use `await client.connect()` instead of `client.connect()`.
affects: All
gotchaAlways ensure to call `await client.disconnect()` or use `async with Client(...)` for client connections to gracefully close the connection and release resources. Failing to do so can leave dangling connections and consume system resources unnecessarily.
fix
Wrap client connection logic in `try...finally` to ensure `await client.disconnect()` is called, or preferably, use `async with Client(...) as client:` which handles connection and disconnection automatically.
affects: All
gotchaWhen interacting with OPC-UA values, ensure correct handling of `asyncua.ua.Variant` and `asyncua.ua.VariantType`. Directly assigning Python types might work for simple cases, but explicit `ua.Variant` usage is often required for specific OPC-UA data types, especially when writing values.
fix
When writing values, explicitly construct `ua.Variant` objects with the correct `VariantType` if the default conversion is not sufficient, e.g., `await node.write_value(ua.Variant(123, ua.VariantType.Int32))`.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'asyncua'
The 'asyncua' module is not installed in the Python environment.
fix
Install the module using pip: 'pip install asyncua'.
ModuleNotFoundError: No module named 'asyncio'
The 'asyncio' module is not installed in the Python environment.
fix
Install the module using pip: 'pip install asyncio'.
ModuleNotFoundError: No module named 'pyee.asyncio'
The 'pyee.asyncio' module is not installed in the Python environment.
fix
Install the module using pip: 'pip install pyee'.
ModuleNotFoundError: No module named 'pyserial-asyncio'
The 'pyserial-asyncio' module is not installed in the Python environment.
fix
Install the module using pip: 'pip install pyserial-asyncio'.
ModuleNotFoundError: No module named 'nest-asyncio'
The 'nest-asyncio' module is not installed in the Python environment.
fix
Install the module using pip: 'pip install nest-asyncio'.
Upgrade
Version history
2.0.1latest on PyPI · released Jun 29, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
102 hits · last 30 days
node
94
OpenAI (training)
1
Resources