Created
February 21, 2021 20:23
-
-
Save gidgid/73daa9b2af99e9f20a73108737348280 to your computer and use it in GitHub Desktop.
shows a short recap of how to read different values by an env variables with Pydantic
This file contains hidden or 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 typing import Union | |
from pydantic import BaseSettings, parse_obj_as | |
from typing_extensions import Literal | |
class LocalContext(BaseSettings): | |
env: Literal["local"] # 1 | |
mongo_url: str | |
class ProdContext(BaseSettings): | |
env: Literal["prod"] # 1 | |
mongo_url: str | |
mongo_replicaset: str # 2 | |
Context = Union[LocalContext, ProdContext] # 3 | |
context = parse_obj_as(Context, {}) # 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment