obsidian-metadata
A script to make batch updates to metadata in an Obsidian vault. Provides the following capabilities:
in-text tag: delete every occurrencein-text tags: Rename tag (#tag1->#tag2)frontmatter: Delete a key matching a regex pattern and all associated valuesfrontmatter: Rename a keyfrontmatter: Delete a value matching a regex pattern from a specified keyfrontmatter: Rename a value from a specified keyinline metadata: Delete a key matching a regex pattern and all associated valuesinline metadata: Rename a keyinline metadata: Delete a value matching a regex pattern from a specified keyinline metadata: Rename a value from a specified keyvault: Create a backup of the Obsidian vault
Install
obsidian-metadata requires Python v3.10 or above.
pip install obsidian-metadata
Important Disclaimer
It is strongly recommended that you back up your vault prior to committing changes. This script makes changes directly to the markdown files in your vault. Once the changes are committed, there is no ability to recreate the original information unless you have a backup. Follow the instructions in the script to create a backup of your vault if needed. The author of this script is not responsible for any data loss that may occur. Use at your own risk.
Usage
The script provides a menu of available actions. Make as many changes as you require and review them as you go. No changes are made to the Vault until they are explicitly committed.
Configuration
obsidian-metadata requires a configuration file at ~/.obsidian_metadata.toml. On first run, this file will be created. You can specify a new location for the configuration file with the --config-file option.
To add additional vaults, copy the default section and add the appropriate information. The script will prompt you to select a vault if multiple exist in the configuration file
Below is an example with two vaults.
["Vault One"] # Name of the vault.
# Path to your obsidian vault
path = "/path/to/vault"
# Folders within the vault to ignore when indexing metadata
exclude_paths = [".git", ".obsidian"]
["Vault Two"]
path = "/path/to/second_vault"
exclude_paths = [".git", ".obsidian"]
To bypass the configuration file and specify a vault to use at runtime use the --vault-path option.
Contributing
Setup: Once per project
There are two ways to contribute to this project.
1. Containerized development (Recommended)
- Clone this repository.
git clone https://github.com/natelandau/obsidian-metadata - Open the repository in Visual Studio Code
- Start the Dev Container. Run Ctrl/⌘ + ⇧ + P → Remote-Containers: Reopen in Container.
- Run
poetry env info -pto find the PATH to the Python interpreter if needed by VSCode.
2. Local development
- Install Python 3.10 and Poetry
- Clone this repository.
git clone https://github.com/natelandau/obsidian-metadata - Install the Poetry environment with
poetry install. - Activate your Poetry environment with
poetry shell. - Install the pre-commit hooks with
pre-commit install --install-hooks.
Developing
- This project follows the Conventional Commits standard to automate Semantic Versioning and Keep A Changelog with Commitizen.
- When you're ready to commit changes run
cz c
- When you're ready to commit changes run
- Run
poefrom within the development environment to print a list of Poe the Poet tasks available to run on this project. Common commands:poe lintruns all linterspoe testruns all tests with Pytest
- Run
poetry add {package}from within the development environment to install a run time dependency and add it topyproject.tomlandpoetry.lock. - Run
poetry remove {package}from within the development environment to uninstall a run time dependency and remove it frompyproject.tomlandpoetry.lock. - Run
poetry updatefrom within the development environment to upgrade all dependencies to the latest versions allowed bypyproject.toml.