flaskipythondjango-extensionsflask-script

How can I use ptiPython with Flask-Script together?


In Django, I can use ptiPython instead of IPython after enabling Django-Extensions plugin to enforce Django-Shell. In Flask world, the alternative one of seems to be Flask-Script, I searched around but could not find anything to use ptiPython with Flask-Shell together.


Solution

  • Flask-Script support ipython and bpython. You can create custom Shell class

    from flask.ext.script import Shell
    from ptpython.ipython import embed
    
    class PtShell(Shell):
        def run(self, **kwargs):
            context = self.get_context()
            embed(user_ns=context)
    
    manager.add_command("shell", PtShell())