@@ -18,12 +18,20 @@ Requires Python 3.12 or later.
1818pip install amara
1919```
2020
21- Or with uv:
21+ Or with uv (recommended) :
2222
2323``` bash
2424uv pip install amara
2525```
2626
27+ ** Note** : This package is currently in development. For the latest features and bug fixes, you can install directly from source:
28+
29+ ``` bash
30+ git clone https://github.com/OoriData/Amara.git
31+ cd Amara
32+ pip install -U .
33+ ```
34+
2735## Quick Start
2836
2937### IRI Processing
@@ -33,8 +41,16 @@ from amara.iri import I, iri
3341
3442# Create and manipulate IRIs
3543url = I(' http://example.org/path/to/resource' )
44+ print (url.scheme) # 'http'
45+ print (url.host) # 'example.org'
46+
47+ # Join relative paths with base URLs
3648joined = iri.join(' http://example.org/a/b' , ' ../c' )
37- # Result: 'http://example.org/a/c'
49+ print (joined) # 'http://example.org/a/c'
50+
51+ # Percent encoding/decoding
52+ encoded = iri.percent_encode(' hello world!' )
53+ print (encoded) # 'hello%20world%21'
3854```
3955
4056### XML Processing
@@ -47,14 +63,21 @@ SAMPLE_XML = """<monty>
4763 <python ministry="abuse">But I was looking for argument</python>
4864</monty>"""
4965
66+ # Parse XML
5067builder = xml.treebuilder()
5168root = builder.parse(SAMPLE_XML )
5269print (root.xml_name) # "monty"
5370
54- # Access children
71+ # Access children and attributes
5572for child in root.xml_children:
5673 if hasattr (child, ' xml_attributes' ):
57- print (child.xml_attributes.get(' spam' ))
74+ print (f " Element: { child.xml_name} " )
75+ print (f " Spam attr: { child.xml_attributes.get(' spam' )} " )
76+ print (f " Text: { child.xml_text} " )
77+
78+ # Iterate through all elements
79+ for elem in root.xml_iter():
80+ print (f " Found element: { elem.xml_name} " )
5881```
5982
6083### HTML5 Processing
@@ -69,11 +92,42 @@ HTML_DOC = """<!DOCTYPE html>
6992</html>"""
7093
7194doc = html5.parse(HTML_DOC )
95+ print (doc.xml_name) # "html"
96+ ```
97+
98+ ### XPath-like Queries
99+
100+ ``` python
101+ from amara.uxpath import xpath
102+
103+ SAMPLE_XML = """ <catalog>
104+ <book id="1">
105+ <title>Python Programming</title>
106+ <author>John Doe</author>
107+ </book>
108+ <book id="2">
109+ <title>Web Development</title>
110+ <author>Jane Smith</author>
111+ </book>
112+ </catalog>"""
113+
114+ builder = xml.treebuilder()
115+ root = builder.parse(SAMPLE_XML )
116+
117+ # Find all book titles
118+ titles = xpath.select(root, ' //book/title' )
119+ for title in titles:
120+ print (title.xml_text)
121+
122+ # Find book by ID
123+ book = xpath.select(root, " //book[@id='2']" )
124+ if book:
125+ print (f " Found: { book[0 ].xml_children[0 ].xml_text} " )
72126```
73127
74128### Command-Line Tool
75129
76- The ` microx ` command provides powerful XML/MicroXML querying:
130+ The ` microx ` command provides powerful XML/MicroXML querying and processing :
77131
78132``` bash
79133# Extract elements by name
@@ -82,13 +136,40 @@ microx file.xml --match=item
82136# XPath-like expressions
83137microx file.xml --expr=" //item[@id='2']"
84138
85- # Extract text content
139+ # Extract text content from specific elements
86140microx file.xml --match=name --foreach=" text()"
141+
142+ # Process multiple files
143+ microx * .xml --match=title --foreach=" text()"
144+
145+ # Pretty-print XML
146+ microx file.xml --pretty
147+
148+ # Convert to MicroXML
149+ microx file.xml --microxml
87150```
88151
152+ For more options, run:
153+ ``` bash
154+ microx --help
155+ ```
89156
157+ ## Requirements
158+
159+ - Python 3.12+
160+ - Dependencies: [ ` ply ` ] ( https://www.dabeaz.com/ply/ply.html ) , [ ` html5lib-modern ` ] ( https://github.com/ashleysommer/html5lib-modern ) , [ ` nameparser ` ] ( https://pypi.org/project/nameparser/ )
161+
162+ ## Development
163+
164+ This project is actively developed by [ Oori Data] ( https://www.oori.dev/ ) . For development setup:
165+
166+ ``` bash
167+ git clone https://github.com/OoriData/Amara.git
168+ cd Amara
169+ pip install -U .
170+ ```
90171
91- # History
172+ ## History
92173
93174Amara was originally an open source project I created, renaming and expanding on [ Anobind 2003] ( https://www.xml.com/pub/a/2003/08/13/py-xml.html ) , looking to simplify and rethink XML and related technology processing. It went through a few evolutions and progress had slowed down since the late 2010s.
94175
0 commit comments