Convert Figma logo to code with AI

kennethreitz logoresponder

A familiar HTTP Service Framework for Python.

3,605
219
3,605
17

Top Related Projects

82,358

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

68,546

The Python micro framework for building web applications.

10,758

The little ASGI framework that shines. 🌟

81,957

The Web framework for perfectionists with deadlines.

21,808

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

15,334

Asynchronous HTTP client/server framework for asyncio and Python

Quick Overview

Responder is a modern Python web framework designed to make building web APIs and services easier and more intuitive. It combines the best ideas from other frameworks like Flask and Falcon, offering a declarative and expressive API with high performance.

Pros

  • Simple and intuitive API design
  • Built-in support for WebSocket and background tasks
  • Automatic API documentation generation
  • High performance due to ASGI foundation

Cons

  • Relatively new project, may have fewer third-party extensions compared to more established frameworks
  • Limited community support and resources compared to larger frameworks
  • May lack some advanced features found in more mature frameworks
  • Documentation could be more comprehensive

Code Examples

  1. Basic route handling:
import responder

api = responder.API()

@api.route("/")
def hello_world(req, resp):
    resp.text = "Hello, World!"

api.run()
  1. JSON response:
@api.route("/api/data")
def get_data(req, resp):
    resp.media = {"name": "John", "age": 30}
  1. WebSocket support:
@api.route("/ws", websocket=True)
async def websocket(ws):
    await ws.accept()
    while True:
        message = await ws.receive_text()
        await ws.send_text(f"Echo: {message}")
  1. Background tasks:
@api.route("/task")
async def long_running_task(req, resp):
    @api.background.task
    def process_data(data):
        # Simulating a long-running task
        time.sleep(5)
        print(f"Processed: {data}")

    process_data("sample data")
    resp.media = {"message": "Task started"}

Getting Started

  1. Install Responder:

    pip install responder
    
  2. Create a new file (e.g., app.py) with the following content:

    import responder
    
    api = responder.API()
    
    @api.route("/")
    def hello_world(req, resp):
        resp.text = "Hello, World!"
    
    if __name__ == "__main__":
        api.run()
    
  3. Run the application:

    python app.py
    
  4. Open a web browser and navigate to http://localhost:5042 to see your application running.

Competitor Comparisons

82,358

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

Pros of FastAPI

  • Better performance due to Starlette and Pydantic
  • More comprehensive documentation and larger community
  • Built-in support for async/await syntax

Cons of FastAPI

  • Steeper learning curve for beginners
  • More verbose code for simple applications

Code Comparison

Responder:

import responder

api = responder.API()

@api.route("/")
def hello_world(req, resp):
    resp.text = "Hello, World!"

api.run()

FastAPI:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def hello_world():
    return {"message": "Hello, World!"}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

Key Differences

  • FastAPI uses type hints for request/response validation
  • Responder focuses on simplicity and ease of use
  • FastAPI offers more features out of the box, including OpenAPI documentation
  • Responder has a more Flask-like API, while FastAPI is inspired by modern Python frameworks

Conclusion

FastAPI is generally considered more powerful and feature-rich, while Responder aims for simplicity and ease of use. Choose FastAPI for larger, more complex projects, and Responder for quick prototypes or simpler applications.

68,546

The Python micro framework for building web applications.

Pros of Flask

  • Mature and widely adopted framework with extensive documentation
  • Large ecosystem of extensions and plugins
  • Highly flexible and customizable

Cons of Flask

  • Requires more boilerplate code for basic setup
  • Less opinionated, which can lead to decision fatigue for beginners

Code Comparison

Flask:

from flask import Flask

app = Flask(__name__)

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

Responder:

import responder

api = responder.API()

@api.route('/')
def hello(req, resp):
    resp.text = 'Hello, World!'

