How to represent pathways as mathematical graphs?
Pathways are generally directed graphs, which can be implemented in python using the networkx package. Note that there will be cycles in graphs.

Please note that there are large numbers of pathways analysis packages that already exist (both python and R packages but also just webservers), so I strongly recommend searching to see if something already exists before wasting time and implementing it yourself.