Tiny library for key-value single-file application data storage
Project description
Summary
Library for application data storage. It is:
- tiny
- key-value
- single-file
- YAML based
Example
from tiny_storage import Unit, Type
import sys
# matches the file /etc/example-app/yaml or %PROGRAMDATA%\example-app\config.yaml
config = Unit('example-app', Type.global_config)
if sys.argv[1] == 'set-greeting':
# changes greeting only if does not exist
if not config('lines.greeting').try_put(sys.argv[2]):
print('Greeting already exists. It should not be changed.')
else:
# prints greeting if it exists or given string
print(config('lines.greeting').pull('Hello, world!'))
Installation
pip install tiny_storage
Mechanics
Import tiny_storage and create storage unit:
import tiny_storage
storage = tiny_storage.Unit(name_of_your_app)
For placement configuration see CONVENTION.md.
Manipulate your storage unit:
storage('some.path').pull(your_value) # get value from storage or default value
storage('some.path').push(your_value) # overwrite, return your_value
storage('some.path').put(your_value) # set if does not exist, return final value
storage('some.path').try_push(your_value) # overwrite, return whether value differed
storage('some.path').try_put(your_value) # set if does not exist, return whether you were successful
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tiny_storage-1.0.23.tar.gz
(3.0 kB
view hashes)
Built Distribution
Close
Hashes for tiny_storage-1.0.23-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 008af2b7153cba58a3a1bff1ab67bf29d929a54a92fb08e8ed637a4b4191e1b1 |
|
MD5 | 8126fd6b8842a30949ac1d6ee18dce3b |
|
BLAKE2b-256 | 907e39119601245c7f3ffe3cc52be8686aa2c4668e31c2b7486ffb544fae3f3d |