Key Differences

  • Responder aims to simplify API development with less boilerplate
  • Flask offers more granular control over request/response handling
  • Responder includes built-in features like WebSocket support and background tasks
  • Flask relies on extensions for advanced functionality

Use Cases

  • Flask: Larger applications, projects requiring specific customizations
  • Responder: Rapid API development, smaller projects prioritizing simplicity

Both frameworks are Python-based and suitable for web development, but they cater to different preferences in terms of simplicity vs. flexibility.

10,758

The little ASGI framework that shines. 🌟

Pros of Starlette

  • Higher performance and lower overhead
  • More flexible and customizable
  • Better suited for larger, more complex applications

Cons of Starlette

  • Steeper learning curve
  • Requires more boilerplate code
  • Less opinionated, which may lead to inconsistencies in large projects

Code Comparison

Responder:

import responder

api = responder.API()

@api.route("/")
def hello_world(req, resp):
    resp.text = "Hello, World!"

api.run()

Starlette:

from starlette.applications import Starlette
from starlette.responses import PlainTextResponse
from starlette.routing import Route

async def hello_world(request):
    return PlainTextResponse("Hello, World!")

app = Starlette(routes=[
    Route("/", hello_world)
])

Summary

Responder is built on top of Starlette and aims to provide a more user-friendly, Flask-like experience. It's easier to get started with and requires less code for basic applications. Starlette, on the other hand, offers more control and better performance at the cost of increased complexity. The choice between the two depends on the project's requirements, the developer's experience, and the desired level of control over the application's architecture.

81,957

The Web framework for perfectionists with deadlines.

Pros of Django

  • Comprehensive full-stack framework with built-in admin interface
  • Large ecosystem with extensive third-party packages
  • Robust ORM for database operations

Cons of Django

  • Steeper learning curve for beginners
  • Can be overkill for small projects
  • More boilerplate code required

Code Comparison

Django:

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

def hello(request):
    return HttpResponse("Hello, World!")

urlpatterns = [
    path('hello/', hello),
]

Responder:

import responder

api = responder.API()

@api.route("/hello")
def hello(req, resp):
    resp.text = "Hello, World!"

api.run()

Django requires more setup and configuration, while Responder offers a more concise and straightforward approach for simple API endpoints. Django's routing is defined separately, whereas Responder uses decorators. Django's view functions receive a request object and return a response, while Responder's route handlers modify a response object directly.

21,808

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

Pros of Tornado

  • More mature and battle-tested, with a larger community and ecosystem
  • Supports both synchronous and asynchronous programming models
  • Offers built-in WebSocket support and other advanced features

Cons of Tornado

  • Steeper learning curve, especially for beginners
  • Less modern syntax and conventions compared to newer frameworks
  • Requires more boilerplate code for basic functionality

Code Comparison

Responder:

import responder

api = responder.API()

@api.route("/")
def hello_world(req, resp):
    resp.text = "Hello, World!"

api.run()

Tornado:

import tornado.ioloop
import tornado.web

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

app = tornado.web.Application([(r"/", MainHandler)])
app.listen(8000)
tornado.ioloop.IOLoop.current().start()

Summary

Tornado is a more established and feature-rich framework, offering greater flexibility and advanced capabilities. However, it comes with a steeper learning curve and requires more code for basic tasks. Responder, on the other hand, provides a more modern and intuitive API, making it easier for beginners to get started, but may lack some of the advanced features and maturity of Tornado.

15,334

Asynchronous HTTP client/server framework for asyncio and Python

Pros of aiohttp

  • More mature and widely adopted project with extensive documentation
  • Offers lower-level control and flexibility for advanced use cases
  • Supports both client and server-side HTTP implementations

Cons of aiohttp

  • Steeper learning curve, especially for beginners
  • Requires more boilerplate code for common web development tasks
  • Less opinionated, which can lead to inconsistencies across projects

Code Comparison

aiohttp example:

from aiohttp import web

async def hello(request):
    return web.Response(text="Hello, World!")

