Skip to content

typerdrive Reference

typerdrive.cloaked

CloakingDevice module-attribute

CloakingDevice = Option(
    parser=lambda _: _,
    hidden=True,
    expose_value=False,
    default_factory=lambda: None,
)

typerdrive.config

TyperdriveConfig

Bases: BaseModel

app_name class-attribute instance-attribute
app_name: str = argv[0]
cache_dir property
cache_dir: Path
log_dir property
log_dir: Path
log_file_compression class-attribute instance-attribute
log_file_compression: FileCompressionSpec = 'tar.gz'
log_file_name class-attribute instance-attribute
log_file_name: str = 'app.log'
log_file_retention class-attribute instance-attribute
log_file_retention: FileRetentionSpec = '1 month'
log_file_rotation class-attribute instance-attribute
log_file_rotation: FileRotationSpec = '1 week'
settings_path property
settings_path: Path

get_typerdrive_config

get_typerdrive_config() -> TyperdriveConfig

set_typerdrive_config

set_typerdrive_config(**kwargs: Any)

typerdrive.constants

ExitCode

Bases: IntEnum

Maps exit codes for the application.

CANNOT_EXECUTE class-attribute instance-attribute
CANNOT_EXECUTE = 126
GENERAL_ERROR class-attribute instance-attribute
GENERAL_ERROR = 1
INTERNAL_ERROR class-attribute instance-attribute
INTERNAL_ERROR = 128
SUCCESS class-attribute instance-attribute
SUCCESS = 0

Validation

Bases: Flag

Defines whether validation should happen "before", "after", "both", or "none"

AFTER class-attribute instance-attribute
AFTER = auto()
BEFORE class-attribute instance-attribute
BEFORE = auto()
BOTH class-attribute instance-attribute
BOTH = BEFORE | AFTER
NONE class-attribute instance-attribute
NONE = 0

typerdrive.context

TyperdriveContext dataclass

cache_manager class-attribute instance-attribute
cache_manager: CacheManager | None = None
client_manager class-attribute instance-attribute
client_manager: ClientManager | None = None
logging_manager class-attribute instance-attribute
logging_manager: LoggingManager | None = None
settings_manager class-attribute instance-attribute
settings_manager: SettingsManager | None = None
__init__
__init__(
    settings_manager: SettingsManager | None = None,
    cache_manager: CacheManager | None = None,
    client_manager: ClientManager | None = None,
    logging_manager: LoggingManager | None = None,
) -> None

from_context

from_context(ctx: Context, name: str) -> TyperdriveManager

get_user_context

get_user_context(ctx: Context)

to_context

to_context(
    ctx: Context, name: str, val: TyperdriveManager
) -> None

typerdrive.dirs

DirInfo dataclass

file_count instance-attribute
file_count: int
total_size instance-attribute
total_size: int
tree instance-attribute
tree: Tree
__init__
__init__(
    tree: Tree, file_count: int, total_size: int
) -> None

clear_directory

clear_directory(path: Path) -> int

is_child

is_child(path: Path, parent: Path)

render_directory

render_directory(
    path: Path, is_root: bool = True
) -> DirInfo

show_directory

show_directory(path: Path, subject: str | None = None)

typerdrive.env

tweak_env

tweak_env(**kwargs: str)

typerdrive.exceptions

P module-attribute

P = ParamSpec('P')

T module-attribute

T = TypeVar('T')

WrappedFunction module-attribute

WrappedFunction = Callable[P, T]

BuildCommandError

Bases: TyperdriveError

exit_code class-attribute instance-attribute
exit_code: ExitCode = INTERNAL_ERROR

ContextError

Bases: TyperdriveError

exit_code class-attribute instance-attribute
exit_code: ExitCode = INTERNAL_ERROR

TyperdriveError

Bases: Buzz

details class-attribute instance-attribute
details: Any | None = None
exit_code class-attribute instance-attribute
exit_code: ExitCode = GENERAL_ERROR
footer class-attribute instance-attribute
footer: str | None = None
subject class-attribute instance-attribute
subject: str | None = None
__init__
__init__(
    *args: Any,
    subject: str | None = None,
    footer: str | None = None,
    details: Any | None = None,
    exit_code: ExitCode | None = None,
    **kwargs: Any,
)

handle_errors

handle_errors(
    base_message: str,
    *,
    handle_exc_class: type[Exception]
    | tuple[type[Exception], ...] = TyperdriveError,
    ignore_exc_class: type[Exception]
    | tuple[type[Exception], ...]
    | None = None,
    do_except: Callable[[DoExceptParams], None]
    | None = None,
    do_else: Callable[[], None] | None = None,
    do_finally: Callable[[], None] | None = None,
    unwrap_message: bool = True,
    debug: bool = False,
) -> Callable[
    [WrappedFunction[P, T]], WrappedFunction[P, T]
]

typerdrive.format

simple_message

simple_message(
    message: str,
    indent: bool = False,
    markdown: bool = False,
    error: bool = False,
)

strip_rich_style

