You can have a look at this post: Error in the sampling process, 'sd' not taken in account in Metropolis.py
where @viiv is calling an external code and writing the output to a text file.
Warning: communicating and computing with external code within pm.Model()
could be slow.