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.32.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for tiny_storage-1.0.32-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edd60b384b353d3e1b5559900b887426d48ebfe1fb373b4b5903663ff1201841 |
|
MD5 | 88c8a35e2418e86d83609e880dd3686a |
|
BLAKE2b-256 | c8e1eb2ecd10a2e9896083effb37dee7108f3ade915397c260d3b6ad39889acb |