Skip to main content

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)

Uploaded Source

Built Distribution

ez_settings-1.0.1-py3-none-any.whl (4.1 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