What is bpython?
bpython is a fancy interface to the Python interpreter for Unix-like operating system.
says the bpython home page. It provides syntax highlighting, auto completion, auto-indentation and such stuff.
Unlike iPython, which implements then entire shell functions and emulates the standard python shell, and adds enhancements, bpython just adds features on top of the existing python shell functionality, using the curses module.

The “killer feature” of bpython is, as you can see from the image above, the IDE like prompting of the function parameters and the doc string of the function dynamically. I have always thought, what IntellijIDEA is to Java, IPython is to Python*. But bpython makes it more so, in terms of the code completion, which adds a lot of value to a ramping up developer.
The only Python IDE that provides Source Assistant and Go-To-Source functionality conveniently, is the commercial one, Wing IDE Professional. Even with that, since all the defined models are replaced (by using meta-classes) in the runtime, that source assistant is not perfect. Newer versions of Wing seems to claim to obtain data dynamically at the runtime, but its not always comfortable to write code, keeping the IDE in a breakpoint. But hey, bpython provides all these for free!
But I already use Ipython
You do? So do I. In fact, I am a Power Ipython user, I use all kinds of %magic functions: %whos, %logstart, %bookmark, %ed and sometimes use Ipython as an alternative even to bash: %cd, %ls, %ll. And even for doc testing: %doctest_mode, copy-pasting %hist -n or running some code module in the interpreter namespace: %run -i and searching code %psearch. You can also give any arbitrary bash(or your default shell) command by escaping it with !. Oh, ?, ?? and / are of course the starters.
In fact did you know, you could get to ipython shell within any arbitrary place within your django code? Just use the following:
from IPython.Shell import IPShellEmbed
ipython = IPShellEmbed()
and then call ipython() anywhere within your view, model, forms and you will be dropped to the shell. Its like ipdb.set_trace() only better (unless you want to step through, that is).
The Python readline bug
The Python version 2.6.4 (the version that is shipped with Ubuntu 9.10), introduced a readline bug that adds spaces after tab completion. This bug also affects the Ipython, as it uses the same readline module. If you spend a lot of time on the shell (if you use python, you must, right?), it is very annoying to backspace after each tab, all the time.
Although the bug got fixed pretty soon, it hasn’t yet made it to any release that ubuntu updates to. There are ways to workaround this problem, by fixing it at the python level and at the Ipython level, many of them are discussed on the corresponding Ipython bug
Using bpython with django
Now that you want to use bpython with django, either because you like the auto completion, or because you find the read line bug annoying (and don’t want/care-enough to patch your python locally), or you just want to try it, how to do it?
django manage.py shell unfortunately, drops only into the ipython shell (if you have ipython installed), and there is no straight forward way to get it to drop to bpython.
But there is still a way to use bpython with django. Just modify your ~/.bashrc to define a python startup environment variable
export PYTHONSTARTUP=~/.pythonrc
And within it, setup the django environment, that is, do it here manually the thing that python manage.py shell would do for you:
#.pythonrc
try:
from django.core.management import setup_environ
import settings
setup_environ(settings)
print 'imported django settings'
except:
pass
This way, bpython or even just python on the command line, should import the django environment for you.
Importing all models automatically into the shell
But then, if you are possibly already used to python manage.py shell_plus (If you are not, you should be.) that is defined by django_command_extensions.
So while we are at setting up the django environment, lets just also import all the models into the shell namespace, so that it is convenient to work. Following is some ugly quick hack to get it done.
This can of course be improved upon. If you do it, just leave it in the comments! In fact it would be good if it also includes from startup.py import * in a try catch, so that, you can put some extra code into startup.py. Saving into startup.py from within a bpython shell is just a Ctrl+s anyway. That way each time you get to the shell, you can have the same expected environment; and it is quite easy to change that file.
*I know, I know, IPython doesn’t refactor code, nor build, nor does a million things that Intellij does, but Python is not Java and basically both intend to enhance developer productivity. And I spend a lot of time on the IPython shell and find it to be a tool just like Intellij is a tool, for Java.
Related posts:

