Created
January 13, 2023 08:56
-
-
Save DxDiagDx/8676f5edbb7ac22aa4240ebf97080d49 to your computer and use it in GitHub Desktop.
environs - Переменные окружения Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
from environs import Env | |
@dataclass | |
class Bots: | |
bot_token: str | |
admin_id: str | |
@dataclass | |
class Db: | |
user: str | |
host: str | |
password: str | |
db: str | |
@dataclass | |
class Settings: | |
bots: Bots | |
db: Db | |
def get_settings(path: str): | |
env = Env() | |
env.read_env(path) | |
return Settings( | |
bots=Bots( | |
bot_token=("BOT_TOKEN"), | |
admin_id=("ADMIN_ID") | |
), | |
db=Db( | |
user=env.str("DB_USER"), | |
host=env.str("DB_HOST"), | |
password=env.str("DB_PASSWORD"), | |
db=env.str("DB_DATABASE") | |
) | |
) | |
settings = get_settings('input') | |
print(settings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment