Pesto
======
Introduction
------------
Pesto is a library for Python web applications. It aims to make writing WSGI
web applications easy and fun. Pesto doesn't constrain you ? how you integrate
with databases, what templating system you use or how you prefer to lay out
your source files is up to you. Above all, pesto is small, well documented and
well tested.
Pesto makes it easy to:
- Map any URI to any part of your application.
- Produce unicode aware, standards compliant WSGI applications.
- Easily interogate WSGI request parameters ? form variables and HTTP request headers.
- Create and manipulate HTTP headers, redirects, cookies etc.
- Integrate with any other WSGI application or middleware, giving you
access to a vast and growing resource.
Contents:
.. toctree::
:maxdepth: 2
getting_started
request
response
dispatch
cookies
session
wsgiutils
caching
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Examples
---------
A simple script to run in a CGI environment::
#!/usr/bin/env python
import pesto
from pesto import Response
def handler(request):
return Response([
"<html>",
"<body><h1>Whoa Nelly!</h1></body>",
"</html>",
])
if __name__ == "__main__":
app = pesto.to_wsgi(handler)
pesto.run_with_cgi(app)
A longer example which uses the ``urldispatcher`` mechanism to map URLs to
handlers, running through Python's wsgiref server::
#!/usr/bin/env python
import pesto
from pesto import Response
dispatcher = pesto.urldispatcher()
recipes = {
'baked-beans' : "Open a tin of baked beans. Put into a saucepan, heat and serve.",
'toast' : "Put a slice of bread under a grill for 2-3 minutes, turning once. Serve.",
}
@dispatcher.match('/', 'GET')
def recipe_index(request):
"""
Display an index of available recipes.
"""
markup = ['<html><body><h1>List of recipes</h1><ul>']
for recipe in recipes:
markup.append(
'<li><a href="%s">%s</a></li>' % (
show_recipe.url(recipe=recipe),
recipe
)
)
markup.append('</ul></body></html>')
return Response(markup)
@dispatcher.match('/recipes/<recipe:unicode>', 'GET')
def show_recipe(request, response, recipe):
"""
Display a single recipe
"""
return Response([
'<html><body><h1>How to make %s</h1>' % recipe,
'<p>%s</p><a href="%s">Back to index</a>' % (recipes[recipe], recipe_index.url()),
'</body></html>'
])
if __name__ == "__main__":
from wsgiref import simple_server
httpd = simple_server.make_server('', 8080, dispatcher)
httpd.serve_forever()
Development status
------------------
Pesto is production ready and used on a wide variety of websites.
To browse or check out the latest development version, visit
http://patch-tag.com/repo/pesto. For documentation, visit http://pesto.redgecko.org/.
Licence
--------
Pesto is available under the terms of the `new BSD licence <http://www.opensource.org/licenses/bsd-license.php>`_.
======
Introduction
------------
Pesto is a library for Python web applications. It aims to make writing WSGI
web applications easy and fun. Pesto doesn't constrain you ? how you integrate
with databases, what templating system you use or how you prefer to lay out
your source files is up to you. Above all, pesto is small, well documented and
well tested.
Pesto makes it easy to:
- Map any URI to any part of your application.
- Produce unicode aware, standards compliant WSGI applications.
- Easily interogate WSGI request parameters ? form variables and HTTP request headers.
- Create and manipulate HTTP headers, redirects, cookies etc.
- Integrate with any other WSGI application or middleware, giving you
access to a vast and growing resource.
Contents:
.. toctree::
:maxdepth: 2
getting_started
request
response
dispatch
cookies
session
wsgiutils
caching
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Examples
---------
A simple script to run in a CGI environment::
#!/usr/bin/env python
import pesto
from pesto import Response
def handler(request):
return Response([
"<html>",
"<body><h1>Whoa Nelly!</h1></body>",
"</html>",
])
if __name__ == "__main__":
app = pesto.to_wsgi(handler)
pesto.run_with_cgi(app)
A longer example which uses the ``urldispatcher`` mechanism to map URLs to
handlers, running through Python's wsgiref server::
#!/usr/bin/env python
import pesto
from pesto import Response
dispatcher = pesto.urldispatcher()
recipes = {
'baked-beans' : "Open a tin of baked beans. Put into a saucepan, heat and serve.",
'toast' : "Put a slice of bread under a grill for 2-3 minutes, turning once. Serve.",
}
@dispatcher.match('/', 'GET')
def recipe_index(request):
"""
Display an index of available recipes.
"""
markup = ['<html><body><h1>List of recipes</h1><ul>']
for recipe in recipes:
markup.append(
'<li><a href="%s">%s</a></li>' % (
show_recipe.url(recipe=recipe),
recipe
)
)
markup.append('</ul></body></html>')
return Response(markup)
@dispatcher.match('/recipes/<recipe:unicode>', 'GET')
def show_recipe(request, response, recipe):
"""
Display a single recipe
"""
return Response([
'<html><body><h1>How to make %s</h1>' % recipe,
'<p>%s</p><a href="%s">Back to index</a>' % (recipes[recipe], recipe_index.url()),
'</body></html>'
])
if __name__ == "__main__":
from wsgiref import simple_server
httpd = simple_server.make_server('', 8080, dispatcher)
httpd.serve_forever()
Development status
------------------
Pesto is production ready and used on a wide variety of websites.
To browse or check out the latest development version, visit
http://patch-tag.com/repo/pesto. For documentation, visit http://pesto.redgecko.org/.
Licence
--------
Pesto is available under the terms of the `new BSD licence <http://www.opensource.org/licenses/bsd-license.php>`_.
Metadata
Release files for pesto 10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pesto-10.tar.gz | 59.7 kB | Details |
Release files / pesto-10.tar.gz
| Download URL | pesto-10.tar.gz |
|---|---|
| Size | 59.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5682dbb005a64b1abc562fc9a8a4ff1349ea92aaa5bfe50bd4adf2bc74ef9354
|
|
BLAKE2b-256 checksum How to use checksums |
bd865851ee7686cccea60bfbffb4fb690ad534524fc1adbdfe9ed0f90916abf3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |