A parser for the CompactData serialisation format.
Project description
CompactData Python Library
A Python library for parsing and serialising data in the CompactData format. CompactData is a compact data serialisation format that prioritises efficiency of data storage and transport. It is well suited for use cases where efficient data storage and transport is a priority.
Features
- Parse CompactData strings into Python objects
- Serialise Python objects into CompactData strings
- Compatible with Python 3.6 and higher
Installation
To install the CompactData Python library, use the following command:
pip install compactdata
Usage
Parsing CompactData strings
To parse a CompactData string into a Python object, use the compactdata.loads()
function:
import compactdata
compactdata_string = "my_object=(string=`abc`;number=1;array=[1;2;3];map=(a=1;b=2;c=3))"
parsed_object = compactdata.loads(compactdata_string)
print(parsed_object)
# Output: {'my_object': {'string': 'abc', 'number': 1, 'array': [1, 2, 3], 'map': {'a': 1, 'b': 2, 'c': 3}}}
Serialising Python objects
To serialise a Python object into a CompactData string, use the compactdata.dumps()
function:
import compactdata
python_object = {"key1": "value1", "key2": 2}
compactdata_string = compactdata.dumps(python_object)
print(compactdata_string)
# Output: (key1=value1;key2=2)
Examples
Here are some examples of parsing and serialising different CompactData strings and Python objects:
import compactdata
# Parsing CompactData strings
compactdata_strings = [
"my_object=(string=`abc`;number=1;array=[1;2;3];map=(a=1;b=2;c=3))",
"[1;2;3]",
"a=1;b=2.5;c=10e3",
"@dv=1;salts=[(s=salts.domainverification.org;ids=[342c208d-0523-4d22-b7dd-32952dbeace2]);(s=example.com;ids=[90797a69-205b-4a35-88fe-8a186392ea15])]",
]
for compactdata_string in compactdata_strings:
print(compactdata.loads(compactdata_string))
# Output:
# {'my_object': {'string': 'abc', 'number': 1, 'array': [1, 2, 3], 'map': {'a': 1, 'b': 2, 'c': 3}}}
# [1, 2, 3]
# {'a': 1, 'b': 2.5, 'c': 10000.0}
# {'@dv': 1, 'salts': [{'s': 'salts.domainverification.org', 'ids': ['342c208d-0523-4d22-b7dd-32952dbeace2']}, {'s': 'example.com', 'ids': ['90797a69-205b-4a35-88fe-8a186392ea15']}]}
# Serialising Python objects
python_objects = [
[1, 2, 3, "123"],
{"key1": "value1", "key2": 2},
"string_value",
123,
[1, {"k": "v"}, 2],
]
for python_object in python_objects:
print(compactdata.dumps(python_object))
# Output:
# [1;2;3;123]
# (key1=value1;key2=2)
# string_value
# 123
# [1;(k=v);2]
License
This project is licensed under the MIT License. See the LICENSE file for details.
Support and Contributions
If you encounter any issues or have feature requests, please open an issue on GitHub. Contributions to this project are welcome. To contribute, please fork the repository, make your changes, and submit a pull request.
For more information about the CompactData format, visit the official website at https://compactdata.org.
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
Built Distribution
File details
Details for the file compactdata-0.0.4.tar.gz
.
File metadata
- Download URL: compactdata-0.0.4.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.2 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78dffbf36f8ef94ceb5281bbf0d51e8ce1579f5ab3184ee7fa1afe91d71b4d5b |
|
MD5 | b58ac55bb5480a90b8460ca0406eb141 |
|
BLAKE2b-256 | 811bd1fbcd18de52b7b347db43cb60b807f2d59036b045a0a248fcaaa6f049df |
File details
Details for the file compactdata-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: compactdata-0.0.4-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.2 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d78ad01a68be90c88a3374479618847c72a696606dd7527152255957021b5e9c |
|
MD5 | e32cdd4cbf1051efd7ed37a0aa4e7bd5 |
|
BLAKE2b-256 | c4c723b20ad2b3b5a01db2e258351aff097c26c6fbc35190c34da53ca383ba21 |