Skip to content

[FEATURE] support Pydantic BaseModel to "collect" all kwargs, like FastAPI #679

Answered by xkollar
odoublewen asked this question in Questions
Discussion options

You must be logged in to vote

Thinking about it more I came up with slightly nicer workaround:

from enum import StrEnum
from typing import Never

import typer
from pydantic import BaseModel, ConfigDict
from typing_extensions import Annotated, override


class Env(StrEnum):
    local = "local"
    dev = "dev"
    research = "research"
    pre = "pre"
    prod = "prod"


class Config(BaseModel):
    environment: Annotated[Env, typer.Option(help="Environment to run the service in")]
    api_key: Annotated[str, typer.Option(help="API key to authenticate with")]
    port: Annotated[int, typer.Option(help="Port to run the service on")] = 8080
    debug: Annotated[bool, typer.Option(help="Enable debug mode")] = False


def f…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@shomeax
Comment options

@xkollar
Comment options

@xkollar
Comment options

Answer selected by odoublewen
@odoublewen
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
4 participants