Convenience routines for parsing and manipulation ofVOEvent XML packets.
Project description
A bare-bones, lightweight library for parsing, manipulating, and generating VOEvent XML packets.
Update: I’ve now designated a version 0.1.0 and uploaded to PyPI. You can install this using:
pip install voevent-parse
(see below for more details).
Rationale
The python library lxml.objectify provides very elegant, attribute-style access to data stored in XML packets. However, dealing with the vagaries of its namespace handling requires some careful reading of the documentation. This library takes care of the details for you, so that accessing those vital data elements is as simple as:
v = voeparse.load(xml_filename) print "AuthorIVORN:", v.Who.AuthorIVORN #Prints ivo://nasa.gsfc.tan/gcn v.Who.AuthorIVORN = 'ivo://i.heart.python/lxml' #Alters the XML value.
It also provides convenience routines for common data access tasks, saving you the hassle of typing out very long attribute chains and dealing with varying formats of VOEvent.
Installation
Voevent-parse only has one python prerequisite, lxml>=2.3. However, lxml requires some system libraries to install correctly. If you encounter a pip error along the lines of:
error: command 'gcc' failed with exit status 1
Then you should check you have the libxml2-dev and libxlt1-dev Debian packages installed (or their Redhat equivalents).
As with any Python package, you have a few sensible options for package installation; typical choices might include:
pip install voevent-parse (with a virtualenv, recommended)
pip install voevent-parse --user (to install for current user only)
Other development tricks e.g. symlink into ~/.local/lib/python2.7/site-packages.
lxml.objectify tips
The objectify library has a few syntactic quirks which can trip up new users. Firstly, you should be aware that the line root.foo actually returns an object that acts like a list of all the children with the name ‘foo’. What’s confusing is that objectify has syntactic sugar applied so that print root.foo is effectively identical to print root.foo[0]. Furthermore, this can confuse access to the actual leaf values, so you should be aware of the accessor to the text representation of the value; .text, e.g.:
>root = lxml.objectify.Element('root') >root.foo = 'sometext' >root.foo 'sometext' >len(root.foo) 1 >#The string clearly does not have length==1 - it's the list. >root.foo.text 'sometext' >print len(root.foo.text) 8 >#Ah, that's better!
For some more examples, you might also try: http://www.saltycrane.com/blog/2011/07/example-parsing-xml-lxml-objectify/.
API reference docs
While currently quite minimal, these can be found at http://voevent-parse.readthedocs.org, or can be built from the source if you prefer the traditional python docs colour-scheme.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file voevent-parse-0.4.1.tar.gz
.
File metadata
- Download URL: voevent-parse-0.4.1.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1c209d0ccd8caa4c09b3e5cf519a068eb4fb64706c350f4e7f91f1eb3c9091c |
|
MD5 | 5b178f6c132126ad4c928c2b53622a86 |
|
BLAKE2b-256 | 17259d4f8d68d6a1db9b06ec0f254b37b2f994dcfaab2d3ec8f4ee0207b9c131 |
File details
Details for the file voevent-parse-0.4.1.linux-x86_64.exe
.
File metadata
- Download URL: voevent-parse-0.4.1.linux-x86_64.exe
- Upload date:
- Size: 80.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3700d122daac163588399a20b03c251a35cfe4209695cb42486cd2492bf8987c |
|
MD5 | 1c7ebce1045dae78e3d4afef2da429b1 |
|
BLAKE2b-256 | 6402118ab8fe499fd478d2146514ccfa3c0e35cb404a7d92c717bda40301a361 |