I am writing a program, and I want it to do different things depending on which LaTeX packages have been installed. My current solution is to automatically generate simple .tex files that \usepackage the packages I care about and then automatically check if pdflatex can compile them or not. This solution seems slow and fragile. What is a better solution?
Edit: The program I am writing is in Python.