Skip to main content

Simple but useful python library that helps you to store and manage user preferences.

Project description

PREFS logo

Python Version PYPI Downloads Stars Watchers
Build Last commit Size Top languages License MIT
made-with-python

What is PREFS?

PREFS is a simple but useful python library to store and manage user preferences.

How does PREFS work?

In a nutshell when you initialize PREFS class, PREFS checks if a file exists with the given filename: if it exists, read it; if doesn't, create it using prefs parameter.

Installation:

On windows: pip install PREFS

On MacOS and Linux: pip3 install PREFS

Syntax:

Each PREFS file is an instance of the PREFS class:
PREFS class has one required parameter, which is a dictionary with the default preferences, default means the preferences that all users will have at first time.

user_prefs = PREFS.PREFS(prefs = {
  "theme": "light", 
  "lang": "en", 
  "keybindings": {"Ctrl+C": "Copy", "Ctrl+V": "Paste", "Ctrl+X": "Cut"}
})

This code will create a file like this:

#PREFS
theme='light'
lang='en'
keybindings=>
  Ctrl+C='Copy'
  Ctrl+V='Paste'
  Ctrl+X='Cut'

A total human readable file that supports cascade/tree in nested dictionaries.


The main methods to manage the preferences are are:

  • read_prefs(): Returns a dictionary reading the PREFS file.

  • write_prefs(): Requires two arguments, first the name of the pref that you want to change (if pref exists) or create if it doesn't, and second argument is the value that you want to assign to the pref. If using nested dictionaries pass in key parameter the keys path separated by a forward slash, e.g.: write_prefs("keybindings/Ctr+C", "Ctrl+D")

  • write_multiple_prefs(): Requires a list of prefs and a list of values to write. As it names says writes multiple prefs in a more efficient way than calling write_prefs() multiple times.

  • convert_to_json(): Converts the PREFS file into a json one.

Methods outside PREFS class:

  • read_json_file(): Requires a the filename of the json file to read and returns it's value.

  • read_yaml_file(): Requires a the filename of the yaml file to read and returns it's value.

  • read_prefs_file(): Given the filename of a PREFS file (which you can create manually) reads it and returns it's value.

Documentation

PREFS documentation can be found at https://patitotective.github.io/PREFS/ with more examples and information.

Extra info.


Links

v0.2

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

PREFS-0.2.tar.gz (16.1 kB view details)

Uploaded Source

File details

Details for the file PREFS-0.2.tar.gz.

File metadata

  • Download URL: PREFS-0.2.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for PREFS-0.2.tar.gz
Algorithm Hash digest
SHA256 1fe11b3288dd7c5a267ea23085b9e07a80890300c8019a1f7a0a8f6c1e23e9af
MD5 dff2891908150198f91ef9be2b3fade2
BLAKE2b-256 e56b17214ff7a2ee8b834b71ae75232f02846d8ddb5c8113521be7c0d777699f

See more details on using hashes here.

Supported by

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