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
Built Distribution
Close
Hashes for tiny_storage-unstable-0.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c302e7fc4abba3b64d4565eca2a5974b3643c793b478f48610a40f6109d79dc |
|
MD5 | 5a01c63e70542eb4dd6d732f861a570d |
|
BLAKE2b-256 | 60b4af48099a144622b450fa7c893f8606e034bacf5d90523adcd8dffa207f95 |
Close
Hashes for tiny_storage_unstable-0.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0474d8a492f40919d5f3c6b220effcb85b0f4df83aa8c8480a47f1220a61de0d |
|
MD5 | d702ab6143a96236171b9b39d093c0c7 |
|
BLAKE2b-256 | c19a99d51faf3d9ee2169d6e5ebd67fe42442fc4c370773f0831959ac74b73f2 |