Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tlocke/pionic
A Python library for the Ion format
https://github.com/tlocke/pionic
ion python python3
Last synced: about 2 months ago
JSON representation
A Python library for the Ion format
- Host: GitHub
- URL: https://github.com/tlocke/pionic
- Owner: tlocke
- License: mit
- Archived: true
- Created: 2017-07-11T19:39:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-23T17:38:52.000Z (over 7 years ago)
- Last Synced: 2024-10-31T01:04:55.331Z (2 months ago)
- Topics: ion, python, python3
- Language: Python
- Size: 87.9 KB
- Stars: 12
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
- starred-awesome - pionic - A Python library for the Ion format (Python)
README
= Pionic
A Python 3 library for the http://amzn.github.io/ion-docs/[Ion format],
released under the
https://github.com/tlocke/pionic/blob/master/LICENSE[MIT Licence].image:https://travis-ci.org/tlocke/pionic.svg?branch=master["Build Status",
link="https://travis-ci.org/tlocke/pionic"]The Ion format is a superset of JSON, adding (among other things) the
much-needed timestamp, decimal and binary data types.== Installation
It's a good idea to set up a virtualenv:
virtualenv venv
source venv/bin/activatethen install Pionic with pip:
pip install pionic
== Quickstart
To go from a Python object to an Ion string use `pionic.dumps`. To go from an
Ion string to a Python object use `pionic.loads`. Eg.....
>>> from pionic import loads, dumps
>>> from datetime import datetime, timezone
>>> from decimal import Decimal
>>>
>>> # Take a Python object
>>> book = {
... 'title': 'A Hero of Our Time',
... 'read_date': datetime(2017, 7, 16, 14, 5, tzinfo=timezone.utc),
... 'would_recommend': True,
... 'description': None,
... 'number_of_novellas': 5,
... 'price': Decimal('7.99'),
... 'weight': 6.88,
... 'key': bytearray(b'kshhgrl'),
... 'tags': ['russian', 'novel', '19th century']}
>>>
>>> # Output it as an Ion string
>>> ion_str = dumps(book)
>>> print(ion_str)
{
'description': null,
'key': {{ a3NoaGdybA== }},
'number_of_novellas': 5,
'price': 7.99,
'read_date': 2017-07-16T14:05:00Z,
'tags': [
"russian",
"novel",
"19th century"],
'title': "A Hero of Our Time",
'weight': 6.88,
'would_recommend': true}
>>>
>>> # Load the Ion string, to give us back the Python object
>>> reloaded_book = loads(ion_str)
>>>
>>> # Print the title
>>> print(reloaded_book['title'])
A Hero of Our Time....
== Contributing
Useful links:
* https://amzn.github.io/ion-docs/spec.html[Ion Specification]
* http://www.antlr.org/api/Java/index.html?overview-summary.html[ANTLR JavaDocs]To run the tests:
* Change to the `pionic` directory: `cd pionic`
* Create a virtual environment: `virtualenv --python=python3 venv`
* Active the virtual environment: `source venv/bin/activate`
* Install tox: `pip install tox`
* Run tox: `tox`The core parser is created using https://github.com/antlr/antlr4[ANTLR] from
the http://amzn.github.io/ion-docs/grammar/IonText.g4.txt[Ion grammar]. To
create the parser files, go to the `antlr` directory and download the ANTLR jar
and then run the following command:java -jar antlr-4.7-complete.jar -Dlanguage=Python3 IonText.g4
=== Making A New Release
Run `tox` to make sure all tests pass, then update the `Release Notes` section
then do:....
git tag -a x.y.z -m "version x.y.z"
python setup.py register sdist bdist_wheel upload --sign
....