

You’re not going to like this answer - there’s a bunch of different ways depending on the app(s) and the desktop environment. The Arch wiki goes over it in detail: https://wiki.archlinux.org/title/Default_applications
I would guess that focusing on the XDG spec and covering Gnome, KDE and Xfce (Xfce can be replaced with anything else like Cinnamon that comes with Mint, “non Gnome or KDE”) is the best plan of attack for what matters to 80%+ of the population.

The above said, it wasn’t hard to find a project using XDG and a JSON mapping file (basically your idea fleshed out in python) to get where you want to go if XDG is enough: https://github.com/JonTheNiceGuy/usbrowser