Skip to main content

Python package that handles loading and dumping json files in a compressed fashion.

Project description

Travis CI build SonarCloud Quality SonarCloud Maintainability Codacy Maintainability Maintainability Pypi project Pypi total project downloads

Python package that handles loading and dumping JSON files in a compressed fashion. The library is loosely based on the compress_pickle library.

How do I install this package?

As usual, just download it using pip:

pip install compress_json

Tests Coverage

Since some software handling coverages sometimes get slightly different results, here’s three of them:

Coveralls Coverage SonarCloud Coverage Code Climate Coverate

Available compression modes

The compression modes, detected automatically by the file name, are gzip, bz2 and lzma, with the notable exception of zip which seems difficult to integrate in the JSON pipeline.

Usage example

The library is extremely easy to use:

import compress_json

D = {
    "A":{
        "B":"C"
    }
}
compress_json.dump(D, "filepath.json.gz") # for a gzip file
compress_json.dump(D, "filepath.json.bz") # for a bz2 file
compress_json.dump(D, "filepath.json.lzma") # for a lzma file

D1 = compress_json.load("filepath.json.gz") # for loading a gzip file
D2 = compress_json.load("filepath.json.bz") # for loading a bz2 file
D3 = compress_json.load("filepath.json.lzma") # for loading a lzma file

Some extra perks

The library makes available, other than the usual load and dump from the JSON library, also the methods load_load and local_dump which let you load and dump file in the same directory of wherever you are calling them, by using the call stack.

This can get useful especially when loading files within packages.

import compress_json

D = {
    "A":{
        "B":"C"
    }
}
compress_json.local_dump(D, "filepath.json.gz") # for a gzip file
compress_json.local_dump(D, "filepath.json.bz") # for a bz2 file
compress_json.local_dump(D, "filepath.json.lzma") # for a lzma file

D1 = compress_json.local_load("filepath.json.gz") # for loading a gzip file
D2 = compress_json.local_load("filepath.json.bz") # for loading a bz2 file
D3 = compress_json.local_load("filepath.json.lzma") # for loading a lzma file

Advanced usage

Clearly you can pass parameters to either the chosen compression mode or the json library as follows:

import compress_json

D = {
    "A":{
        "B":"C"
    }
}
compress_json.dump(
    D, "filepath.json.gz",
    compression_kwargs = {kwargs go here},
    json_kwargs = {kwargs go here}
)

D4 = compress_json.load(
    "filepath.json.gz",
    compression_kwargs = {kwargs go here},
    json_kwargs = {kwargs go here}
)

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

compress_json-1.0.4.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file compress_json-1.0.4.tar.gz.

File metadata

  • Download URL: compress_json-1.0.4.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for compress_json-1.0.4.tar.gz
Algorithm Hash digest
SHA256 170d0b8884815853f404715c09bb1db0c15fd57f5fb3548334cbbadb927d4981
MD5 def5e53a11018f6a0b408376d250d001
BLAKE2b-256 c09d1a79dbc3b9d69c57be363b4cc8bd6f278f919a0973f46c7bb831438c9333

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