# Ignition and Python LXML

**URL:** <https://forum.inductiveautomation.com/t/ignition-and-python-lxml/97351>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [October 16, 2024, 9:57pm UTC](https://forum.inductiveautomation.com/t/ignition-and-python-lxml/97351 "2024-10-16T21:57:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 16, 2024, 9:57pm UTC](https://forum.inductiveautomation.com/t/ignition-and-python-lxml/97351/1 "2024-10-16T21:57:01Z")

</div>

I want to use the lxml 3rd party library within Ignition.

How do I add it and will the library be included with a gateway backup? - if not, what would be the best way to "bundle" it so that the scripting that relies on it will have the library available?

TIA

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 16, 2024, 10:01pm UTC](https://forum.inductiveautomation.com/t/ignition-and-python-lxml/97351/2 "2024-10-16T22:01:12Z")

</div>

[https://www.docs.inductiveautomation.com/docs/8.1/platform/scripting/python-scripting/libraries#importing-3rd-party-libraries](https://https://www.docs.inductiveautomation.com/docs/8.1/platform/scripting/python-scripting/libraries#importing-3rd-party-libraries)

But I don't think you can use lxml as it appears to be bindings to a C library.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 16, 2024, 10:01pm UTC](https://forum.inductiveautomation.com/t/ignition-and-python-lxml/97351/3 "2024-10-16T22:01:22Z")

</div>

> [@amarks](#):
>
> use the lxml 3rd party library within Ignition.

You cannot:

> The lxml XML toolkit is a Pythonic binding for the C libraries libxml2 and libxslt.

> [@amarks](#):
>
> will the library be included with a gateway backup?

Even if you could use it, it would live in `user-lib/pylib`, which is not included in gateway backups.

Use java's native XML support. Helpers available here: [xml.py](https://www.automation-pros.com/ignition/xml.py)

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 17, 2024, 1:28pm UTC](https://forum.inductiveautomation.com/t/ignition-and-python-lxml/97351/4 "2024-10-17T13:28:16Z")

</div>

Ok, I see in the lxml description that it uses Cython and Ignition uses Jython.

Just curious, how do I tell what version of Jython Ignition uses?

edit: nevermind - it's the first thing that prints in the script console interpreter. You can also get it directly via

```python
import sys
print sys.version_info

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 17, 2024, 1:30pm UTC](https://forum.inductiveautomation.com/t/ignition-and-python-lxml/97351/5 "2024-10-17T13:30:55Z")

</div>

In general, a Python library needs to be compatible with Python 2.7 and not use native/C code in order to be used in Ignition / run on Jython.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 17, 2024, 3:49pm UTC](https://forum.inductiveautomation.com/t/ignition-and-python-lxml/97351/6 "2024-10-17T15:49:07Z")

</div>

Luckily `xml.etree.ElementTree` is basically the same implementation, minus the support for CDATA, but I'll just use string.format() for that anyway.

```python
CDATA = '<![CDATA[{cdata}]]>'

desc = ET.SubElement(tag, 'Description')
desc.text	= CDATA.format(cdata = tag_desc)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 17, 2024, 4:09pm UTC](https://forum.inductiveautomation.com/t/ignition-and-python-lxml/97351/7 "2024-10-17T16:09:00Z")

</div>

Don't use ElementTree. Like most of the jython standard library, its handling of international strings/encodings is broken.

Use the java XML standard classes. Full stop.
