Welcome to web.py! (web.py)
is a web framework for Python that is as simple as it is powerful.
is in the public domain, you can use it for whatever purpose with
absolutely no restrictions.
To install the latest for Python 3, please run:
The latest 0. 62 release supports Python >= 3. 5.
Version 0. 51 is the last release with Python 2. 7 support.
A minimal application
Save code below in file
urls = (
‘/(. *)’, ‘hello’)
app = lication(urls, globals())
def GET(self, name):
if not name:
name = ‘World’
return ‘Hello, ‘ + name + ‘! ‘
if __name__ == “__main__”:
Start the application with command below, it listens on by default.
was originally published while Aaron Swartz worked at, where the site used it as it grew to become one of the top 1000 sites according to Alexa and served millions of daily page views. “It’s the anti-framework framework. doesn’t get in your way, ” explained founder Steve Huffman. (The site was rewritten using other tools after being acquired by Condé Nast. )
Some user testimonials:
“In the ecosystem of web frameworks, something must occupy the niche of ‘small, light, and fast’: does this. ”*
— Lloyd Dalton,
“[ inspired the] web framework we use at FriendFeed [and] the webapp framework that ships with App Engine…”*
— Brett Taylor, co-founder of FriendFeed and original tech lead on Google App Engine
“Django lets you write web apps in Django. TurboGears lets you write web apps in TurboGears. lets you write web apps in Python. ”*
— Alice Atlas
“Guido* [van Rossum, creator of Python], you’ll probably find that best suits your style. … If you don’t like it, I can’t imagine which of the other dozens of frameworks out there you would like. ”
— Phillip J. Eby, creator of the Python Web Server Gateway Interface (WSGI) #
Python import web not working – Stack Overflow
So I’m getting the following error when running a script that imports web.
$ python bin/
Traceback (most recent call last):
File “bin/”, line 1, in
ImportError: No module named web
I tried using easy_install web but get this error:
$ easy_install web
Searching for web
Reading Reading Reading No local packages or download links found for web
error: Could not find suitable distribution for (‘web’)
And I tried pip install web but get the following:
$ pip install web
Could not find any downloads that satisfy the requirement web
No distributions at all found for web
Storing complete log in /Users/zcj90/
File “/usr/local/bin/pip”, line 8, in
load_entry_point(‘pip==1. 0. 2’, ‘console_scripts’, ‘pip’)()
File “/Library/Python/2. 6/site-packages/”, line 116, in main
return (initial_args, args[1:], options)
File “/Library/Python/2. 6/site-packages/”, line 151, in main
log_fp = open_logfile(log_fn, ‘w’)
File “/Library/Python/2. 6/site-packages/”, line 180, in open_logfile
log_fp = open(filename, mode)
IOError: [Errno 13] Permission denied: ‘/Users/zcj90/’
urls = (
app = lication(urls, globals())
greeting = “Hello World”
if __name__ == “__main__”:
Install guide – web.py
Other languages: español
LightTPD.. with FastCGI
Apache.. with CGI.. with CGI using. htaccess.. with FastCGI.. with SCGI.. with mod_python.. with mod_wsgi.. with mod_rewrite
To install for Python >= 3. 5, download:
or the get the latest dev version:
extract it and copy the web folder into a directory where your application is. Or, to make it accessible to all applications, run:
Note: on some unix like systems you may need sudo to get root privilege:
sudo python install
see recommended setup.
Another option is to use Easy Install. Once Easy Install is properly setup:
To install for Python 2. 7, please use the version 0. 51, the last supported version for Python 2.
python2 -m pip install
comes with a built-in webserver. Learn how to write an application by following the tutorial. When you have an application written, put your code into and start the server like this:
Open your browser and go to localhost:8080/ to view the page. To specify another port, use python 1234.
The web server that gets started when you run a program is nice, but
for popular sites you’re going to want something a little more serious.
implements WSGI and runs with
everything that is compatible to it. WSGI is a common API between web servers
and applications, analogous to Java’s Servlet Interface. To run with
CGI, FastCGI or SCGI you will need to install
(download here), which provides WSGI
interfaces for those APIs.
For all the CGI variants, add this to the top of your
And run chmod +x to make it executable.
uWSGI service deployment through Nginx on Linux
mod_wsgi deployment through Nginx
Fastcgi deployment through Nginx
Ligd.. with FastCGI
FastCGI with ligd is the recommended way of using in production. handles millions of hits this way.
Your ligd config can be something like:
dules = (“mod_fastcgi”, “mod_rewrite”)
cument-root = “/path/to/root/”
= ( “/” =>
(( “socket” => “/tmp/”,
“bin-path” => “/path/to/root/”,
“max-procs” => 1)))
write-once = (
“^/$” => “/static/”,
“^/static/(. *)$” => “/static/$1”,
“^/(. *)$” => “/$1”)
With some versions of ligd, it is important to ensure the “check-local” property of the entry is set to “false”, especially if your is located outside of the document root.
If you get error messages about not being able to import flup, install it by typing “easy_install flup” at the command line.
Since revision 145, it is necessary to set a bin-environment variable on the fastcgi configuration if your code uses redirects. If when your code redirects to and in the url bar you see, you’ll need to set the environment variable. This will cause your configuration above to look something like this:
“socket” => “/tmp/”,
“max-procs” => 1,
“bin-environment” => (
“REAL_SCRIPT_NAME” => “”),
“check-local” => “disable”)))
Apache.. with CGI
Add the following to or
Alias /foo/static/ /path/to/static
ScriptAlias /foo/ /path/to/.. htaccess
CGI is easy to configure, but is not suitable for high-performance websites.
Add this to your. htaccess:
and point your browser to. Don’t forget the trailing slash, otherwise you’ll see a not found message (because the urls list you defined do not match anything). To make things work without having to enter, enable mod_rewrite rules (see below).
Note: The way is implemented breaks the cgitb module because it captures stdout. I worked around the issue by using this:
import cgitb; ()
#… import web etc here…
= web. _oldstdout
ternalerror = cgidebugerror.. with FastCGI
FastCGI is easy to configure and performs as well as mod_python.
Unfortunately, unlike ligd, Apache gives no hint that it wants your script to act as a FastCGI server so you have to tell explicitly. Add this to before your if __name__ == “__main__”: line:
= lambda func, addr=None: (func, addr)
Walter has some additional advice… with SCGI
download mod_scgi source here: windows apache user:
LoadModule scgi_module Modules/
SCGIMount / 127. 0. 1:8080
restart apache and then start your in the command below:
python 127. 1:8080 scgi
and open you browser, visit 127. 1
It’s ok!.. with mod_python
mod_python performs as well as FastCGI, but is not as straight-forward to configure.
For Python 2. 5 do this:
cd /usr/lib/python2. 5/wsgiref
# or in windows: cd /python2. 5/lib/wsgiref
wget -O # or fetch the file from that address using your browser
For Python <2. 4/site-packages # or in windows: cd /python2. 4/lib/site-packages svn co svn cd wsgiref Rename your to something like and add: app = lication(urls, globals()) main = gifunc() In your. htaccess, add: AddHandler python-program PythonHandler dpython_gateway::handler PythonOption lication codep::main You also probably want to add a RewriteRule pointing / to / Be sure to visit / with the extra / on the end. Otherwise, you’ll see an error message like A server error occurred. Please contact the administrator... with mod_wsgi mod_wsgi is a new Apache module which typically outperforms mod_python for hosting WSGI applications, and is very easy to set up.