How to use the pydantic.BaseSettings function in pydantic

To help you get started, we’ve selected a few pydantic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github checktheroads / hyperglass / hyperglass / configuration / models.py View on Github external
"""Class model for params.branding"""

    site_name: str = "hyperglass"

    class Colors(BaseSettings):
        """Class model for params.colors"""

        primary: Color = "#40798c"
        secondary: Color = "#330036"
        danger: Color = "#a21024"
        warning: Color = "#eec643"
        light: Color = "#fbfffe"
        dark: Color = "#383541"
        background: Color = "#fbfffe"

    class Credit(BaseSettings):
        """Class model for params.branding.credit"""

        enable: bool = True

    class Font(BaseSettings):
        """Class model for params.branding.font"""

        primary: str = "Nunito"
        mono: str = "Fira Code"

    class HelpMenu(BaseSettings):
        """Class model for params.branding.help_menu"""

        enable: bool = True

    class Logo(BaseSettings):
github MolSSI / QCElemental / qcelemental / util / autodocs.py View on Github external
def is_pydantic(test_object):
    try:
        instance = isinstance(test_object, BaseSettings) or isinstance(test_object, BaseModel)
    except TypeError:
        instance = False
    try:
        subclass = issubclass(test_object, BaseSettings) or issubclass(test_object, BaseModel)
    except TypeError:
        subclass = False
    return instance or subclass
github checktheroads / hyperglass / hyperglass / configuration / models.py View on Github external
hostnames.append(dev)
            for vrf in router_params.dict()["vrfs"]:
                vrfs.add(vrf)
        Routers.routers = routers
        Routers.hostnames = hostnames
        Routers.vrfs = list(vrfs)
        return Routers()

    class Config:
        """Pydantic Config"""

        validate_all = True
        validate_assignment = True


class Network(BaseSettings):
    """Model for per-network/asn config in devices.yaml"""

    display_name: str


class Networks(BaseSettings):
    """Base model for networks class"""

    @classmethod
    def import_params(cls, input_params):
        """
        Imports passed dict from YAML config, removes unsupported
        characters from device names, dynamically sets attributes for
        the credentials class.
        """
        obj = Networks()
github binderclip / code-snippets-python / packages / pydantic_sp / setting_sp.py View on Github external
from pydantic import BaseSettings


class Settings(BaseSettings):
    redis_host = 'localhost'    # set os env APP_REDIS_HOST to overwrite
    redis_port = 6379
    redis_database = 0
    debug = False   # 'true' and '1' are True, 'false' and '0' are False

    class Config:
        env_prefix = 'APP_'


def main():
    settings = Settings()
    print(settings.redis_host)
    print(settings.redis_port, type(settings.redis_port))
    print(settings.debug)
github samuelcolvin / aiohttp-toolbox / atoolbox / settings.py View on Github external
pg_dsn_default = 'postgres://postgres@localhost:5432/app'


try:
    from cryptography.fernet import Fernet
except ImportError:
    auth_key_default = None
else:
    # generate_key is used to avoid a public default value ever being used in production
    auth_key_default = Fernet.generate_key().decode()

# see https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha-what-should-i-do
GREPAPTCHA_TEST_SECRET = '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe'


class BaseSettings(_BaseSettings):
    worker_func: str = None
    create_app: str = 'main.create_app'
    patch_paths: List[str] = []

    sql_path: Path = 'models.sql'
    pg_dsn: Optional[str] = pg_dsn_default
    # eg. the db already exists on heroku and never has to be created
    pg_db_exists = False

    redis_settings: Optional[RedisSettings] = redis_settings_default
    port: int = 8000

    auth_key: str = auth_key_default

    max_request_size = 10 * 1024 ** 2  # 10MB
    locale = 'en_US.utf8'