app = web.Application()
app.add_routes([web.get('/', hello)])
web.run_app(app)

Responder example:

import responder

api = responder.API()

@api.route("/")
def hello_world(req, resp):
    resp.text = "Hello, World!"

api.run()

Summary

aiohttp is a more established and versatile library, offering greater control and flexibility for experienced developers. It's well-suited for complex applications requiring fine-tuned performance. However, it can be more challenging for beginners and requires more code for basic tasks.

Responder, on the other hand, provides a more user-friendly and intuitive API, making it easier to get started with web development in Python. It offers a simpler syntax and requires less boilerplate code, but may lack some of the advanced features and customization options available in aiohttp.

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

Responder: a familiar HTTP Service Framework for Python

ci-tests ci-docs Documentation Status version license python-versions downloads contributors status

responder-synopsis

Responder is powered by Starlette. View documentation.

Responder gets you an ASGI app, with a production static files server pre-installed, Jinja templating, and a production webserver based on uvloop, automatically serving up requests with gzip compression. The async declaration within the example program is optional.

Testimonials

"Pleasantly very taken with python-responder. @kennethreitz at his absolute best." —Rudraksh M.K.

"ASGI is going to enable all sorts of new high-performance web services. It's awesome to see Responder starting to take advantage of that." — Tom Christie author of Django REST Framework

"I love that you are exploring new patterns. Go go go!" — Danny Greenfield, author of Two Scoops of Django

More Examples

See the documentation's feature tour for more details on features available in Responder.

Installing Responder

Install the most recent stable release:

pip install --upgrade 'responder'

Include support for all extensions and interfaces:

pip install --upgrade 'responder[full]'

Individual optional installation extras are:

  • graphql: Adds GraphQL support via Graphene
  • openapi: Adds OpenAPI/Swagger interface support

Install package with CLI and GraphQL support:

uv pip install --upgrade 'responder[cli,graphql]'

Alternatively, install directly from the repository:

pip install 'responder[full] @ git+https://github.com/kennethreitz/responder.git'

Responder supports Python 3.7+.

The Basic Idea

The primary concept here is to bring the niceties that are brought forth from both Flask and Falcon and unify them into a single framework, along with some new ideas I have. I also wanted to take some of the API primitives that are instilled in the Requests library and put them into a web framework. So, you'll find a lot of parallels here with Requests.

  • Setting resp.content sends back bytes.
  • Setting resp.text sends back unicode, while setting resp.html sends back HTML.
  • Setting resp.media sends back JSON/YAML (.text/.html/.content override this).
  • Case-insensitive req.headers dict (from Requests directly).
  • resp.status_code, req.method, req.url, and other familiar friends.

Ideas

  • Flask-style route expression, with new capabilities -- all while using Python 3.6+'s new f-string syntax.
  • I love Falcon's "every request and response is passed into to each view and mutated" methodology, especially response.media, and have used it here. In addition to supporting JSON, I have decided to support YAML as well, as Kubernetes is slowly taking over the world, and it uses YAML for all the things. Content-negotiation and all that.
  • A built in testing client that uses the actual Requests you know and love.
  • The ability to mount other WSGI apps easily.
  • Automatic gzipped-responses.
  • In addition to Falcon's on_get, on_post, etc methods, Responder features an on_request method, which gets called on every type of request, much like Requests.
  • A production static file server is built-in.
  • Uvicorn built-in as a production web server. I would have chosen Gunicorn, but it doesn't run on Windows. Plus, Uvicorn serves well to protect against slowloris attacks, making nginx unnecessary in production.
  • GraphQL support, via Graphene. The goal here is to have any GraphQL query exposable at any route, magically.
  • Provide an official way to run webpack.

Development

See Development Sandbox.

Supported by

JetBrains logo.

Special thanks to the kind people at JetBrains s.r.o. for supporting us with excellent development tooling.