Easy settings module
Project description
🌴 EZ Settings
EZ Settings is a very simple, lightweight settings module that makes it easy to get and set settings for your application. It's all stored in a JSON file, so any value you want to store has to be able to be serialized in a JSON file.
Initializing
from ez_settings.ez_settings import EZSettings
settings = EZSettings("/home/applications/my_app/settings.json")
Setting values
I like to make simple classes to store setting names, just because it makes it easier to autocomplete when writing code. You can also just pass in a normal string in the set
and get
functions.
from ez_settings.ez_settings import EZSettings
class Settings:
NAME = "name"
POSITION = "position"
SUPERBOWL_WINS = "superbowl_wins"
TEAMS = "teams"
ACTIVE = "active"
settings = EZSettings("/home/applications/my_app/settings.json")
settings.set(Settings.NAME, "Tom Brady")
settings.set(Settings.SUPERBOWL_WINS, 5)
Getting values
from ez_settings.ez_settings import EZSettings
class Settings:
NAME = "name"
POSITION = "position"
SUPERBOWL_WINS = "superbowl_wins"
TEAMS = "teams"
ACTIVE = "active"
settings = EZSettings("/home/applications/my_app/settings.json")
championships = settings.get(Settings.SUPERBOWL_WINS)
List values
You can append or pop items if the value of your setting is a list
from ez_settings.ez_settings import EZSettings
class Settings:
NAME = "name"
POSITION = "position"
SUPERBOWL_WINS = "superbowl_wins"
TEAMS = "teams"
ACTIVE = "active"
settings = EZSettings("/home/applications/my_app/settings.json")
# set a list value
settings.set(Settings.TEAMS, ["New England"])
# add to the list value
settings.append(Settings.TEAMS, "Tampa Bay")
# remove from the list values
settings.pop(Settings.TEAMS, "New England")
Deleting a single setting
from ez_settings.ez_settings import EZSettings
class Settings:
NAME = "name"
POSITION = "position"
SUPERBOWL_WINS = "superbowl_wins"
TEAMS = "teams"
ACTIVE = "active"
settings = EZSettings("/home/applications/my_app/settings.json")
settings.remove(Settings.POSITION)
Wiping all settings
from ez_settings.ez_settings import EZSettings
settings = EZSettings("/home/applications/my_app/settings.json")
settings.reset()
Checking if a setting exists
from ez_settings.ez_settings import EZSettings
settings = EZSettings("/home/applications/my_app/settings.json")
settings.exists("Injuries")
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
ez_settings-1.0.1.tar.gz
(3.1 kB
view hashes)
Built Distribution
Close
Hashes for ez_settings-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3b35fbed122e3c10f21e1b4cc072ff9ae7ec3f8b7893a591997899ce19fad6f |
|
MD5 | 3afbd9da83aac9f37def17b999db6428 |
|
BLAKE2b-256 | e566e431a84ae8c1fc8a28febfdd210de0bd7e57976a50d2ce9bfcba8ea89735 |