Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A lightweight web framework for Python 3
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


py3web is a web framework for Python 3.2+, designed to make web programming
simple, intuitive, and rapid. There is no "black magic" that happens behind the
scenes -- as the Zen says, "explicit is better than implicit." The framework
makes liberal use of lazy initialization, so you don't pay for what you don't use.

Here's a quick and dirty demo of the framework's basic features. To run it,
point your favorite CGI or WSGI server at a module containing this code:

from py3web import cgi, html, wsgi

def application(environ, start_response):
	# WSGI entry point:  We launch the framework, passing it the WSGI environment
	# and our routing function. py3web will call the routing function, and then
	# either call the first matching handler, or emit a 404 if no match is found.
	return, start_response, route=do_routes)

def do_routes(router):
	# Routes are defined using regexes, which are automatically surrounded by ^$.
	router.redirect('', 'ask/', 301)
	router.route('ask/', ask)
	router.route('hello/', hello, method='POST')

def ask(web):
	# The client object is canonically passed around using the name 'web'. Just about all
	# interaction with the framework happens through either 'web.request' or 'web.response'.
		'''<form method=post action="/hello/">
		<p><label>Enter your name: <input name=name></label>
		<p><input type=submit>

def hello(web):
		name = web.request.post_vars['name'].string()
	except Exception:
		web.response.write('Forget something?')
		web.response.write('Greetings, <em>' + html.escape(name) + '</em>!')

if __name__ == '__main__':

For development purposes, you can use Python's batteries-included reference
WSGI implementation. Don't ever use it in a production environment, though!

if __name__ == '__main__':
	from wsgiref import simple_server
	httpd = simple_server.make_server('', 80, application)

If you're looking for a production-ready pure Python 3 WSGI web server, I recommend taking
a look at the one included with CherryPy. It's probably about as fast as you can get
without resorting to C code, and it can be used independently from the rest of CherryPy:

if __name__ == '__main__':
	from cherrypy import wsgiserver
	httpd = wsgiserver.CherryPyWSGIServer(('', 80), application)
Something went wrong with that request. Please try again.