A tool to export nodes/values from an OPC UA server to a file, and import them into another OPC UA server.
- Stage 1 (Export): Browse and read all nodes/values from a source OPC UA server and save to a JSON file
- Stage 2 (Import): Read nodes/values from a JSON file and write them to a destination OPC UA server
Download the latest executables from the GitHub Actions artifacts (built automatically on push to master):
export_opc_nodes.exe- Export toolimport_opc_nodes.exe- Import toolcreate_nodes_from_export.exe- Create server from export
Place the executables in the same directory as the PowerShell scripts.
pip install -r requirements.txtTo build executables yourself:
pip install pyinstaller
pyinstaller export_opc_nodes.spec
pyinstaller import_opc_nodes.spec
pyinstaller create_nodes_from_export.specThe executables will be in the dist/ directory.
python export_opc_nodes.py --source-url opc.tcp://localhost:4840 --output-file nodes_export.jsonOptions:
--source-url: OPC UA server endpoint URL (default:opc.tcp://localhost:4840)--output-file: Output JSON file path (default:opc_nodes_export.json)--username: Optional username for authentication--password: Optional password for authentication--security-policy: Security policy (default: None, options: Basic128Rsa15, Basic256, Basic256Sha256)--security-mode: Security mode (default: None, options: Sign, SignAndEncrypt)
There are two ways to import:
python import_opc_nodes.py --destination-url opc.tcp://localhost:4841 --input-file nodes_export.jsonThis assumes the destination server already has the same node structure. It only writes values to existing nodes.
Options:
--destination-url: Destination OPC UA server endpoint URL (default:opc.tcp://localhost:4841)--input-file: Input JSON file path (default:opc_nodes_export.json)--username: Optional username for authentication--password: Optional password for authentication--security-policy: Security policy (default: None)--security-mode: Security mode (default: None)--dry-run: Validate without writing
python create_nodes_from_export.py --input-file nodes_export.json --port 4841This creates a new Python OPC UA server with nodes created from the export file. Nodes are created in the correct order (parents before children), then values are written.
Options:
--input-file: Input JSON file path (default:opc_nodes_export.json)--port: Port to run server on (default: 4841)--namespace-uri: Namespace URI (default:http://examples.freeopcua.github.io)
Run a test Python OPC UA server:
python test_server.py --port 4840This creates a simple server with some test nodes for demonstration.
The export file is a JSON file containing:
- Node ID
- Node Class (Variable, Object, etc.)
- Browse Name
- Display Name
- Data Type
- Value (if readable)
- Access Level (if applicable)
- Children nodes (recursive structure)
Run the test suite:
# Install test dependencies
pip install -r requirements.txt
# Run all tests
pytest
# Run with verbose output
pytest -v
# Run specific test file
pytest tests/test_opc_sync.py
# Run specific test
pytest tests/test_opc_sync.py::TestOPCExport::test_export_nodesThe test suite includes:
- Export tests: Verify nodes are exported correctly with values
- Import tests: Verify values are imported and modified on destination servers
- Integration tests: Full export/import cycle with value verification
Tests use separate test servers on ports 4850 and 4851 to avoid conflicts.
- Only readable/writable nodes are exported/imported
- The tool handles hierarchical node structures
- Variable nodes with values are prioritized for import
- Object nodes are created but their values come from their child Variable nodes
- Tests automatically start/stop test servers for isolated testing