Skip to main content

Python LXML object binding.

Project description

Python LXML object binding.

[![Build Status](https://travis-ci.org/jessemyers/lxmlbind.png)](https://travis-ci.org/jessemyers/lxmlbind)

What is this?

The [xml.etree][1] library is a great way to manipulate XML in Python, but in most domains it is clearer to use objects that model your domain entities instead of manipulating the XML representation directly. The motivating example was [Jenkins][2] XML job configurations, but the same problem is likely to exist for any XML-based modeling.

This project attempts to use Python [data descriptors][3] to bind an element tree to Python objects.

[1]: http://lxml.de/tutorial.html [2]: http://jenkins-ci.org/ [3]: http://docs.python.org/2/howto/descriptor.html

Example

Assume that you have an API using XML representations of people with first and last names:

xml = “<person><first>John</first><last>Doe</last></person”

lxmlbind makes it easy to define a Person object that maps to this structure:

from lxmlbind.api import Base, Property

class Person(Base):

first = Property(“first”) last = Property(“last”)

Instances of Person wrap an lxml.etree and support manipulation of this structure through instance attributes:

# create the person from XML person = Person.from_xml(xml)

# get the first name attribute assert person.first == “John”

# set the last name attribute person.last = “Smith”

# print the resulting XML print person.to_xml()

# delete the first name entirely del person.first

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lxmlbind-2.0.tar.gz (11.8 kB view details)

Uploaded Source

File details

Details for the file lxmlbind-2.0.tar.gz.

File metadata

  • Download URL: lxmlbind-2.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lxmlbind-2.0.tar.gz
Algorithm Hash digest
SHA256 a57f41488a13d27f48ab2dc2133bc04f278a26f543fe332911ce51460e1c7334
MD5 f67d3d8588e8e195ef41fb11f51cfe02
BLAKE2b-256 d172013d8f8b21ad3a5223c9784c3cbdcd7160c5ddeeecd6340fcbdd92924737

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page