zapier / jsonmask

Implements Google Partial Response dictionary pruning in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status Coverage Status PyPI Version

Overview

Implements Google Partial Response / json-mask in Python.

Requirements

  • Python 2.7
  • Python 3.6+

Installation

Install jsonmask with pip:

$ pip install jsonmask

or directly from the source code:

$ git clone https://github.com/zapier/jsonmask.git
$ cd jsonmask
$ python setup.py install

Usage

After installation, the package can imported:

$ python
>>> import jsonmask
>>> jsonmask.__version__

To prune dictionaries:

>>> import jsonmask
>>> mask = jsonmask.parse_fields('a,b(c,d)')
>>> jsonmask.apply_json_mask(
    {
        'a': {
            'nested_within_a': True,
        },
        'b' {
            'c': True,
            'd': {'Will get included?': 'Yes'},
            'e': 'Tough luck here',
        },
        'c': 'Definitely hopeless',
    },
    mask,
)

{
    'a': {
        'nested_within_a': True,
    },
    'b' {
        'c': True,
        'd': {'Will get included?': 'Yes'},
    },
}

About

Implements Google Partial Response dictionary pruning in Python

License:MIT License


Languages

Language:Python 82.3%Language:Makefile 17.7%