Jump to content

CherryPy

From Wikipedia, the free encyclopedia

Template:Short description {{#invoke:Infobox|infobox}}Template:Template other {{#invoke:Check for unknown parameters|check|unknown=Template:Main other|preview=Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y| AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo class | logo size | logo title | logo upright | logo_alt | logo_caption | logo_class | logo_size | logo_title | logo_upright | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | qid | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot class | screenshot size | screenshot title | screenshot upright | screenshot_alt | screenshot_class | screenshot_size | screenshot_upright | service_name | size | standard | title | ver layout | website }}Template:Main other{{#invoke:Check for conflicting parameters|check | template = Template:Infobox software | cat = Template:Main other | logo size; logo_size | logo class; logo_class | logo alt; logo_alt | logo title; logo_title | logo caption; logo_caption | screenshot size; screenshot_size | screenshot upright; screenshot_upright | screenshot class; screenshot_class | screenshot alt; screenshot_alt | screenshot title; screenshot title | latest release version; latest_release_version | latest release date; latest_release_date | latest preview version; latest_preview_version | latest preview date; latest_preview_date | latest release version; latest_release_version | latest release date; latest_release_date | latest preview version; latest_preview_version | latest preview date; latest_preview_date | programming language; programming_language | operating system; operating_system }} Template:Self-published CherryPy is an object-oriented web application framework using the Python programming language. It is designed for rapid development of web applications by wrapping the HTTP protocol but stays at a low level and does not offer much more than what is defined in RFC 7231.

CherryPy can be a web server itself or one can launch it via any WSGI compatible environment. It does not deal with tasks such as templating for output rendering or backend access. The framework is extensible with filters, which are called at defined points in the request/response processing.

Pythonic interface

One of the goals of the project founder, Remi Delon, was to make CherryPy as pythonic as possible. This allows the developer to use the framework as any regular Python module and to forget (from a technical point of view) that the application is for the web.

For instance, the common Hello World program with CherryPy 3 would look like:

<syntaxhighlight lang="python"> import cherrypy

class HelloWorld:

   def index(self):
       return "Hello World!"
   index.exposed = True

cherrypy.quickstart(HelloWorld()) </syntaxhighlight>Or, as the example currently shows on their website, using Python decorators to automatically expose the index route:<syntaxhighlight lang="python"> import cherrypy

class HelloWorld(object):

   @cherrypy.expose
   def index(self):
       return "Hello World!"

cherrypy.quickstart(HelloWorld()) </syntaxhighlight>

Features

CherryPy implements:

  • A HTTP/1.1-compliant, WSGI thread-pooled webserver.[1] Typically, CherryPy itself takes only 1–2 ms per page.[2][3]
  • Support for any other WSGI-enabled web server or adapter, including Apache, IIS, lighttpd, mod_python, FastCGI, SCGI, and mod_wsgi.
  • A native mod_python adapter.
  • Multiple HTTP servers (e.g. ability to listen on multiple ports).[4]
  • A plugin system[5] CherryPy plugins hook into events within the server process — into server startup, server shutdown, server exiting, etc. — to run code that needs to be run when the server starts up or shuts down.
  • Built-in tools for caching, encoding, sessions, authorization, static content, and others. CherryPy tools hook into events within the request process. Whenever the CherryPy server receives a request, there is a specific set of steps it goes through to handle that request. Page handlers are only one step in the process. Tools also provide a syntax and configuration API for turning them on and off for a specific set of handlers.
  • A configuration system for developers and deployers .[6][7][8] CherryPy deployments are configurable on site, on application and on controller level, through Python dictionaries, configuration files, and open file objects.
  • A complete test suite for core functionality and associated framework which can be used to test CherryPy applications.[9]
  • Built-in profiling since v2.1,[10] coverage[11] and testing support.

CherryPy doesn't force you to use a specific object–relational mapper (ORM), template language or JavaScript library.

Can be used with CherryPy

  • Routes — a Python re-implementation of the Ruby on Rails's routes system for mapping URLs to controllers/actions and generating URLs.[12]

Object–relational mappers

Templating languages

  • Mako[16] — a template library written in Python, usable with a simple CherryPy tool.[17]
  • Cheetah — an open source template engine and code generation tool, written in Python.
  • CherryTemplate — a templating language for CherryPy.
  • Genshi[18][19] — a powerful XML templating language.
  • Jinja — a general purpose templating language. CherryPy has a tool for using Jinja templates.[20]
  • Kid — a simple template language for XML based vocabularies written in Python. TurboGears 1.x uses CherryPy as server and Kid as frontend.[21]

CherryPy wiki helps[22] choosing a templating language.

Products using CherryPy

  • TurboGears — CherryPy 2.x is a main component of TurboGears 1.x.
  • Splunk Enterprise — CherryPy 3.1.2[23]

See also

{{#invoke:Portal|portal}}

References

Template:Reflist

Template:Python web frameworks Template:Web frameworks

  1. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  2. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  3. ↑ How fast is CherryPy? Template:Webarchive
  4. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  5. ↑ Custom engine plugins with CherryPy Template:Webarchive
  6. ↑ Configuration system of CherryPy Template:Webarchive
  7. ↑ Configuration API of CherryPy Template:Webarchive
  8. ↑ Short summary of configuration options
  9. ↑ How to test CherryPy itself Template:Webarchive
  10. ↑ Profiler module of CherryPy Template:Webarchive
  11. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  12. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  13. ↑ TurboGears 2.x uses CherryPy as server and SQLAlchemy as its default ORM
  14. ↑ TurboGears 1.x uses CherryPy as server and SQLObject as ORM Template:Webarchive
  15. ↑ Dejavu Template:Webarchive
  16. ↑ Mako
  17. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  18. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  19. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  20. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  21. ↑ TurboGears 1.x uses CherryPy as server and Kid as frontend Template:Webarchive
  22. ↑ CherryPy wiki about choosing a templating language Template:Webarchive
  23. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}