github checktheroads / hyperglass / hyperglass / configuration / models.py View on Github external
bgp_aspath: str = 'show bgp {afi} unicast quote-regexp "{target}"'
            bgp_route: str = "show bgp {afi} unicast {target} | exclude pathid:|Epoch"
            ping: str = (
                "ping {afi} {target} repeat 5 source {source} | exclude Type escape"
            )
            traceroute: str = (
                "traceroute ipv6 {target} timeout 1 probe 2 source {source} "
                "| exclude Type escape"
            )

        vpnv4: VPNv4 = VPNv4()
        vpnv6: VPNv6 = VPNv6()
        ipv4: IPv4 = IPv4()
        ipv6: IPv6 = IPv6()

    class CiscoXR(BaseSettings):
        """Class model for default cisco_xr commands"""

        class Dual(BaseSettings):
            """Default commands for dual afi commands"""

            bgp_community: str = (
                "show bgp all unicast community {target} | utility egrep -v "
                '"\\(BGP |Table |Non-stop\\)"'
            )
            bgp_aspath: str = (
                "show bgp all unicast regexp {target} | utility egrep -v "
                '"\\(BGP |Table |Non-stop\\)"'
            )

        class IPv4(BaseSettings):
            """Default commands for ipv4 commands"""
github identixone / fastapi_contrib / fastapi_contrib / conf.py View on Github external
from pydantic import BaseSettings
from typing import List


class Settings(BaseSettings):
    """
    Configuration settings for this library.

    For now you could only change the settings
    via CONTRIB_ environment variables.

    :param logger: Dotted path to the logger (using this attribute, standard
                   logging methods will be used: logging.debug(), .info(), etc.
    :param log_level: Standard LEVEL for logging (DEBUG/INFO/WARNING/etc.)
    :param debug_timing: Whether to enable time logging for decorated functions
    :param request_id_header: String name for header, that is expected to have
                              unique request id for tracing purposes.
                              Might go away when we add opentracing here.
    :param mongodb_dsn: DSN connection string to MongoDB
    :param mongodb_dbname: String name of a database to connect to in MongoDB
    :param mongodb_id_generator: Dotted path to the function, which will
github checktheroads / hyperglass / hyperglass / configuration / models.py View on Github external
"""Class model for params.branding.credit"""

        enable: bool = True

    class Font(BaseSettings):
        """Class model for params.branding.font"""

        primary: str = "Nunito"
        mono: str = "Fira Code"

    class HelpMenu(BaseSettings):
        """Class model for params.branding.help_menu"""

        enable: bool = True

    class Logo(BaseSettings):
        """Class model for params.branding.logo"""

        path: str = "ui/images/hyperglass-dark.png"
        width: int = 384
        favicons: str = "ui/images/favicons/"

    class PeeringDb(BaseSettings):
        """Class model for params.branding.peering_db"""

        enable: bool = True

    class Terms(BaseSettings):
        """Class model for params.branding.terms"""

        enable: bool = True
github checktheroads / hyperglass / hyperglass / configuration / models.py View on Github external
networks = {}
        for (netname, params) in input_params.items():
            netname = clean_name(netname)
            setattr(Networks, netname, Network(**params))
            networks.update({netname: Network(**params).dict()})
        Networks.networks = networks
        return obj

    class Config:
        """Pydantic Config"""

        validate_all = True
        validate_assignment = True


class Credential(BaseSettings):
    """Model for per-credential config in devices.yaml"""

    username: str
    password: SecretStr


class Credentials(BaseSettings):
    """Base model for credentials class"""

    @classmethod
    def import_params(cls, input_params):
        """
        Imports passed dict from YAML config, removes unsupported
        characters from device names, dynamically sets attributes for
        the credentials class.
        """
github checktheroads / hyperglass / hyperglass / configuration / models.py View on Github external
class BgpCommunity(BaseSettings):
        """Class model for params.features.bgp_community"""

        enable: bool = True

        class Regex(BaseSettings):
            """Class model for params.features.bgp_community.regex"""

            decimal: str = r"^[0-9]{1,10}$"
            extended_as: str = r"^([0-9]{0,5})\:([0-9]{1,5})$"
            large: str = r"^([0-9]{1,10})\:([0-9]{1,10})\:[0-9]{1,10}$"

        regex: Regex = Regex()

    class BgpAsPath(BaseSettings):
        """Class model for params.features.bgp_aspath"""

        enable: bool = True

        class Regex(BaseSettings):
            """Class model for params.bgp_aspath.regex"""

            mode: constr(regex="asplain|asdot") = "asplain"
            asplain: str = r"^(\^|^\_)(\d+\_|\d+\$|\d+\(\_\.\+\_\))+$"
            asdot: str = (
                r"^(\^|^\_)((\d+\.\d+)\_|(\d+\.\d+)\$|(\d+\.\d+)\(\_\.\+\_\))+$"
            )

        regex: Regex = Regex()

    class Ping(BaseSettings):