Convert Figma logo to code with AI

cherrypy logocherrypy

CherryPy is a pythonic, object-oriented HTTP framework. https://cherrypy.dev

1,829
361
1,829
250

Top Related Projects

67,504

The Python micro framework for building web applications.

79,088

The Web framework for perfectionists with deadlines.

21,674

Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.

10,027

The little ASGI framework that shines. 🌟

75,446

FastAPI framework, high performance, easy to learn, fast to code, ready for production

3,938

Pyramid - A Python web framework

Quick Overview

CherryPy is a minimalist, object-oriented web framework for Python. It provides a simple and flexible way to build web applications, allowing developers to focus on the core functionality of their project rather than the underlying web server infrastructure.

Pros

  • Lightweight and Modular: CherryPy has a small footprint and can be easily integrated into existing projects or used as a standalone web server.
  • Flexible and Extensible: CherryPy's plugin system allows developers to easily add new functionality and customize the framework to their specific needs.
  • Cross-platform Compatibility: CherryPy runs on multiple platforms, including Windows, macOS, and Linux, making it a versatile choice for web development.
  • Active Community: CherryPy has an active community of contributors and users, providing a wealth of resources, documentation, and support.

Cons

  • Limited Scalability: While CherryPy can handle moderate traffic, it may not be the best choice for highly scalable, high-traffic web applications.
  • Steep Learning Curve: Compared to some other Python web frameworks, CherryPy may have a steeper learning curve for developers new to the ecosystem.
  • Lack of Widespread Adoption: CherryPy is not as widely used as some other popular Python web frameworks, such as Django or Flask, which may limit the availability of third-party libraries and resources.
  • Older Codebase: CherryPy has been around for a long time, and its codebase may not be as modern or feature-rich as some newer web frameworks.

Code Examples

Here are a few examples of how to use CherryPy:

  1. Basic Hello World Application:
import cherrypy

class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        return "Hello, World!"

if __name__ == '__main__':
    cherrypy.quickstart(HelloWorld())
  1. Handling HTTP Methods:
import cherrypy

class MyApp(object):
    @cherrypy.expose
    def index(self, **kwargs):
        if cherrypy.request.method == 'GET':
            return "This is a GET request."
        elif cherrypy.request.method == 'POST':
            return "This is a POST request."
        else:
            raise cherrypy.HTTPError(405, "Method Not Allowed")

if __name__ == '__main__':
    cherrypy.quickstart(MyApp())
  1. Serving Static Files:
import cherrypy

class StaticFileServer(object):
    @cherrypy.expose
    def index(self):
        return """
            <html>
                <body>
                    <a href="static/example.txt">View Example File</a>
                </body>
            </html>
        """

    @cherrypy.expose
    def static(self, filename):
        return cherrypy.lib.static.serve_file(filename, content_type="text/plain")

if __name__ == '__main__':
    cherrypy.config.update({
        'server.socket_host': '0.0.0.0',
        'server.socket_port': 8080,
        'tools.staticdir.root': os.path.abspath(os.getcwd())
    })
    cherrypy.quickstart(StaticFileServer(), '/', {
        '/static': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'static'
        }
    })

Getting Started

To get started with CherryPy, follow these steps:

  1. Install CherryPy using pip:
pip install cherrypy
  1. Create a new Python file (e.g., app.py) and define your web application:
import cherrypy

class MyApp(object):
    @cherrypy.expose
    def index(self):
        return "Hello, World!"

if __name__ == '__main__':
    cherrypy.quickstart(MyApp())
  1. Run the application:
python app.

Competitor Comparisons

67,504

The Python micro framework for building web applications.

Pros of Flask

  • Simplicity: Flask is known for its simplicity and ease of use, making it a great choice for small to medium-sized web applications.
  • Flexibility: Flask is a micro-framework, which means it has a small core and allows developers to choose their own tools and libraries, providing more flexibility.
  • Extensive Ecosystem: The Flask ecosystem is rich with a wide range of third-party extensions, making it easy to add functionality to your application.

Cons of Flask

  • Limited Scalability: As a micro-framework, Flask may not be the best choice for large-scale, complex web applications that require more robust features and performance.
  • Lack of Opinionated Structure: The lack of an opinionated structure in Flask can be both a pro and a con, as it requires developers to make more decisions about the project's architecture.

Code Comparison

Flask:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run()

CherryPy:

import cherrypy

class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        return "Hello, world!"

if __name__ == '__main__':
    cherrypy.quickstart(HelloWorld())

Both examples demonstrate a simple "Hello, World!" application, but the approach differs. Flask uses a more declarative style with the @app.route decorator, while CherryPy uses a class-based approach with the @cherrypy.expose decorator.

79,088

The Web framework for perfectionists with deadlines.

