Skip to main content

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


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.27.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

tiny_storage-1.0.27-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page