Read URP File in python

Hi,

I wanted to know if there is a way to read a .urp file into python. I know the urp file is a form of compressed xml format, but I can’t seem to get the correct encoding to read it in python.

This library has a Python wrapper that allows you to edit the XML inside a URP file.

from underautomation.universal_robots.files.ur_program import URProgram

import clr

clr.AddReference("System.Xml.Linq")

from System.Xml.Linq import XElement

prg = URProgram.load("path\\to\\program.urp")

xmlString = prg.xml.ToString()

## Edit xmlString

modifiedPrg = URProgram(XElement.Parse(xmlString))

modifiedPrg.save("path\\to\\program.urp")

Thanks for the library share, looks useful! Unfortunately it’s a bit overkill for my application.

I have found a way to open the file using gzip in python.

Example:

import gzip
with gzip.open("file.urp", "rb") as file:
  file.readLine()