Skip to content

ValUtils/ValStorage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ValStorage

PyPI - Version GitHub deployments GitHub

A helper module for managing paths and environments for the ValUtils project.

Features

  • Easy file system access
  • Comprehensible API
  • Default settings from dataclass_json

Installation

The preferred method of installation is through pip but if you know better use the package manager that you want.

pip install ValStorage

Reference

ValStorage contains the following methods:

  • list_dir to list a directory
  • save_to_drive to save a string to the filesystem
  • read_from_drive to read a string to the filesystem
  • json_write to write data as json to the filesystem
  • json_read to read data as json to the filesystem
  • utils_path to get the path for ValUtils

And the special get_settings method explained down below.

Usage

Basic usage

from ValStorage import json_read, json_write, utils_path

data = json_read(utils_path / "data.json")
data["time"] = 100
json_write(data, utils_path / "data.json")

Magic usage

In this use case we export all the functionality as a local module and also our local settingsPath referencing the module directory.

from ValStorage import *


def set_path():
    global settingsPath
    utilsPath = utils_path()
    settingsPath = utilsPath / "test"
    create_path(settingsPath)


set_path()

Settings API

The get_settings method takes a dataclass_json and a path as parameters and it retrieves or the settings in said path or the default settings. For that our dataclass needs to have default values, here's a quick example:

from ValStorage import get_settings
from dataclass_json import DataClassJsonMixin
from dataclass import dataclass

@dataclass
class Data(DataClassJsonMixin):
    time: float = 0
    argument: string = "default"

get_settings(Data, "data.json")

If data.json doesn't exist it gets filled with the default data provided by our dataclass.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages