Skip to content

Integrations

Working with Pydantic

ProperPath can be used with Pydantic models or fields the same way pathlib.Path can be.

try_with_pydantic.py
from pydantic import BaseModel

from properpath import P


class ConfigSource(BaseModel):
    local_path: P
    system_path: P


config_source = ConfigSource(
    local_path="~/.config/app.toml", system_path="/etc/app.toml"
)
print(config_source)
# Prints: ConfigSource(local_path=ProperPath(path=/Users/culdesac/.config/app.toml, actual=('~/.config/app.toml',), kind=file, exists=False, is_symlink=False, err_logger=<RootLogger root (WARNING)>), system_path=ProperPath(path=/etc/app.toml, actual=('/etc/app.toml',), kind=file, exists=False, is_symlink=False, err_logger=<RootLogger root (WARNING)>))

Rich pretty-printing in REPL

If rich is installed (can optionally be installed with properpath[rich]), ProperPath instances will be pretty-printed in REPL. Make sure from rich import pretty; pretty.install() is run in the REPL beforehand, or added to the PYTHONSTARTUP script.

>>> from rich import pretty; pretty.install()
>>> config_source  # from the example before 
properpath rich pretty repr screenshot light properpath rich pretty repr screenshot dark