strip_rich_style(text: str | Text) -> str

terminal_message

terminal_message(
    message: str | RenderableType,
    subject: str | None = None,
    subject_align: Literal[
        "left", "right", "center"
    ] = "left",
    color: str = "green",
    footer: str | None = None,
    footer_align: Literal[
        "left", "right", "center"
    ] = "left",
    indent: bool = True,
    markdown: bool = False,
    error: bool = False,
)

typerdrive.types

FileCompressionSpec module-attribute

FileCompressionSpec = str | Callable[[str], None]

FileRetentionSpec module-attribute

FileRetentionSpec = (
    str | int | timedelta | Callable[[list[str]], None]
)

FileRotationSpec module-attribute

FileRotationSpec = (
    str
    | int
    | timedelta
    | time
    | Callable[[str, TextIO], bool]
)

typerdrive.version

__version__ module-attribute

__version__ = get_version()

get_version

get_version() -> str

get_version_from_metadata

get_version_from_metadata() -> str

get_version_from_pyproject

get_version_from_pyproject() -> str

typerdrive.cache.attach

ContextFunction module-attribute

ContextFunction = Callable[Concatenate[Context, P], T]

P module-attribute

P = ParamSpec('P')

T module-attribute

T = TypeVar('T')

attach_cache

attach_cache(
    show: bool = False,
) -> Callable[
    [ContextFunction[P, T]], ContextFunction[P, T]
]

get_cache_manager

get_cache_manager(ctx: Context) -> CacheManager

typerdrive.cache.commands

add_cache_subcommand

add_cache_subcommand(cli: Typer)

add_clear

add_clear(cli: Typer)

add_show

add_show(cli: Typer)

clear

clear(
    ctx: Context,
    path: Annotated[
        str | None,
        Option(
            help="Clear only the entry matching this path. If not provided, clear the entire cache"
        ),
    ] = None,
)

show

show(ctx: Context)

typerdrive.cache.exceptions

CacheClearError

Bases: CacheError

CacheError

Bases: TyperdriveError

exit_code class-attribute instance-attribute
exit_code: ExitCode = GENERAL_ERROR

CacheInitError

Bases: CacheError

CacheLoadError

Bases: CacheError

CacheStoreError

Bases: CacheError

typerdrive.cache.manager

CacheManager

cache_dir instance-attribute
cache_dir: Path = cache_dir
__init__
__init__()
clear_all
clear_all() -> int
clear_path
clear_path(path: Path | str) -> Path
load_bytes
load_bytes(path: Path | str) -> bytes
load_json
load_json(path: Path | str) -> dict[str, Any]
load_text
load_text(path: Path | str) -> str
resolve_path
resolve_path(path: Path | str, mkdir: bool = False) -> Path
store_bytes
store_bytes(
    data: bytes, path: Path | str, mode: int | None = None
)
store_json
store_json(
    data: dict[str, Any],
    path: Path | str,
    mode: int | None = None,
)
store_text
store_text(
    text: str, path: Path | str, mode: int | None = None
)

typerdrive.client.attach

ContextFunction module-attribute

ContextFunction = Callable[Concatenate[Context, P], T]

P module-attribute

P = ParamSpec('P')

T module-attribute

T = TypeVar('T')

attach_client

attach_client(
    **client_urls_or_settings_keys: str,
) -> Callable[
    [ContextFunction[P, T]], ContextFunction[P, T]
]

get_client

get_client(ctx: Context, name: str) -> TyperdriveClient

get_client_manager

get_client_manager(ctx: Context) -> ClientManager

typerdrive.client.base

TyperdriveClient

Bases: Client

__init__
__init__(*args: Any, **kwargs: Any)
delete_x
delete_x(
    url: URL | str,
    *,
    param_obj: BaseModel | None = None,
    body_obj: BaseModel | None = None,
    expected_status: int | None = None,
    expect_response: bool = True,
    response_model: type[RM] | None = None,
    **request_kwargs: Any,
) -> RM | int | dict[str, Any]
get_x
get_x(
    url: URL | str,
    *,
    param_obj: BaseModel | None = None,
    body_obj: BaseModel | None = None,
    expected_status: int | None = None,
    expect_response: bool = True,
    response_model: type[RM] | None = None,
    **request_kwargs: Any,
) -> RM | int | dict[str, Any]
patch_x
patch_x(
    url: URL | str,
    *,
    param_obj: BaseModel | None = None,
    body_obj: BaseModel | None = None,
    expected_status: int | None = None,
    expect_response: bool = True,
    response_model: type[RM] | None = None,
    **request_kwargs: Any,
) -> RM | int | dict[str, Any]
post_x
post_x(
    url: URL | str,
    *,
    param_obj: BaseModel | None = None,
    body_obj: BaseModel | None = None,
    expected_status: int | None = None,
    expect_response: bool = True,
    response_model: type[RM] | None = None,
    **request_kwargs: Any,
) -> RM | int | dict[str, Any]
put_x
put_x(
    url: URL | str,
    *,
    param_obj: BaseModel | None = None,
    body_obj: BaseModel | None = None,
    expected_status: int | None = None,
    expect_response: bool = True,
    response_model: type[RM] | None = None,
    **request_kwargs: Any,
) -> RM | int | dict[str, Any]
request_x
request_x(
    method: str,
    url: URL | str,
    *,
    param_obj: BaseModel | None = None,
    body_obj: BaseModel | None = None,
    expected_status: int | None = None,
    expect_response: bool = True,
    response_model: type[RM] | None = None,
    **request_kwargs: Any,
) -> RM | int | dict[str, Any]

