[XML-SIG] ANN: Amara XML Toolkit

Uche Ogbuji uche at ogbuji.net
Fri Jan 5 21:45:35 CET 2007

Amara 1.2 was released to Cheeseshop New Year's Eve, but in all the
festivities and travel I forgot the announcements.  Just as well because
I'd forgotten to include a minor fix, and so here is


Changes since Amara 1.1.9:

* Add omit_nodetype_rule bindery rule
* Add force_nsdecls parameter to bindery node xml() method
* 4Suite 1.0 compatibility (requires 4Suite 1.0.2, in fact)
* Add support for attribute patterns to pushdom/pushbind
* Add experimental (not very reliable) xml_xslt() method to bindery object
  to apply transforms
* Improvements to trimxml command line
* Turn off DTD validation by default
* Add support for DTD validation & custom binding classes to convenience APIs
* Add custom binding demo
* Updates to the manual
* Bug fixes

Amara XML Toolkit is a collection of Python tools for XML processing--
not just tools that happen to be written in Python, but tools built from
the ground up to use Python's conventions and take advantage of the many
advantages of the language.

Amara builds on 4Suite [http://4Suite.org], but whereas 4Suite offers
more on literal implementation of XML standards in Python, Amara
focuses on Pythonic idiom.  It provides tools you can trust to conform
with XML standards without losing the familiar Python feel.

The components of Amara are:

* Bindery: data binding tool (a very Pythonic XML API)
* Scimitar: implementation of the ISO Schematron schema language for
            XML; converts Schematron files to Python scripts
* domtools: set of tools to augment Python DOMs
* saxtools: set of tools to make SAX easier to use in Python
* Flextyper: user-defined datatypes in Python for XML processing

There's a lot in Amara, but here are highlights:

Amara Bindery: XML as easy as py

Bindery reads an XML document and it returns a data structure of
Python objects corresponding to the vocabulary used in the XML document,
for maximum clarity.

Bindery turns the document

      <python spam="eggs">What do you mean "bleh"</python>
      <python ministry="abuse">But I was looking for argument</python>

Would become a set of objects so that you could write


In order to get the value "eggs" (as a Python Unicode object) or 


In order to get the element object with the contents "But I was looking for argument". 

There are other such tools for Python, and what makes Bindery unique is
that it's driven by a very declarative rules-based system for binding
XML to the Python data.  You can register rules that are triggered by
XPattern expressions specialized binding behavior.  It includes XPath
support and is very efficient, using SAX to generate bindings.

See the user documentation, manual.html, for more details.

Scimitar: exceptional schema language for an exceptional programming language

Scimitar is an implementation of ISO Schematron that compiles a Schematron
schema into a Python validator script.  You typically use scimitar in two
phases.  Say you have a schematron schema schema1.stron and you want to
validate multiple XML files against it, instance1.xml, instance2.xml,

First you run schema1.stron through the scimitar compiler script,

scimitar.py schema1.stron

A file, schema1-stron.py, is generated in the current working directory.
If you'd prefer a different location or file name, use the "-o" option.
The generated file is a validator script in Python.  It checks the
schematron rules specified in schema1.stron.

Run this validator on each XML file you wish to validate:

python schema1.py instance1.xml

The validation report is generated on standard output by default, or you
can use the "-o" option to redirect it to a file.

The validation report is an XML external parsed entity, a format much like
a well-formed XML document, but with some restrictions relaxed.

Amara DOM Tools: giving DOM a more Pythonic face

Amara DOM Tools features pushdom, similar to xml.dom.pulldom, but easier
to use, and a function to return an XPath location for any DOM node.

Amara SAX Tools: SAX without the brain explosion

Tenorsax (amara.saxtools.tenorsax) is a framework for "linerarizing" SAX logic
so it flows a bit more naturally, needing much less state machine wizardry.


Amara is open source, provided under the 4Suite variant of the Apache
license.  See the file COPYING for details.


Amara requires Python 2.4 or more recent and 4Suite-XML 1.0 or more
recent.  The easiest way to install it is:

easy_install amara

If this does not work you are probably not set up for easy_install and I
suggest you follow the simple instructions at


easy_install will automatically take care of installing dependencies for
you.  If you prefer not to use easy_install, grab a 4Suite-XML package more
recent than 1.0 and install that, then install the Amara package
using the usual:

python setup.py install

Or a Windows installer, or other method.

Uche Ogbuji                               Work: The Kadomo Group, Inc.
http://uche.ogbuji.net                    http://kadomo.com
http://copia.ogbuji.net                   Lead dev at http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

More information about the XML-SIG mailing list