FirePython — no prints?
While I’m developing some web application I almost never use any debuggers or supporting tools: in 90% of cases usual print variable is enough for understanding a trouble. Of course, there are some very complicated cases, when I do import pdb; pdb.set_trace().
But I was pointed at very cool thing yesterday — FirePython. This thing consists of two parts — small library on python and plugin for Firebug. This tandem is engaged with very useful business — it displays all python logged activity1 in Firebug tab.
This tool is really helpful — now I need only two applications for development: an editor and a browser. Good news is that I don’t need to look for print output in runserver output. Regarding usual usage of logging there are some benefits too — at least you don’t need to follow files and their paths (for creation of which you may not have rights), moreover immediately you have nice viewer for logs with ability to filter them.
I’ve contributed today to development of FirePython by development of two middlewares — one for Django and one for WSGI applications, so now its usage is just a question of few movements. ;) In short: you need to install plugin itself, which depends on Firebug 1.3 (it’s still in beta stage, but I’m using Firefox 3.1, so this is not scary for me :P). After that do easy_install firepython. Another option: clone project from github and put folder firepython from python folder in sys.path or your project directory.
After that you just need to enable middleware by adding its path in MIDDLEWARE_CLASSES: firepython.django.FirePythonDjango. WSGI middleware has another path (how strange! :D): firepython.wsgi.FirePythonWSGI, which you should use as any other WSGI middleware.
Usage of whole system in code looks like:
import logging
logging.debug('what you want to debug today?')
Naturally you can use any level instead of debug — you can filter them in FirePython interface.
Precisely saying you will get logs which was logged while FirePython was registered as a handler in logging.

Comments: 35 Subscribe (already: 5) Comment post
I haven’t tested yet, just out of curiosity and maybe you just know it: does it work on appengine as well ?
Yes, it was written for AppEngine initially.
huh, I tried now, first I had to set simplejson class path from simplejson to django.utils.simplejson and then I got this error (on appengine):
Any idea what went wrong ?
and btw., amazing project, your blogengine !!!
Oh, yes… We will try to fix that.
Thanks! :-)
P.S. Indenting code with 4 spaces will render it as code, that’s a markdown syntax.
Roberto, update to latest App Engine SDK. sys.exc_traceback is available during exception on my system OSX 10.5.5, Python 2.5.1, GAE SDK 1.1.7
or alternatively comment out lines around #27 in firepython/init.py it is there only for fixing incorrect paths in log records on OSX (?)
Antonin, if I check my versions, OSX 10.5.5, Python 2.5.1, GAE SDK 1.1.7 is EXACTLY what I have. Strange !
please try adding
import sysbefore linereturn sys.exc_traceback.tb_frame.f_back.f_back.f_back.f_backand let me know here
Got a microstep further, but now it complains about undefined simplejson (I imported it at top as django.utils.simplejson):
NameError: name ‘simplejson’ is not defined
Roberto, I’ve just copied simplejson folder to root of my GAE project (where is app.yaml). It doesn’t hurt.
playing with sys.path or class path is not a good idea for goole app engine. there are bugs. for me as a python newbie it is nothing but magic.
see http://code.google.com/appengine/articles/django10_zipimport.html and look for “bug”
Oh, why GAE is resetting
sys.path? It’s simply bad idea. :\Do it like
from django.utils import simplejson. I’ll patch firepython to do that by default.ok, now I got:
SystemError: Parent module ‘firepython’ not loaded
next I remove the “import sys” in the correctCurrentFrame() and I got the following exception:
Comment out line
logging.currentframe = correctCurrentframe, I think you should not need it.About Django — isn’t Django in sys.path of GAE? I’m not sure as I haven’t used GAE at all. :-(
still getting:
monkeypatched django is loaded from a zip file (GAE has only very old django preinstalled) and I use the monkeypatch from appenginepatch to do that, but I am not yet familiar with the hidden details of how it works (I am Python newby, sorry)
Ok, I’m going to try that and will comment as soon as it will work.
Hey Roberto! From traceback I see that you have placed
firepythonmodule intocommondirectory. (/Users/rsaccon/appengine/skast/common/firepython).I’ve said don’t mess with sys.path and put all modules into root directory of gae project. You are asking for troubles.
Unfortunately that is how appenginepatch (the django monkeypatcher I am using) works.
I don’t know appenginepatch, but you should be still able to place modules to root of the project. I suppose sys.path still contains PROJECT_ROOT. So, put firepython into project root and see what happens
unfortunately the same error. I think it has to do with how appenginepatch does the django monkyepatching. Will ask the appenginepatch guys for advice.
Please comment here if you’ll have success with that. :-)
Nice plugin! :)
The traceback says it all: There indeed is no module “firepython.django”.Please try “firepython.middleware.FirePythonDjango”. Alexander, could you please update the documentation?
Oh! :D Thanks, documentation is updated.
BTW, this blog post refers to “firepython.django”, too.
It was written about version 0.2, for which this is right path. ;-) I’ll better write new blog post about 0.3, when it will come out :-)
Ouuuch ! That was it, no more errors now. It doesn’t log yet at the FirePython tab, so there is still something wrong in my code …
Yes, unfortunately GAE relies (at least in SDK part, haven’t tried GAE itself) on deprecated feature of WSGI, support for which I have committed 30 seconds ago. Look at my repo.
Oops, there are troubles with threading and GAE. Fixing that right now.
I was wrong. SDK works fine now.
Alexander, I just updated from your git repo, now I get the following error
If I check the source, the following logging statement seems to use undefined variables:
(Of course I am aware that if I am supposed to get this debug message, there is another thing wrong with my setup …)
Thanks for checking, this bug appeared after refactoring. Fixed and pushed to github.
it’s wrong again on github, It works for me if I adapt it as follows:
The actual error message I get, produced by that statement, is:
That is odd, because I have installed FirePython via mozilla addon service and the version is 0.2 (checking in the GUI, via menu Tools/Add-ons)
Confirmed: It is bug in 0.2 release of firebug extension.
This won’t happen in the future. I promise :-)
It works great for me except in cases where my handler does a redirect.
self.redirect(‘/’) for example, in which case the HTTP response is cleared
application = webapp.WSGIApplication(routes) from external.firepython.middleware import FirePythonWSGI application = FirePythonWSGI(application)
Using it in app engine with SDK 1.1.7
Thanks for report, I’ll look at that soon.
Comment form for «FirePython - no prints?»