A distribution could be implemented as a class containing one Function “self.pdf” and a method sample()
class Distribution():
    def __init__(self):
        self.pdf = # autograd Function

    def sample():
        # use self.pdf for Monte Carlo algorithm

( by the way, how do you use python coloration when providing code in this forum ?)