Module xsettings.env_settings

Expand source code
from xsettings.settings import BaseSettings
from .retreivers import EnvVarRetriever


class EnvVarSettings(BaseSettings, default_retrievers=EnvVarRetriever()):
    """
    Base subclass of `xsettings.settings.BaseSettings` with the default retriever
    set as the `xsettings.retrievers.EnvVarRetriever`.

    This means when a settings field is defined without a retriever
    it will use the `xsettings.retrievers.EnvVarRetriever` by default to retriever its value.

    The `xsettings.retrievers.EnvVarRetriever` will check `os.environ` dict for the values.

    It first tries with the plain name of the field.

    If a value is not found (not even an empty string) it will next try looking up the env-var
    by upper-casing the name
    (as it's extremely common to use all upper-case vars for environmental var names).

    If it still can't be found then None will be returned and the system will look
    at the next retriever and/or the default value for the field as necessary/needed.
    """
    pass

Classes

class EnvVarSettings (retrievers: Optional[Union[List[SettingsRetrieverProtocol], SettingsRetrieverProtocol]] = None, **kwargs)

Base subclass of BaseSettings with the default retriever set as the xsettings.retrievers.EnvVarRetriever.

This means when a settings field is defined without a retriever it will use the xsettings.retrievers.EnvVarRetriever by default to retriever its value.

The xsettings.retrievers.EnvVarRetriever will check os.environ dict for the values.

It first tries with the plain name of the field.

If a value is not found (not even an empty string) it will next try looking up the env-var by upper-casing the name (as it's extremely common to use all upper-case vars for environmental var names).

If it still can't be found then None will be returned and the system will look at the next retriever and/or the default value for the field as necessary/needed.

Set attributes to values that are passed via key-word arguments, these are the initial values for the settings instance your creating; they are set directly on the instance as if you did this:

# These two statements do the same thing:
obj = SomeSettings(some_keyword_arg="hello")

obj = SomeSettings()
obj.some_keyword_arg="hello"

Args

retrievers
can be used to populate new instance's retrievers,

see BaseSettings.settings__instance_retrievers.

Expand source code
class EnvVarSettings(BaseSettings, default_retrievers=EnvVarRetriever()):
    """
    Base subclass of `xsettings.settings.BaseSettings` with the default retriever
    set as the `xsettings.retrievers.EnvVarRetriever`.

    This means when a settings field is defined without a retriever
    it will use the `xsettings.retrievers.EnvVarRetriever` by default to retriever its value.

    The `xsettings.retrievers.EnvVarRetriever` will check `os.environ` dict for the values.

    It first tries with the plain name of the field.

    If a value is not found (not even an empty string) it will next try looking up the env-var
    by upper-casing the name
    (as it's extremely common to use all upper-case vars for environmental var names).

    If it still can't be found then None will be returned and the system will look
    at the next retriever and/or the default value for the field as necessary/needed.
    """
    pass

Ancestors

Static methods

def __init_subclass__(thread_sharable=Default, attributes_to_skip_while_copying: Optional[Iterable[str]] = Default, **kwargs)

Inherited from: BaseSettings.__init_subclass__

Args

thread_sharable
If False: While a dependency is lazily auto-created, we will ensure we do it per-thread, and not make it visible …
def grab() ‑> ~T

Inherited from: BaseSettings.grab

Gets a potentially shared dependency from the current udpend.context.XContext

def proxy() ‑> ~R

Inherited from: BaseSettings.proxy

Returns a proxy-object, that when and attribute is asked for, it will proxy it to the current object of cls

def proxy_attribute(attribute_name: str) ‑> Any

Inherited from: BaseSettings.proxy_attribute

Returns a proxy-object, that when and attribute is asked for, it will proxy it to the current attribute value on the current object of cls

Instance variables

var obj

Inherited from: BaseSettings.obj

class property/attribute that will return the current dependency for the subclass it's asked on by calling Dependency.grab, passing no extra …

var settings__instance_retrievers : List[SettingsRetrieverProtocol]

Inherited from: BaseSettings.settings__instance_retrievers

You can add one or more retrievers to this instance of settings (won't modify default_retrievers for the entire class, only modifies this specific …

Methods

def __call__(self, func)

Inherited from: BaseSettings.__call__

This makes Resource subclasses have an ability to be used as function decorators by default unless this method is overriden to provide some other …

def __copy__(self)

Inherited from: BaseSettings.__copy__

Basic shallow copy protection (I am wondering if I should just remove this default copy code) …