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 details)
Built Distribution
File details
Details for the file ez_settings-1.0.1.tar.gz
.
File metadata
- Download URL: ez_settings-1.0.1.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c63421869f8f33d57446ad632998707981a83f3031d40c62d1a700330d33b2b0 |
|
MD5 | 04a09430b70178507d21a401c227bc70 |
|
BLAKE2b-256 | 028c56151077471ec2fee4122723090ce6b545f8ef55e9b2ed02cee2d29f630e |
File details
Details for the file ez_settings-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: ez_settings-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3b35fbed122e3c10f21e1b4cc072ff9ae7ec3f8b7893a591997899ce19fad6f |
|
MD5 | 3afbd9da83aac9f37def17b999db6428 |
|
BLAKE2b-256 | e566e431a84ae8c1fc8a28febfdd210de0bd7e57976a50d2ce9bfcba8ea89735 |