Skip to main content

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.

Metadata

Release files for compactdata 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for compactdata 0.0.4
File Size Uploaded Provenance Actions
compactdata-0.0.4.tar.gz 12.0 kB Without provenance Details for compactdata-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for compactdata 0.0.4
File Interpreter ABI Platform Actions
compactdata-0.0.4-py3-none-any.whl Python 3 none any Details for compactdata-0.0.4-py3-none-any.whl

Total release size: 24.6 kB

Release files / compactdata-0.0.4.tar.gz

Download URL compactdata-0.0.4.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
78dffbf36f8ef94ceb5281bbf0d51e8ce1579f5ab3184ee7fa1afe91d71b4d5b
BLAKE2b-256 checksum
How to use checksums
811bd1fbcd18de52b7b347db43cb60b807f2d59036b045a0a248fcaaa6f049df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.2 Darwin/22.3.0

Release files / compactdata-0.0.4-py3-none-any.whl

Download URL compactdata-0.0.4-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d78ad01a68be90c88a3374479618847c72a696606dd7527152255957021b5e9c
BLAKE2b-256 checksum
How to use checksums
c4c723b20ad2b3b5a01db2e258351aff097c26c6fbc35190c34da53ca383ba21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.2 Darwin/22.3.0

Security for compactdata 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page