class Macro(object):

    def __init__(self, name, value):
        self.name = name
self._value = value
ip = get_ipython()
magics = StatefulMagics(ip, {name: value})
ip.register_magics(magics)

def value(self):
    return self._value

def __repr__(self):
    return self.name
How to pass a variable to magic ´run´ function in IPython