{ 4 trackbacks }
{ 57 comments… read them below or add one }
PyDev gives you quite a bit of the functionality that Intellij does – it has Source Assistant and Go-To-Source as well as other great features and its completely free.
@Leo
I love pytyhon, but the state of IDEs in python is at least a generation behing Java/(or Visual studio). eg In Eclipse/NetBeans, I almos never have to import, Ctrl+shift+i, and I am done.
Thanks for this article! I had never heard of bpython, but I do use ipython quite a bit. I’ll have to try this out!
“seems to claim to obtain” is unnecessary, “claims to obtain”
When you will provide answers for djagno quiz ??
Also see: http://github.com/ulope/django-extensions/commit/1fb163c72017ea889ce8c6aa61160a4bbf5d766c
Thanks for the post, seems like the site’s getting a bit of traffic from here, now I am even more famous, hooray !
I am totally guilty of having stolen this bits and pieces and also put them here http://sunoano.name/ws/public_xhtml/python.html#is_there_a_better_python_shell_interpreter
greetings to all Pythonistas our there
Simple way to use bpython with django in only one command line http://bit.ly/4A09Tb
Thanks for your post, this bpython is just The Thing. Not only is IPython a bit slow, it also has a nasty bug with non-ascii (at least cyrillic) characters. The ticket is full of desperate cries and simple patches, but these patches seem to stay there forever. The extra space issue was also very annoying (sometimes it was OK not to hit backspace, but usually that would break further completion). And the prompting of parameters is simply what was missing in all tools I tried — except for the bulky IDEs which usually stay in your way instead of helping with certain tasks.
Facebook Şifre Alma Programı Bilgisayara Girme Programı
http://bit.ly/4X0HR3 Using bpython shell with django (and some Ipython features you should know)
This comment was originally posted on Twitter
Using bpython shell with django (and some Ipython features you should know): Comments http://url4.eu/v4LY
This comment was originally posted on Twitter
Using bpython shell with django (and some Ipython features you should know): What is bpython?
bpython is a f.. http://bit.ly/53RAvw
This comment was originally posted on Twitter
Fancy shmancy shell for Python: http://bit.ly/5Aemse #python #django #shell
This comment was originally posted on Twitter
Using bpython shell with django (and some Ipython features you should know) http://bit.ly/8mSENo
This comment was originally posted on Twitter
http://twitter.com/loggly/statuses/6604797701 “Fancy shmancy shell for Python: http://bit.ly/5Aemse #python #django #shell”
This comment was originally posted on Twitter
Using bpython shell with django (and some Ipython features you should know): http://bit.ly/5MewXg Comments: http://bit.ly/62i7Kf
This comment was originally posted on Twitter
Shabda Raaj: Using bpython shell with django (and some Ipython features you should know) http://tinyurl.com/ybf2kls
This comment was originally posted on Twitter
bpython seems to be much better than ipython … switching now ~
This comment was originally posted on Hacker News
Using bpython shell with django (and some Ipython features you should know)
: http://bit.ly/5TsHdO
This comment was originally posted on Twitter
StartupNews: Using bpython shell with django (and some Ipython features you should know) http://bit.ly/5BL7L1
This comment was originally posted on Twitter
Shabda Raaj: Using bpython shell with django (and some Ipython features you should know)
: http://bit.ly/72v7og
This comment was originally posted on Twitter
Using bpython shell with django (and some Ipython features you…: Bookmark this on Delicious – Saved by zchro… http://bit.ly/6j9kzh
This comment was originally posted on Twitter
Using bpython shell with django (and some Ipython features you should know) http://bit.ly/5SmUYX
This comment was originally posted on Twitter
Using bpython shell with django (and some Ipython features you should know) — The Usware Blog – Django Web Develo… http://bit.ly/6j9kzh
This comment was originally posted on Twitter
using bpython with django http://uswaretech.com/blog/2009/12/using-bpython-shell-with-django-and-some-ipython-features-you-should-know/
This comment was originally posted on Twitter
That is true only if you don’t use the magic functions!
This comment was originally posted on Hacker News
And it is true that most people don’t.I think both have their place.
This comment was originally posted on Hacker News
Reddit/p: Using bpython shell with django (and some Ipython features you should know) http://bit.ly/6Sx1ef
This comment was originally posted on Twitter
Well, depending on what you want from it — the curses UI and autocomplete implementation are very nice, but ipython has a lot of additional features that bpython isn’t interested in implemented. I miss the ??function_name feature in ipython that shows the complete source code for a function or class, since the function header isn’t always informative enough; I tend to use ipython’s bash emulation pretty frequently too.
This comment was originally posted on Hacker News
Using bpython shell with django (and some Ipython features you should know) — The Usware Blog – Django Web Deve.. http://bit.ly/7PBBUq
This comment was originally posted on Twitter
Using bpython shell with django (and some Ipython features you should know) ? The Usware Blog – Django Web Developm… http://bit.ly/6j9kzh
This comment was originally posted on Twitter
【Mix】 Using bpython shell with django (and some Ipython features you should know) ? The Usware Blog – .. http://bit.ly/7PBBUq
This comment was originally posted on Twitter
I just need a better replacement for the default python shell. iPython has those nice extras, but I rarely use them … so bpython is a much better choice for me now
This comment was originally posted on Hacker News
Can anyone tell me why the following only outputs the exit status "0"?import osos.system(’ls’)
I don’t get this problem in ipython.
Thanks
This comment was originally posted on Hacker News
Can anyone tell me why the following only outputs the exit status "0"?import osos.system(‘ls’)
I don’t get this problem in ipython.
Thanks
This comment was originally posted on Hacker News
Using bpython shell with django (and some Ipython features you should know) — The Usware Blog – Django Web Development http://is.gd/5lm7b
This comment was originally posted on Twitter
Using bpython shell with django (and some Ipython features you should know) — The Usware Blog – Django Web Development http://is.gd/5lm7b
This comment was originally posted on Twitter
Seriously… thi might very well be the coolest things I’v found
recently IPShellEmbed
http://bit.ly/7g9uwr
This comment was originally posted on Twitter
Also I have a branch on github that adds bpython support to shell_plus: http://github.com/ulope/django-extensions/commit/1fb163c72017ea889ce8c6aa61160a4bbf5d766c
This comment was originally posted on Reddit
bpython shell: http://uswaretech.com/blog/2009/12/using-bpython-shell-with-django-and-some-ipython-features-you-should-know/
This comment was originally posted on Twitter
Using bpython shell with django (and some Ipython features you should know)
: http://bit.ly/4PGSJA
This comment was originally posted on Twitter
Using bpython shell with django , improved Ipython shell : http://bit.ly/6UzRIo auto
This comment was originally posted on Twitter
bpython: noch eine klasse python shell http://is.gd/5lKcb
This comment was originally posted on Twitter
http://twitter.com/Fry3001/statuses/6627536686 “bpython: noch eine klasse python shell http://is.gd/5lKcb”;
This comment was originally posted on Twitter
http://twitter.com/Fry3001/statuses/6627536686 “bpython: noch eine klasse python shell http://is.gd/5lKcb”;
This comment was originally posted on Twitter
The ide in a python >>> : http://uswaretech.com/blog/2009/12/using-bpython-shell-with-django-and-some-ipython-features-you-should-know/
This comment was originally posted on Twitter
http://twitter.com/daveaitel/statuses/6638228584 “The ide in a python >>> : http://bit.ly/7g9uwr”;
This comment was originally posted on Twitter
http://twitter.com/daveaitel/statuses/6638228584 “The ide in a python >>> : http://bit.ly/7g9uwr”;
This comment was originally posted on Twitter