python data object notation. like json, but pythonic
Project description
pydon
Python data object notation. Like json, but pythonic
This package provides some basic tools for reading and writing python data objects to and from strings or files. A .pydon file or string is simply a string representation of python data. The pydon package is meant to provide similar functionality to json. Any pydon strings should be valid python expressions and must be parsable by the python AST’s literal_eval method. This means that pydon strings can safely contain data expressed as pytyhon literals.
Requirements
Python 3
Installing
Install using pip:
$ pip install pydon
Using
This package should be usable in a very similar manner to the json package:
import pydon
my_data = pydon.load_string("{'a': 1, 'b': '2', 'c': [4, 5, 6]}")
The load_file method may be used to load data from a file directly:
import pydon
my_data = pydon.load_file('some_file.pydon')
The dump_string method may be used to dump a pydon serializable data object to a string. The method can accept pprint format arguments:
import pydon
pydon.dump_string({'a': 1, 'b': '2', 'c': [4, 5, 6]}, width=1, indent=2)
This should result in the following output:
{ 'a': 1, 'b': '2', 'c': [4, 5, 6], }
The dump_file method may be used to dump a pydon serializable data object directly to a named file. The method can accept pprint format arguments as well:
import pydon
pydon.dump_file(
{'a': 1, 'b': '2', 'c': [4, 5, 6]},
'some_file.pydon',
width=1, indent=2,
)
Note that the .pydon extension is only used as a matter of convention. You may find it more useful to simply use the .py extension.
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
File details
Details for the file pydon-0.1.1rc2.tar.gz
.
File metadata
- Download URL: pydon-0.1.1rc2.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbcf0d52ca22721dae86c8d3341ee8ae54c5c2b16f5c459a9adf1fe0ec17c658 |
|
MD5 | ddb4eb55995d79ab06c4155a792ac8f2 |
|
BLAKE2b-256 | 71c50fa996b0ce45a3005d34732e657f3dbbed9b16b70bcf1a5090556c0c72b0 |