Skip to content
Discussion options

You must be logged in to vote

You can make IPv4Address (and other custom types) working by specifying parser parameter:

from ipaddress import IPv4Address

import typer
from typing_extensions import Annotated

def main(
    host: Annotated[
        IPv4Address,
        typer.Argument(
            parser=IPv4Address,
            default_factory=lambda: IPv4Address("127.0.0.1"),
            help="Host address (IP v4)",
            show_default="127.0.0.1",
        ),
    ],
):
    print(f"host is {host}")

if __name__ == "__main__":
    typer.run(main)

Docs: https://typer.tiangolo.com/tutorial/parameter-types/custom-types/

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

This discussion was converted from issue #239 on September 17, 2025 05:23.