Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created July 5, 2020 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save podhmo/7773d6f16468203833ae655a5b273afd to your computer and use it in GitHub Desktop.
Save podhmo/7773d6f16468203833ae655a5b273afd to your computer and use it in GitHub Desktop.
import typing_extensions as tx
import sheetconf
from pydantic import BaseModel, Field
class XXXConfig(BaseModel):
name: str
token: str
class YYYConfig(BaseModel):
name: str = Field(default="yyy", description="name of yyy")
token: str = Field(description="token of yyy")
class LoggerConfig(BaseModel):
level: tx.Literal["DEBUG", "INFO", "WARNING", "ERROR"]
class Config(BaseModel):
xxx: XXXConfig
yyy: YYYConfig
logger: LoggerConfig
if __name__ == "__main__":
url = "https://docs.google.com/spreadsheets/d/1PgLfX5POop6QjpgjDLE9wbSWWXJYcowxRBEpxmpG8og"
config = sheetconf.loadfile(url, config=Config, format="spreadsheet", adjust=True)
print(config)
# Config(logger=LoggerConfig(level='INFO'), xxx=XXXConfig(name='xxx', token='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'), yyy=YYYConfig(name='yyy', token='yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment