Skip to main content

A Python library for compressing and decompressing JSON data using Brotli

Project description

JSONBrotliMinifyer

A Python library for compressing and decompressing JSON data using the Brotli compression algorithm.

Features

  • Compress JSON-serializable Python objects (dicts, lists, strings, numbers, etc.) into compact byte representations.
  • Decompress Brotli-compressed data back to the original JSON objects.
  • Compress and decompress JSON files directly.
  • Efficient lossless compression suitable for data storage and transmission.

Installation

Install the library using pip:

pip install jsonbrotliminifyer

Or install from source:

git clone https://github.com/egorserdyuk/jsonbrotliminifyer.git
cd jsonbrotliminifyer
pip install -e .

Usage

import jsonbrotliminifyer

# Original JSON data
data = {
    "name": "John Doe",
    "age": 30,
    "items": ["apple", "banana", "cherry"],
    "active": True
}

# Compress the data (with default quality 11)
compressed = jsonbrotliminifyer.compress_json(data)
print(f"Compressed size: {len(compressed)} bytes")

# Compress with custom quality (0-11, lower = faster but larger)
compressed_fast = jsonbrotliminifyer.compress_json(data, quality=0)
print(f"Fast compression size: {len(compressed_fast)} bytes")

# Decompress the data
decompressed = jsonbrotliminifyer.decompress_json(compressed)
print(decompressed)  # Should match the original data

File Compression

import jsonbrotliminifyer

# Compress a JSON file (with default quality 11)
jsonbrotliminifyer.compress_json_file('input.json', 'output.br')

# Compress with custom quality
jsonbrotliminifyer.compress_json_file('input.json', 'output_fast.br', quality=0)

# Decompress a compressed file back to JSON
jsonbrotliminifyer.decompress_json_file('output.br', 'restored.json')

API

compress_json(json_obj, quality=11)

Compresses a JSON-serializable Python object.

  • Parameters:
    • json_obj - Any JSON-serializable Python object
    • quality - Compression quality level (0-11), default 11 (best compression)
  • Returns: bytes - The compressed data

decompress_json(compressed_bytes)

Decompresses Brotli-compressed data back to the original JSON object.

  • Parameters: compressed_bytes - The compressed data as bytes
  • Returns: The original Python object

compress_json_file(input_path, output_path, quality=11)

Compresses a JSON file using Brotli compression.

  • Parameters:
    • input_path - Path to the input JSON file
    • output_path - Path to the output compressed file
    • quality - Compression quality level (0-11), default 11 (best compression)

decompress_json_file(input_path, output_path)

Decompresses a Brotli-compressed file back to a JSON file.

  • Parameters:
    • input_path - Path to the input compressed file
    • output_path - Path to the output JSON file

Dependencies

  • brotli - Python bindings for the Brotli compression library

Testing

Run the tests using unittest:

python -m unittest tests.test_jsonbrotliminifyer

License

MIT License

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

jsonbrotliminifyer-0.3.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsonbrotliminifyer-0.3.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file jsonbrotliminifyer-0.3.0.tar.gz.

File metadata

  • Download URL: jsonbrotliminifyer-0.3.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jsonbrotliminifyer-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c7ef86d040257a4ee558db1038ed23c863ebf148884761f5edb9ae6199d76f5f
MD5 c41a9db82e21c445656c810ac96245de
BLAKE2b-256 87cbac3db3b8b4ca801bb4c9fda9daa5f41cf9a6fcbf76e8b1a300b0d22a824c

See more details on using hashes here.

File details

Details for the file jsonbrotliminifyer-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jsonbrotliminifyer-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ff4e2b28299de0f0b8135851cb14b5965bd3a01e4ede687defbf6f72a9db7e0
MD5 b8f77c1044e1d74ccd8e1beb70843d9f
BLAKE2b-256 5444b56bf70be6a39e85b63de68d73943757868dfec2ba6411bb8dd4f95712b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page