https://github.com/Minyus/smalldict
SmallDict: Python package to slim down a dict read from JSON or YAML to check the contents
https://github.com/Minyus/smalldict
Last synced: 6 days ago
JSON representation
SmallDict: Python package to slim down a dict read from JSON or YAML to check the contents
- Host: GitHub
- URL: https://github.com/Minyus/smalldict
- Owner: Minyus
- License: apache-2.0
- Created: 2021-03-27T11:30:50.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-28T03:56:31.000Z (about 4 years ago)
- Last Synced: 2024-09-20T07:07:20.177Z (8 months ago)
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SmallDict
SmallDict: Python package to slim down a dict read from JSON or YAML to check the contents
[](https://pypi.org/project/smalldict/)
[](https://badge.fury.io/py/smalldict)
[](https://github.com/Minyus/smalldict/blob/master/LICENSEj)
[](https://smalldict.readthedocs.io/)## Overview
When you open a big JSON or YAML file, the text viewer often freezes.
You can extract a small subset of a Python dict read from a JSON or YAML file to check the contents.## Install
### [Option 1] Install from the PyPI
```bash
pip install smalldict
```### [Option 2] Development install
This is recommended only if you want to modify the source code of SmallDict.
```bash
git clone https://github.com/Minyus/smalldict.git
cd smalldict
python setup.py develop
```## How to use
Example:
```python
from smalldict import SmallDictd = {
"key_1": ["value_1", "value_2", "value_3"],
"key_2": {"key_1": "value", "key_2": "value", "key_3": "value"},
"key_3": "value",
}def test_no_limit():
assert SmallDict(d).get() == ddef test_limit():
assert SmallDict(d).get(
dict_limit=2, list_limit=1, str_limit=3, json_out=None, yaml_out=None
) == {
"key_1": ["val"],
"key_2": {"key_1": "val", "key_2": "val"},
}
```JSON/YAML file input/output is supported.
- Input: Specify the path, either JSON (`.json`) or YAML (`.yaml`, `.yml`), as `d` argument for `SmallDict`.
- Output: Specify the path as `json_out` or `yaml_out` argument for `SmallDict.get` method.