typerdrive.client.exceptions

ClientError

Bases: TyperdriveError

exit_code class-attribute instance-attribute
exit_code: ExitCode = GENERAL_ERROR

typerdrive.client.manager

ClientManager

clients instance-attribute
clients: dict[str, TyperdriveClient] = {}
__init__
__init__()
add_client
add_client(name: str, spec: ClientSpec) -> None
get_client
get_client(name: str) -> TyperdriveClient

ClientSpec

Bases: BaseModel

base_url instance-attribute
base_url: Annotated[
    str, BeforeValidator(pyright_safe_validator)
]

pyright_safe_validator

pyright_safe_validator(value: str) -> str

typerdrive.logging.attach

ContextFunction module-attribute

ContextFunction = Callable[Concatenate[Context, P], T]

P module-attribute

P = ParamSpec('P')

T module-attribute

T = TypeVar('T')

attach_logging

attach_logging(
    verbose: bool = False,
) -> Callable[
    [ContextFunction[P, T]], ContextFunction[P, T]
]

get_logging_manager

get_logging_manager(ctx: Context) -> LoggingManager

typerdrive.logging.commands

add_audit

add_audit(cli: Typer)

add_clear

add_clear(cli: Typer)

add_logs_subcommand

add_logs_subcommand(cli: Typer)

add_show

add_show(cli: Typer)

audit

audit(ctx: Context, manager: LoggingManager)

clear

clear(ctx: Context, manager: LoggingManager)

show

show(ctx: Context, manager: LoggingManager)

typerdrive.logging.exceptions

LoggingError

Bases: TyperdriveError

exit_code class-attribute instance-attribute
exit_code: ExitCode = GENERAL_ERROR

typerdrive.logging.manager

LoggingManager

log_dir instance-attribute
log_dir: Path = log_dir
log_file instance-attribute
log_file: Path = log_dir / log_file_name
__init__
__init__(*, verbose: bool = False)
audit
audit()
clear
clear()
show
show()

typerdrive.settings.attach

ContextFunction module-attribute

ContextFunction = Callable[Concatenate[Context, P], T]

P module-attribute

P = ParamSpec('P')

T module-attribute

T = TypeVar('T')

attach_settings

attach_settings(
    settings_model: type[BaseModel],
    *,
    validation: Validation = Validation.BEFORE,
    persist: bool = False,
    show: bool = False,
) -> Callable[
    [ContextFunction[P, T]], ContextFunction[P, T]
]

get_settings

get_settings(ctx: Context, type_hint: type[ST]) -> ST

get_settings_manager

get_settings_manager(ctx: Context) -> SettingsManager

get_settings_value

get_settings_value(ctx: Context, settings_key: str) -> Any

typerdrive.settings.commands

add_bind

add_bind(cli: Typer, settings_model: type[BaseModel])

add_reset

add_reset(cli: Typer, settings_model: type[BaseModel])

add_settings_subcommand

add_settings_subcommand(
    cli: Typer, settings_model: type[BaseModel]
)

add_show

add_show(cli: Typer, settings_model: type[BaseModel])

add_unset

add_unset(cli: Typer, settings_model: type[BaseModel])

add_update

add_update(cli: Typer, settings_model: type[BaseModel])

bind

bind(ctx: Context)

reset

reset(ctx: Context)

show

show(ctx: Context)

unset

unset(ctx: Context)

update

update(ctx: Context)

typerdrive.settings.exceptions

SettingsError

Bases: TyperdriveError

exit_code class-attribute instance-attribute
exit_code: ExitCode = GENERAL_ERROR

SettingsInitError

Bases: SettingsError

SettingsResetError

Bases: SettingsError

SettingsSaveError

Bases: SettingsError

SettingsUnsetError

Bases: SettingsError

SettingsUpdateError

Bases: SettingsError

typerdrive.settings.manager

SettingsManager

invalid_warnings instance-attribute
invalid_warnings: dict[str, str] = {}
settings_instance instance-attribute
settings_instance: BaseModel = settings_model(
    **settings_values
)
settings_model instance-attribute
settings_model: type[BaseModel] = settings_model
settings_path instance-attribute
settings_path: Path = settings_path
__init__
__init__(settings_model: type[BaseModel])
pretty
pretty(with_style: bool = True) -> str
reset
reset()
save
save()
set_warnings
set_warnings(err: ValidationError)
unset
unset(*unset_keys: str)
update
update(**settings_values: Any)
validate
validate()