overview
The pyxser name stands for Python XML Serialization and is a Python object to XML serializer and deserializer. In other words, it can convert a Python object into XML and also, convert that XML back into the original Python object. It uses a preorder traversal tree algorithm over the object tree and the XML tree. The algorithm is , and uses some compiler construction techniques as memoization to create unique instances of each element in the object tree. It supports cross referenced and circular referenced object trees, so the serializer do not crash with those kinds of objects. Each serialized object before being deserialized is validated against the pyxser XML schema. It also uses mutually recursive functions to serialize and deserialize the object tree, but it has some features, like the depth argument, which allows you to stop serializing / deserializing the object tree at certain point. The pyxser module is self documented, if you want to take a look on the documentation, just run pydoc pyxser on a terminal. The current version is 1.5.2-r2. It supports Python 2.4 to Python 2.7 and is available through easy_install.
features
- Serialization of cross references.
- Serialization of circular references.
- Preserves object references.
- Custom serializations.
- Custom deserializations.
- Custom serialization depth limit.
- Object attribute selection callback.
- Standards based serialization.
- Standards based XML validation using pyxser XML Schema.
- C14N based serialization, as optional kind of output.
- Model based XML serialization, represented on XML Schema and XML DTD.
donations
Support this project by donating through PayPal:
Also I can receive donations in books & hardware, just use the Contact Form to let you know how to donate.
sample output
Remember to download and save as XML and view with an XML editor.
download
You can download pyxser from the github repository.
win32 binaries
The pyxser binary distribution for Win32 platform requires the libxml2 binaries to work. To install the binary distribution of pyxser for Win32, you need to meet the following requirements, and alternatively to build your own binary distribution you can compile pyxser from the trunk branch, which will be providing support for Python 3.X very soon.
- Visual C++ 2008 Runtime
- libxml2 Win32 binaries
I think that the Visual C++ 2008 Runtime comes with .NET framework 3.5. The libxml2 binaries needs to be placed on the system path — for example C: Windows System32 — and requires Python 2.7 to be installed before you install the pyxser extension.
related documentation
- Pyxser, Serialización XML en Python (Spanish), a paper written in Spanish which describes the pyxser serialization model and was to postulate to the JRSL’09 event in Chile.
- Pyxser, Serialización XML en Python (Spanish), a LaTeX Beamer presentation in Spanish which describes the pyxser serialization model and was to postulate to the JRSL’09 event in Chile.
license
The pyxser license is GNU Lesser General Public License version 3. You can use in your closed source application, but if you modify pyxser, you must publish the changes.
using pyxser
Using pyxser is quite simple:
import pyxser as pyx class TestClass(object): a = None b = None c = None def __init__(self, a, b, c): self.a = a self.b = b self.c = c tst = TestClass("var_a", "var_b", "var_c") ser = pyx.serialize(obj=tst, enc="utf-8") print(ser)