We already have bits of codes that query those files spread around in different functions. It might make sense to have one single function to do that.
pybids has a whole module dedicated to that we can get some inspiration from.
https://github.com/bids-standard/pybids/tree/master/bids/analysis