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.26.tar.gz
(3.0 kB
view hashes)
Built Distribution
Close
Hashes for tiny_storage-1.0.26-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 134bb4f8f6831df3fd7740c94df8bbb233c28cad6ec24fdbc8b3a1ce80af28ca |
|
MD5 | c3f5e2bbd6d7533e51077f4b1201ca15 |
|
BLAKE2b-256 | 29c39fc47a8eaf8da5072a1ac1d7bd431dfbe2b3e5a97a5f623987a9e34e4432 |