Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

amara3-xml

A data processing library built on Python 3 and MicroXML. This module adds the MicroXML support, and adaptation to classic XML.

Uche Ogbuji < uche@ogbuji.net > More discussion, etc: https://groups.google.com/forum/#!forum/akara

Install

Requires:

For the latter 2, you can do:

pip install pytest “amara3-iri>=3.0.0a2”

Use

Amara in version 3.0 is focused on MicroXML, rather than full XML. However because most of the XML-like data you’ll be dealing with is XML 1.0, Amara provides capabilities to parse legacy XML and reduce it to MicroXML. In many cases the biggest implication of this is that namespace information is stripped. As long as you know what you’re doing you can get pretty far by ignoring this, but make sure you know what you’re doing.

  from amara3.uxml import xml

  MONTY_XML = """<monty xmlns="urn:spam:ignored">
    <python spam="eggs">What do you mean "bleh"</python>
    <python ministry="abuse">But I was looking for argument</python>
  </monty>"""

  builder = xml.treebuilder()
  root = builder.parse(MONTY_XML)
  print(root.xml_name) #"monty"
  child = next(root.xml_children)
  print(child) #First text node: "
"
  child = next(root.xml_children)
  print(child.xml_value) #"What do you mean "bleh""
  print(child.xml_attributes["spam"]) #"eggs"

There are some utilities to make this a bit easier as well.

from amara3.uxml import xml
from amara3.uxml.treeutil import *

MONTY_XML = """<monty xmlns="urn:spam:ignored">
  <python spam="eggs">What do you mean "bleh"</python>
  <python ministry="abuse">But I was looking for argument</python>
</monty>"""

builder = xml.treebuilder()
root = builder.parse(MONTY_XML)
py1 = next(select_name(root, "python"))
print(py1.xml_value) #"What do you mean "bleh""
py2 = next(select_attribute(root, "ministry", "abuse"))
print(py2.xml_value) #"But I was looking for argument"

Experimental MicroXML parser

For this parser the input truly must be MicroXML. Basics:

>>> from amara3.uxml.parser import parse
>>> events = parse('<hello><bold>world</bold></hello>')
>>> for ev in events: print(ev)
...
(<event.start_element: 1>, 'hello', {}, [])
(<event.start_element: 1>, 'bold', {}, ['hello'])
(<event.characters: 3>, 'world')
(<event.end_element: 2>, 'bold', ['hello'])
(<event.end_element: 2>, 'hello', [])
>>>

Or…And now for something completely different!…Incremental parsing.

>>> from amara3.uxml.parser import parsefrags
>>> events = parsefrags(['<hello', '><bold>world</bold></hello>'])
>>> for ev in events: print(ev)
...
(<event.start_element: 1>, 'hello', {}, [])
(<event.start_element: 1>, 'bold', {}, ['hello'])
(<event.characters: 3>, 'world')
(<event.end_element: 2>, 'bold

Metadata

Release files for amara3.xml 3.0.0b5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for amara3.xml 3.0.0b5
File Size Uploaded Provenance Actions
amara3-xml-3.0.0b5.tar.gz 43.2 kB Without provenance Details for amara3-xml-3.0.0b5.tar.gz

Release files / amara3-xml-3.0.0b5.tar.gz

Download URL amara3-xml-3.0.0b5.tar.gz
Size 43.2 kB
Tags Source
SHA-256 checksum
How to use checksums
46a127d8fc6c4d880d76f6831793ef7bb9865edca2a823aea067d2de1f3dfbf8
BLAKE2b-256 checksum
How to use checksums
695f1cc0f227d9854220f8f9d4aceda7356b2c733db9c537cdcff1f5a7ba9888
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for amara3.xml 3.0.0b5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page