Skip to content

Environnement variable fallback annotation #455

@jRimbault

Description

@jRimbault

Hi, what do you think of adding a tyro.conf.Env to the available annotations?

It would be used something like this:

@dataclasses.dataclass
class ServerConfig:
    # Env var name derived automatically from field name. Required.
    secret: Annotated[str, tyro.conf.Env()]

    # Falls back to HOST env var if --host is not passed.
    host: Annotated[str, tyro.conf.Env()] = "localhost"

    # Explicit env var name overrides derivation.
    port: Annotated[int, tyro.conf.Env("APP_PORT")] = 8080

Priority would be: hardcoded < environment < flags.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions