Skip to main content

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 with atomic write operations to prevent data corruption.
  • 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')

Command Line Interface

After installation, you can use the jsonbrotlim command to compress and decompress JSON data from the command line.

Compress JSON data

# Compress a JSON file
jsonbrotlim compress --input-file input.json --output-file output.br

# Compress with custom quality (0-11)
jsonbrotlim compress --input-file input.json --output-file output.br --quality 0

# Compress JSON from stdin
echo '{"name": "test"}' | jsonbrotlim compress > output.br

Decompress JSON data

# Decompress a compressed file
jsonbrotlim decompress --input-file output.br --output-file restored.json

# Decompress from stdin
cat output.br | jsonbrotlim decompress

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
  • Raises: ValueError - If quality is not between 0 and 11

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
  • Raises: ValueError - If the data is not valid Brotli-compressed data or does not decode to valid JSON

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)
  • Raises: ValueError - If the input file does not exist, is not readable, contains invalid JSON, or if writing to the output file fails

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
  • Raises: ValueError - If the input file does not exist, is not readable, or if writing to the output file fails

Dependencies

  • Python >= 3.9
  • brotli - Python bindings for the Brotli compression library

Testing

Run the tests using unittest:

python -m unittest tests.test_jsonbrotliminifyer

Or using pytest

pytest tests/test_jsonbrotliminifyer.py

License

MIT License

Metadata

Release files for jsonbrotliminifyer 1.2.0

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

Source distribution (sdist)

Source distribution for jsonbrotliminifyer 1.2.0
File Size Uploaded Provenance Actions
jsonbrotliminifyer-1.2.0.tar.gz 8.9 kB Without provenance Details for jsonbrotliminifyer-1.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 16.3 kB

Release files / jsonbrotliminifyer-1.2.0.tar.gz

Download URL jsonbrotliminifyer-1.2.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
30792459e40f88343370eecbaa1c582d95791a3bba8588351dd854297a465772
BLAKE2b-256 checksum
How to use checksums
c78c721af7a2c8b49a55ad5c2f9f50c6839aa3ae7e1a4a3659f14f0600b5b01e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / jsonbrotliminifyer-1.2.0-py3-none-any.whl

Download URL jsonbrotliminifyer-1.2.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7569046ff7306fb4e05b03805e87420db40aa85edac6a7b3ea28e3c1a235f537
BLAKE2b-256 checksum
How to use checksums
ed795db8c8201149bf7d4c7e0506ae573900bc82b74a1341ecb4f413f28992c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for jsonbrotliminifyer 1.2.0

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