Pros of Django

  • Comprehensive web framework with built-in features like ORM, admin interface, and templating engine
  • Large and active community with extensive documentation and third-party packages
  • Emphasis on rapid development and "batteries included" philosophy

Cons of Django

  • Steeper learning curve compared to lightweight frameworks like CherryPy
  • Monolithic architecture can make it harder to scale individual components
  • May be overkill for smaller projects that don't require all of Django's features

Code Comparison

CherryPy (5 lines):

import cherrypy

class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        return "Hello, world!"

cherrypy.quickstart(HelloWorld())

Django (5 lines):

from django.http import HttpResponse
from django.urls import path

def index(request):
    return HttpResponse("Hello, world!")

urlpatterns = [path('', index)]
21,674

Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.

Pros of Tornado

  • Tornado is a high-performance web framework that is designed to handle large-scale, real-time web applications.
  • It provides a non-blocking I/O model, which allows it to handle a large number of concurrent connections efficiently.
  • Tornado has built-in support for WebSockets, which makes it a good choice for building real-time, bidirectional communication applications.

Cons of Tornado

  • Tornado has a steeper learning curve compared to CherryPy, as it requires a deeper understanding of asynchronous programming concepts.
  • The Tornado community is smaller than the CherryPy community, which may make it harder to find resources and support.
  • Tornado's focus on high-performance and real-time applications may make it overkill for simpler web applications.

Code Comparison

CherryPy:

import cherrypy

class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        return "Hello, World!"

if __name__ == '__main__':
    cherrypy.quickstart(HelloWorld())

Tornado:

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

if __name__ == "__main__":
    app = tornado.web.Application([
        (r"/", MainHandler),
    ])
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()
10,027

The little ASGI framework that shines. 🌟

Pros of Starlette

  • Starlette is a modern, asynchronous web framework that is designed to be fast and efficient, making it a good choice for building high-performance web applications.
  • Starlette has a modular design, which allows developers to easily integrate it with other libraries and frameworks, such as FastAPI and Pydantic.
  • Starlette provides a range of built-in features, such as middleware, routing, and testing utilities, which can help developers save time and effort.

Cons of Starlette

  • Starlette is a relatively new framework, and as such, it may have a smaller community and fewer resources available compared to more established frameworks like CherryPy.
  • Starlette's asynchronous nature may be more complex to understand and work with, especially for developers who are more familiar with traditional synchronous web frameworks.
  • Starlette may have a steeper learning curve compared to CherryPy, as it requires a deeper understanding of asynchronous programming concepts.

Code Comparison

CherryPy (Python):

import cherrypy

class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        return "Hello, world!"

if __name__ == '__main__':
    cherrypy.quickstart(HelloWorld())

Starlette (Python):

from starlette.applications import Starlette
from starlette.responses import HTMLResponse

app = Starlette()

@app.route("/")
async def homepage(request):
    return HTMLResponse("<h1>Hello, world!</h1>")
75,446

FastAPI framework, high performance, easy to learn, fast to code, ready for production

Pros of FastAPI

  • FastAPI is a modern, fast (high-performance), web framework for building APIs with Python, based on standard Python type hints.
  • It provides automatic API documentation generation using Swagger/OpenAPI, making it easy to document and share your API.
  • FastAPI has built-in support for asynchronous programming, allowing for efficient handling of concurrent requests.

Cons of FastAPI

  • FastAPI is a relatively new framework, with a smaller community and ecosystem compared to more established options like CherryPy.
  • The learning curve for FastAPI may be steeper, especially for developers unfamiliar with modern Python features like type hints.
  • FastAPI's focus on API development may not be as suitable for building traditional web applications as CherryPy.

Code Comparison

CherryPy (basic server setup):

import cherrypy

class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        return "Hello, world!"

if __name__ == '__main__':
    cherrypy.quickstart(HelloWorld())

FastAPI (basic server setup):

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}
3,938

Pyramid - A Python web framework

Pros of Pyramid

  • Pyramid provides a more comprehensive and opinionated web framework, with built-in support for features like URL generation, templating, and database integration.
  • Pyramid has a larger and more active community, with more third-party packages and resources available.
  • Pyramid's documentation is generally considered to be more extensive and user-friendly.

Cons of Pyramid

  • Pyramid has a steeper learning curve compared to CherryPy, especially for developers new to web development.
  • Pyramid may be overkill for smaller, simpler web applications that don't require the full set of features it provides.

Code Comparison

CherryPy:

import cherrypy

class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        return "Hello, world!"

if __name__ == '__main__':
    cherrypy.quickstart(HelloWorld())

Pyramid:

from pyramid.config import Configurator
from pyramid.response import Response

def hello_world(request):
    return Response('Hello, world!')

