Skip to content

Instantly share code, notes, and snippets.

@DxDiagDx
Created January 13, 2023 08:56
Show Gist options
  • Save DxDiagDx/8676f5edbb7ac22aa4240ebf97080d49 to your computer and use it in GitHub Desktop.
Save DxDiagDx/8676f5edbb7ac22aa4240ebf97080d49 to your computer and use it in GitHub Desktop.
environs - Переменные окружения Python
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