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
File details
Details for the file tiny_storage-unstable-unstable-0.0.0.tar.gz
.
File metadata
- Download URL: tiny_storage-unstable-unstable-0.0.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5e0d274d10040092ce8b0b995f128a29e17800567f7f8b23f5c78b0cf33d7e2 |
|
MD5 | 7959dacb6e8871f03f3fc965d98cee27 |
|
BLAKE2b-256 | b151d3662a75bbcfca1df37cee238f0e6fee13f025372529ab68bf9c049d229b |
File details
Details for the file tiny_storage_unstable_unstable-0.0.0-py3-none-any.whl
.
File metadata
- Download URL: tiny_storage_unstable_unstable-0.0.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47c39052f0c5577ee3b747143a0f4a41d0a261f9bc64ee6fe2a90f36c5fa97da |
|
MD5 | 50c2df9fe5ce0163715f6e7f8ca3c4e0 |
|
BLAKE2b-256 | 74f75734d1162c46c80d6665d72114fd70ca9d95806ba90870d73f835e71d9b4 |