Serialize and deserialize data to python source notation (hbn)
Reason this release was yanked:
Completely broken use 0.2.0
Project description
Hiss Byte Notation
Library to make it easy to use python literal syntax as a data format
Have you seen people try to print a dict and then use the JSON library to parse the output? This library is some helper function for that scenario. It is a small wrapper around ast.literal_eval and will have a API similar to other serializer/deserializers such as json, pickle, pyyaml, etc.
Safety
ast.literal_eval
is safer than eval
but the python docs still imply that there are malicious payloads. I'm not
sure if they are the same problems that could affect json or other formats.
Usage
import hissbytenotation as hbn
data ={
"mammal": "cat",
"reptile": ["snake", "lizard"],
"version": 1
}
data_as_string = hbn.dumps(data)
rehydrated = hbn.loads(data_as_string)
print(rehydrated)
# {'mammal': 'cat', 'reptile': ['snake', 'lizard'], 'version': 1}
How it works
Serialization is done by calling repr, checking if ast.literal_eval can read it. Repr can be called on more data structures than ast.literal_eval can handle.
Prior art
You could just call repr
and ast.literal_eval
directly.
None that I know of, except possibly astor which serializes to a string representation of the AST, which looks nothing like the source code, nor json.
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
Hashes for hissbytenotation-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1471e87bf7faf40f233f5bcef0cd46aa876a64eb403de7aa4db9cdc7b4a0f12e |
|
MD5 | 87117ecf3c9e37fc2d186a35636a2f12 |
|
BLAKE2b-256 | a2d40520ec4083d082f07f3a8a43e663af87d132ba4b1ea9065422065f5f029e |