1.. _tutorials.quickstart.nogae:
2
3Quick start (to use webapp2 outside of App Engine)
4==================================================
5webapp2 can also be used outside of App Engine as a general purpose web
6framework, as it has these features:
7
8- It is independent of the App Engine SDK. If the SDK is not found, it sets
9  fallbacks to be used outside of App Engine.
10- It supports threaded environments through the module :ref:`api.webapp2_extras.local`.
11- All webapp2_extras modules are designed to be thread-safe.
12- It is compatible with ``WebOb`` 1.0 and superior, which fixes several bugs
13  found in the version bundled with the SDK (which is of course supported as
14  well).
15
16It won't support App Engine services, but if you like webapp, why not use it
17in other servers as well? Here we'll describe how to do this.
18
19.. note::
20   If you want to use webapp2 on App Engine,
21   read the :ref:`tutorials.quickstart` tutorial instead.
22
23
24Prerequisites
25-------------
26If you don't have a package installer in your system yet (like ``pip`` or
27``easy_install``), install one. See :ref:`tutorials.installing.packages`.
28
29If you don't have ``virtualenv`` installed in your system yet, install it.
30See :ref:`tutorials.virtualenv`.
31
32
33Create a directory for your app
34-------------------------------
35Create a directory ``hellowebapp2`` for your new app. It is where you will
36setup the environment and create your application.
37
38
39Install WebOb, Paste and webapp2
40--------------------------------
41We need three libraries to use webapp2: `WebOb <http://pypi.python.org/pypi/WebOb>`_, for Request and Response objects,
42`Paste <http://pypi.python.org/pypi/Paste>`_, for the development server,
43and `webapp2 <http://pypi.python.org/pypi/webapp2>`_ itself.
44
45Type this to install them using the **active virtual environment**
46(see :ref:`tutorials.virtualenv`):
47
48.. code-block:: text
49
50   $ pip install WebOb
51   $ pip install Paste
52   $ pip install webapp2
53
54Or, using easy_install:
55
56.. code-block:: text
57
58   $ easy_install WebOb
59   $ easy_install Paste
60   $ easy_install webapp2
61
62Now the environment is ready for your first app.
63
64
65Hello, webapp2!
66---------------
67Create a file ``main.py`` inside your ``hellowebapp2`` directory and define
68a handler to display a 'Hello, webapp2!' message. This will be our bootstrap
69file::
70
71    import webapp2
72
73    class HelloWebapp2(webapp2.RequestHandler):
74        def get(self):
75            self.response.write('Hello, webapp2!')
76
77    app = webapp2.WSGIApplication([
78        ('/', HelloWebapp2),
79    ], debug=True)
80
81    def main():
82        from paste import httpserver
83        httpserver.serve(app, host='127.0.0.1', port='8080')
84
85    if __name__ == '__main__':
86        main()
87
88
89Test your app
90-------------
91Now start the development server using the Python executable provided by
92virtualenv:
93
94.. code-block:: text
95
96   $ python main.py
97
98The web server is now running, listening for requests on port 8080. You can
99test the application by visiting the following URL in your web browser:
100
101    http://127.0.0.1:8080/
102