Skip to content

Settings

Who never had that feeling that sometimes haing some database settings would be nice? Well, since Edgy is from the same author of Esmerald and since Esmerald is settings oriented, why not apply the same principle but in a simpler manner but to Edgy?

This is exactly what happened.

Edgy Settings Module

The way of using the settings object within a Edgy use of the ORM is via:

  • EDGY_SETTINGS_MODULE environment variable.

All the settings are Pydantic BaseSettings objects which makes it easier to use and override when needed.

EDGY_SETTINGS_MODULE

Edgy by default uses is looking for a EDGY_SETTINGS_MODULE environment variable to run and apply the given settings to your instance.

If no EDGY_SETTINGS_MODULE is found, Edgy then uses its own internal settings which are widely applied across the system.

Custom settings

When creating your own custom settings class, you should inherit from EdgySettings which is the class responsible for all internal settings of Edgy and those can be extended and overriden with ease.

Something like this:

myproject/configs/settings.py
from typing import Optional

from edgy import EdgySettings
from edgy.conf.enums import EnvironmentType


class MyCustomSettings(EdgySettings):
    """
    My settings overriding default values and add new ones.
    """

    environment: Optional[str] = EnvironmentType.TESTING

    # new settings
    my_new_setting: str = "A text"

Super simple right? Yes and that is the intention. Edgy does not have a lot of settings but has some which are used across the codebase and those can be overriden easily.

Danger

Be careful when overriding the settings as you might break functionality. It is your own risk doing it.

Parameters
  • ipython_args - List of arguments passed to ipython when starting the edgy shell.

    Default: ["--no-banner"]

  • ptpython_config_file - Config file to be loaded into ptpython when starting the edgy shell --kernel ptpython.

    Default: "~/.config/ptpython/config.py"

How to use it

Similar to esmerald settings, Edgy uses it in a similar way.

Using the example above and the location myproject/configs/settings.py, the settings should be called like this:

$ EDGY_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings edgy <COMMAND>

Example:

Starting the default shell

$ EDGY_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings edgy shell

Starting the PTPython shell

$ EDGY_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings edgy shell --kernel ptpython

Creating the migrations folder

$ EDGY_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings edgy init

Generating migrations

$ EDGY_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings edgy makemigrations

Appying migrations

$ EDGY_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings edgy migrate

And the list goes on and on, you get the gist. To understand which commands are available, check the commands available to you and the shell support for the Edgy shell support.