Skip to content

types.strings

Char = t.Annotated[str, Len(1)] module-attribute

String than can only be length 1

Email = t.Annotated[str, Matches(email_regex, message='is not a valid email address')] module-attribute

String type with email validation

Password

Bases: UserString

For Secret Strings.

When prompted for input, the user's input will not be echoed to the screen.

Additionally, the string will be obscured when printed. For example:

from typing import Annotated
import arc
from arc.types import Password

@arc.command
def command(password: Password):
    print(password) # This would be obscured
    print(password.data) # This would be the actual password
Source code in /home/runner/work/arc/arc/arc/types/strings.py
class Password(UserString):
    """For Secret Strings.

    When prompted for input, the user's input will not be echoed to the screen.

    Additionally, the string will be obscured when printed. For example:

    ```py
    from typing import Annotated
    import arc
    from arc.types import Password

    @arc.command
    def command(password: Password):
        print(password) # This would be obscured
        print(password.data) # This would be the actual password
    ```
    """

    def __str__(self) -> str:
        return "*" * len(self)

    def __repr__(self) -> str:
        return "Password()"

    @classmethod
    def __prompt__(cls, param: Param[str], ctx: Context) -> str:
        return input_prompt(param, ctx, echo=False)

    @classmethod
    def __convert__(cls, value: str) -> Password:
        return cls(value)