Skip to content

Profiles

obsidian_export.profiles

Profile management for obsidian-export.

init_user_dir

init_user_dir() -> Path

Create ~/.obsidian-export/ directory structure.

Source code in obsidian_export/profiles.py
def init_user_dir() -> Path:
    """Create ~/.obsidian-export/ directory structure."""
    base = Path.home() / ".obsidian-export"
    PROFILE_DIR.mkdir(parents=True, exist_ok=True)
    USER_STYLES_DIR.mkdir(parents=True, exist_ok=True)
    return base

list_profiles

list_profiles() -> list[str]

List available profile names.

Source code in obsidian_export/profiles.py
def list_profiles() -> list[str]:
    """List available profile names."""
    if not PROFILE_DIR.exists():
        return []
    return sorted(p.stem for p in PROFILE_DIR.glob("*.yaml"))

get_profile_path

get_profile_path(name: str) -> Path

Get the path to a profile YAML file.

Raises ProfileNameError if the name contains unsafe characters or path traversal sequences that would resolve outside PROFILE_DIR.

Source code in obsidian_export/profiles.py
def get_profile_path(name: str) -> Path:
    """Get the path to a profile YAML file.

    Raises ProfileNameError if the name contains unsafe characters or
    path traversal sequences that would resolve outside PROFILE_DIR.
    """
    if not _SAFE_NAME_RE.match(name):
        raise ProfileNameError(
            f"Invalid profile name {name!r}: only alphanumeric characters, hyphens, and underscores are allowed."
        )
    path = (PROFILE_DIR / f"{name}.yaml").resolve()
    if not path.is_relative_to(PROFILE_DIR.resolve()):
        raise ProfileNameError(f"Invalid profile name (path traversal detected): {name!r}")
    return path

load_profile

load_profile(name: str) -> ConvertConfig

Load a profile by name from ~/.obsidian-export/profiles/.

Source code in obsidian_export/profiles.py
def load_profile(name: str) -> ConvertConfig:
    """Load a profile by name from ~/.obsidian-export/profiles/."""
    path = get_profile_path(name)
    if not path.exists():
        raise FileNotFoundError(f"Profile not found: {name!r} (expected at {path})")
    return load_config(path)

save_profile

save_profile(name: str, config_dict: dict[str, Any]) -> Path

Save a profile YAML to ~/.obsidian-export/profiles/.

Source code in obsidian_export/profiles.py
def save_profile(name: str, config_dict: dict[str, Any]) -> Path:
    """Save a profile YAML to ~/.obsidian-export/profiles/."""
    init_user_dir()
    path = get_profile_path(name)
    path.write_text(yaml.dump(config_dict, default_flow_style=False, sort_keys=False), encoding="utf-8")
    return path

delete_profile

delete_profile(name: str) -> None

Delete a profile by name.

Source code in obsidian_export/profiles.py
def delete_profile(name: str) -> None:
    """Delete a profile by name."""
    path = get_profile_path(name)
    if not path.exists():
        raise FileNotFoundError(f"Profile not found: {name!r} (expected at {path})")
    path.unlink()