Py-obsidianmd - Modify your notes' metadata in batch

Hello Obsidian community,

py-obsidianmd is a python library that enables you to change your notes’ metadata in batch. You can also easily move your metadata between the frontmatter and inline notation (dataview style).

Checkout the presentation video, github repository and examples.

It has saved me a lot of time, and made me free to experiment with how I handle my knowledge base’s metadata. I hope it can also be useful to others in the community !

Let me know if you have any feedback.

Cheers,

12 Likes

I just love this. I recently asked in the Dataview thread on Discord whether someone had written a JS script for this exact purpose and then you strode in with a polished tool, ready to use, written in my favoured language, Python. Really awesome work. Running this over a lot of files will likely take some time, which is expected, but I’m excited to try it out on my media database. So far I’ve only tried with some example files.
Thanks a lot for sharing!

4 Likes

Hi @apfelstrudelig glad you find it helpful !

Please do back up your vault before using it on its entirety. The tool is still in its early development, better safe than sorry.

If you have any feedback after running it in batch (positive or negative) it would be very helpful if you share it here or on the github.

Cheers !

4 Likes

Thanks for sharing!

I was just browsing for a good way to interface Python and Obsidian to make sure I wasn’t being too “ugly” using my Templater workaround. This helps a lot since this was going to be one of my tool objectives!

Keep it :floppy_disk:,

  • LarBear
1 Like

love this!

Can I use to modify properties?

I would like to provide feedback.

For context, I am NOT a developer but I can (to some extent) read the code of others and makes sense of it. I consider myself a heavy users of Obsidian, lots of plugins and templates, daily use for multiple topics (work and private), lots of METADATA work. So that’s me, my “persona”.

This library is so HELPFULL to me. I have just started to TEST doing stuff in the proposed dummy vault, and it has been so wise to do it that way, because of course I made mistakes (and I think I found a bug, also).

Right now I am in the process of carefully crafting test notes with both simple and corner cases, and making sure that I can easily move back and forth metadata from FRONTMATTER to INLINE and revert that. Interestingly, I learned that if you have the metadata as INLINE within a CALLOUT (which looks lovely), you have to do an extra step to move it to FRONTMATTER (first you have to move the INLINE to standard format, i.e., remove the callout).

Currently, I am testing stuff like…

  • Collecting all INLINE metadata in diff places and grouping at the top or bottom of the note
  • Moving/removing tags
  • … more

For example, I created a test note called Test1 with both FRONTMATTER and INLINE metadata, and I am testing to manipulate exclusively all INLINE metadata, sort both the KEYS and the VALUES. And I have placed the metadata Dataview fields all over the note, even some hidden with ‘%%’. The order of appearance of the keys is out of alphabetical order, and within the keys, the values are also out of order. So I am doing this:

  • Filter notes by name
  • Sort INLINE metadata keys in ASC order
  • Sort INLINE metadata values in ASC order
  • Group all INLINE metadata into one location, regardless of where in the nodes is located
  • Place INLINE metadata at the top
  • Write the INLINE in “standard” format
from pyomd import Notes
from pyomd.metadata import MetadataType
from pathlib import Path
from pyomd.misc import Order

path = Path('/Users/FGS/Documents/Obsidian/TestVault/Media')
notes = Notes(path)

notes.filter(starts_with="Test1")
notes.metadata.order(k=None, o_keys=Order.ASC, o_values=Order.ASC)
notes.update_content(inline_inplace=False,inline_position="top",inline_tml="standard")
notes.write()

And it works!
Amazing!
Thanks so much to the creator of this library!