ShortIO library is intended to avoid context manager boilerplate in simple io operations. The library supports plain text, JSON, pickle and YAML (PyYAML impl).
Inspired by ilio.
pip install shortio
from shortio import read, write
s = read('filename')
write('filename', s)
from shortio import read, write
s = read('filename', 'rb')
write('filename', s, 'wb')
from shortio import read_json, write_json
d = read_json('filename.json')
write_json('filename.json', d)
from shortio import read_pickle, write_pickle
d = read_pickle('filename.pkl')
write_pickle('filename.pkl', d)
Since python does not support YAML out of the box you have to install PyYAML.
pip install PyYAML>=5.1
from shortio import read_yaml, write_yaml
d = read_yaml('filename.yaml')
write_yaml('filename.yaml', d)