Skip to content

A Python implementation of the Zish data serialization format

License

Notifications You must be signed in to change notification settings

tlocke/zish_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zish

A Python library for the Zish format, released under the MIT-0 licence.

Build Status

  • Create a virtual environment: python3 -m venv venv
  • Activate the virtual environment: source venv/bin/activate
  • Install: pip install zish

To go from a Python object to an Zish string use zish.dumps. To go from a Zish string to a Python object use zish.loads. Eg.

>>> from zish 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': b'kshhgrl',
...     'tags': ['russian', 'novel', '19th century']}
>>>
>>> # Output it as an Zish string
>>> zish_str = dumps(book)
>>> print(zish_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 Zish string, to give us back the Python object
>>> reloaded_book = loads(zish_str)
>>>
>>> # Print the title
>>> print(reloaded_book['title'])
A Hero of Our Time
Python To Zish Type Mapping
Python Type Zish Type
bool bool
int integer
str string
datetime.datetime timestamp
dict map
decimal.Decimal decimal
float decimal
bytearray bytes
bytes bytes
list list
tuple list
  • Change to the zish directory: cd zish
  • Create a virtual environment: python3 -m venv venv
  • Activate the virtual environment: source venv/bin/activate
  • Install tox: pip install tox
  • Run tox: tox

This file is written in the reStructuredText format. To generate an HTML page from it, do:

  • Activate the virtual environment: source venv/bin/activate
  • Install Sphinx: pip install Sphinx
  • Run rst2html.py: rst2html.py README.rst README.html

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"
rm -r dist
python -m build
twine upload dist/*
  • Fix bug where dump() didn't escape " and \\ properly.
  • Remove support for Python 3.7 and add support for Python 3.11.
  • Switch to MIT-0 licence.
  • Make the U+00A0 NO-BREAK SPACE character whitespace
  • Better error message when dump() encounters an unrecognised type.
  • Allow trailing commas in maps and lists.
  • Make dumps sort the set type before outputing as a list.
  • Use 1-based line and character numbers, rather than zero-based.
  • Arrow time library upgraded.
  • Line and character numbers now available in errors
  • Better error message when parsing an empty string.
  • Fix new Flake8 errors.
  • Better error message if there's a duplicate key in a map.
  • An exception is thrown if there's a duplicate key in a map.
  • Change formatting for map and list in dumps. The trailing } and ] are now on a line down and at the original index.
  • A decimal with an uppercase 'E' in the exponent wasn't being recognized.
  • A map key can't be null, following change in spec.
  • Remove '//' as a comment, following change in spec.
  • Allow 'e' and 'E' in the exponent of a decimal, following change in spec.
  • Better error message when the end of the document is reached without a map being closed.
  • Fix bug where an integer after a value (and before a ',' or '}') in a map doesn't give a good error.
  • A map key can't now be a list or a map.
  • A map key can now be of any type.
  • The 'set' type has been removed from Zish.
  • Zish now recognizes the full set of Unicode EOL sequences.
  • The 'float' type has been removed from Zish.
  • Fixed bug when sorting map with keys of more than one type.
  • Give a better error if the end of the document is reached before a map is completed.
  • Give an error if there are multiple top-level values, rather than silently truncating.
  • Decimal exponent dumped as E rather than d.
  • Add tests for float formatting.
  • Tighten up parsing of container types.
  • Make sure floats are formatted without an uppercase E.
  • Allow lists and sets as keys.
  • Fixed map parsing bug where an error wasn't reported properly if it was expecting a : but got an integer.
  • Fixed bug where sets couldn't be formatted.
  • Performance improvement.
  • Add Travis configuration.
  • Give a better error message if a string isn't closed.
  • New native parser that doesn't use antlr. It's about twice as fast.
  • Fix bug where int was being parsed as Decimal.
  • Make bytes type return a bytes rather than a bytearray.
  • Container types aren't allowed as map keys.
  • Performance improvements.
  • Fix bug with UTC timestamp formatting.
  • Fix bug in timestamp formatting.
  • Add note about comments.
  • Fix bug where dumps fails for a tuple.
  • Simplify integer types.
  • Fixed bug where interpreter couldn't find the zish.antlr package in eggs.
  • Removed a few superfluous escape sequences.
  • Now uses RFC3339 for timestamps.
  • Fix bug where an EOF could cause an infinite loop.
  • First public release. Passes all the tests.

About

A Python implementation of the Zish data serialization format

Resources

License

Stars

Watchers

Forks

Languages