if __name__ == '__main__':
    with Configurator() as config:
        config.add_route('hello', '/')
        config.add_view(hello_world, route_name='hello')
        app = config.make_wsgi_app()

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

.. image:: https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct.svg :target: https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md :alt: SWUbanner

.. image:: https://img.shields.io/pypi/v/cherrypy.svg :target: https://pypi.org/project/cherrypy

.. image:: https://tidelift.com/badges/package/pypi/CherryPy :target: https://tidelift.com/subscription/pkg/pypi-cherrypy?utm_source=pypi-cherrypy&utm_medium=readme :alt: CherryPy is available as part of the Tidelift Subscription

.. image:: https://img.shields.io/badge/Python%203%20only-pip%20install%20%22%3E%3D18.0.0%22-%234da45e.svg :target: https://python3statement.org/

.. image:: https://img.shields.io/badge/Python%203%20and%202-pip%20install%20%22%3C18.0.0%22-%2349a7e9.svg :target: https://python3statement.org/#sections40-timeline

.. image:: https://readthedocs.org/projects/cherrypy/badge/?version=latest :target: https://docs.cherrypy.dev/en/latest/?badge=latest

.. image:: https://img.shields.io/badge/StackOverflow-CherryPy-blue.svg :target: https://stackoverflow.com/questions/tagged/cheroot+or+cherrypy

.. image:: https://img.shields.io/badge/Mailing%20list-cherrypy--users-orange.svg :target: https://groups.google.com/group/cherrypy-users

.. image:: https://img.shields.io/gitter/room/cherrypy/cherrypy.svg :target: https://gitter.im/cherrypy/cherrypy

.. image:: https://img.shields.io/travis/cherrypy/cherrypy/master.svg?label=Linux%20build%20%40%20Travis%20CI :target: https://travis-ci.org/cherrypy/cherrypy

.. image:: https://circleci.com/gh/cherrypy/cherrypy/tree/master.svg?style=svg :target: https://circleci.com/gh/cherrypy/cherrypy/tree/master

.. image:: https://img.shields.io/appveyor/ci/CherryPy/cherrypy/master.svg?label=Windows%20build%20%40%20Appveyor :target: https://ci.appveyor.com/project/CherryPy/cherrypy/branch/master

.. image:: https://img.shields.io/badge/license-BSD-blue.svg?maxAge=3600 :target: https://pypi.org/project/cheroot

.. image:: https://img.shields.io/pypi/pyversions/cherrypy.svg :target: https://pypi.org/project/cherrypy

.. image:: https://badges.github.io/stability-badges/dist/stable.svg :target: https://github.com/badges/stability-badges :alt: stable

.. image:: https://api.codacy.com/project/badge/Grade/48b11060b5d249dc86e52dac2be2c715 :target: https://www.codacy.com/app/webknjaz/cherrypy-upstream?utm_source=github.com&utm_medium=referral&utm_content=cherrypy/cherrypy&utm_campaign=Badge_Grade

.. image:: https://codecov.io/gh/cherrypy/cherrypy/branch/master/graph/badge.svg :target: https://codecov.io/gh/cherrypy/cherrypy :alt: codecov

Welcome to the GitHub repository of CherryPy <https://cherrypy.dev>_!

CherryPy is a pythonic, object-oriented HTTP framework.

  1. It allows building web applications in much the same way one would build any other object-oriented program.
  2. This design results in more concise and readable code developed faster. It's all just properties and methods.
  3. It is now more than ten years old and has proven fast and very stable.
  4. It is being used in production by many sites, from the simplest to the most demanding.
  5. And perhaps most importantly, it is fun to work with :-)

Here's how easy it is to write "Hello World" in CherryPy:

.. code:: python

import cherrypy

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

cherrypy.quickstart(HelloWorld())

And it continues to work that intuitively when systems grow, allowing for the Python object model to be dynamically presented as a website and/or API.

While CherryPy is one of the easiest and most intuitive frameworks out there, the prerequisite for understanding the CherryPy documentation <https://docs.cherrypy.dev>_ is that you have a general understanding of Python and web development. Additionally:

If the docs are insufficient to address your needs, the CherryPy community has several avenues for support <https://docs.cherrypy.dev/en/latest/support.html>_.

For Enterprise

CherryPy is available as part of the Tidelift Subscription.

The CherryPy maintainers and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.

Learn more <https://tidelift.com/subscription/pkg/pypi-cherrypy?utm_source=pypi-cherrypy&utm_medium=referral&utm_campaign=github>_.

Contributing

Please follow the contribution guidelines <https://docs.cherrypy.dev/en/latest/contribute.html>. And by all means, absorb the Zen of CherryPy <https://github.com/cherrypy/cherrypy/wiki/The-Zen-of-CherryPy>.