Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Work with XML documents as if they were Python objects

Project Description


Mappet has been created to enable an easy an intuitive way to work with XML structures in Python code.

A well known lxml module has been used under the hood, mainly due to XML parsing performance.

Mappet accepts a string with valid XML, an lxml.etree._Element object or a dict representing the XML tree.

>>> import mappet
>>> f = open('example.xml', 'r')
>>> m = mappet.Mappet(

As an example, an XML document of the following structure has been used:

<?xml version='1.0' encoding='iso-8859-2'?>
        <id seq="20" tstamp="2015-07-13T10:55:25+02:00"/>
        <initiator>Mr Sender</initiator>
        <user first-name="Name" last-name="LastName">id</user>


Every XML node can be accessed in two ways: by attribute and item access.

Dictionary access:

Dictionary access is possible thanks to XML document being represented as a Python dictionary. Conversion of values is done explicitly.

By default, values are returned as str.

>>> m['reply']['cars']['Car'][0]['Manufacturer']

Nodes’ names are case-sensitive.

Attribute access:

Due to restrictions in Python variable names, tag names are normalized for attribute access. Tag names are normalized to lowercase and hyphens to underlines.

Same example using attribute access (__repr__ is responsible for representing the tag):


To get a string representation use get().


get() has two parameters, default and callback. The first one is returned when then node’s value is empty, the second is a function to be called upon the returned value.


Alternatively, one can use built-in helper functions, defined in


Helper functions

  • to_bool
  • to_int
  • to_str
  • to_string
  • to_float
  • to_time
  • to_datetime
  • to_date
Release History

Release History

This version
History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
mappet-0.1.2-py2-none-any.whl (13.7 kB) Copy SHA256 Checksum SHA256 py2 Wheel Aug 27, 2015
mappet-0.1.2.tar.gz (10.7 kB) Copy SHA256 Checksum SHA256 Source Aug 27, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting