Skip to main content

Python implementation of PVL (Parameter Value Language)

Project description

https://img.shields.io/pypi/v/pvl.svg?style=flat-square https://img.shields.io/travis/planetarypy/pvl.svg?style=flat-square https://img.shields.io/pypi/dm/pvl.svg?style=flat-square

Python implementation of PVL (Parameter Value Language)

PVL is a markup language, similar to xml, commonly employed for entries in the Planetary Database System used by NASA to store mission data, among other uses. This package supports both encoding a decoding a superset of PVL, including the USGS Isis Cube Label and NASA PDS 3 Label dialects.

Installation

At the command line:

$ pip install pvl

Basic Usage

pvl exposes an API familiar to users of the standard library json module.

Decoding is primarily done through pvl.load for file like objects and pvl.loads for strings:

>>> import pvl
>>> module = pvl.loads("""
...     foo = bar
...     items = (1, 2, 3)
...     END
... """)
>>> print module
PVLModule([
  (u'foo', u'bar')
  (u'items', [1, 2, 3])
])
>>> print module['foo']
bar

You may also use pvl.load to read a label directly from an image:

>>> import pvl
>>> label = pvl.load('pattern.cub')
>>> print label
PVLModule([
  (u'IsisCube',
   PVLObject([
    (u'Core',
     PVLObject([
      (u'StartByte', 65537)
      (u'Format', u'Tile')
# output truncated...
>>> print label['IsisCube']['Core']['StartByte']
65537

Similarly, encoding pvl modules is done through pvl.dump and pvl.dumps:

>>> import pvl
>>> print pvl.dumps({
...     'foo': 'bar',
...     'items': [1, 2, 3]
... })
items = (1, 2, 3)
foo = bar
END

PVLModule objects may also be pragmatically built up to control the order of parameters as well as duplicate keys:

>>> import pvl
>>> module = pvl.PVLModule({'foo': 'bar'})
>>> module.append('items', [1, 2, 3])
>>> print pvl.dumps(module)
foo = bar
items = (1, 2, 3)
END

A PVLModule is a dict like container that preserves ordering as well as allows multiple values for the same key. It provides a similar similar semantics to a list of key/value tuples but with dict style access:

>>> import pvl
>>> module = pvl.PVLModule([
...     ('foo', 'bar'),
...     ('items', [1, 2, 3]),
...     ('foo', 'remember me?'),
... ])
>>> print module['foo']
bar
>>> print module.getlist('foo')
['bar', 'remember me?']
>>> print module.items()
[('foo', 'bar'), ('items', [1, 2, 3]), ('foo', u'remember me?')]
>>> print pvl.dumps(module)
foo = bar
items = (1, 2, 3)
foo = "remember me?"
END

For more information on custom serilization and deseralization see the full documentation.

Contributing

Feedback, issues, and contributions are always gratefully welcomed. See the contributing guide for details on how to help and setup a development environment.

History

0.2.0 (2015-08-13)

  • Drastically increase test coverage.

  • Lots of bug fixes.

  • Add Cube and PDS encoders.

  • Cleanup README.

  • Use pvl specification terminology.

  • Added element access by index and slice.

0.1.1 (2015-06-01)

  • Fixed issue with reading Pancam PDS Products.

0.1.0 (2015-05-30)

  • First release on PyPI.

Project details


Download files

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

Source Distribution

pvl-0.2.0.tar.gz (1.4 MB view details)

Uploaded Source

File details

Details for the file pvl-0.2.0.tar.gz.

File metadata

  • Download URL: pvl-0.2.0.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pvl-0.2.0.tar.gz
Algorithm Hash digest
SHA256 374e0c82bf53520066abc3f4b99b7cdd45f635519d28064add6f6b781279d491
MD5 4a7b1c94fb425b22de87ba2e1e020dd8
BLAKE2b-256 96ba2b08ad600313a9829fa969bd3c41b560c531d0e745bbb5acac85f0f2b40b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page