Metadata-Version: 2.4
Name: responder
Version: 3.6.2
Summary: A familiar HTTP Service Framework for Python.
Author-email: Kenneth Reitz <me@kennethreitz.org>
License: Apache 2.0
Project-URL: Documentation, https://responder.kennethreitz.org
Project-URL: Homepage, https://github.com/kennethreitz/responder
Project-URL: Issues, https://github.com/kennethreitz/responder/issues
Project-URL: Repository, https://github.com/kennethreitz/responder
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: Free Threading
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Internet :: WWW/HTTP
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: a2wsgi
Requires-Dist: apispec>=1
Requires-Dist: chardet
Requires-Dist: docopt-ng
Requires-Dist: graphene>=3
Requires-Dist: graphql-core>=3.1
Requires-Dist: marshmallow
Requires-Dist: msgpack
Requires-Dist: pueblo[sfa-full]>=0.0.11
Requires-Dist: pydantic>=2
Requires-Dist: python-multipart
Requires-Dist: starlette[full]>=1
Requires-Dist: uvicorn[standard]
Provides-Extra: develop
Requires-Dist: pyproject-fmt; extra == "develop"
Requires-Dist: ruff; extra == "develop"
Requires-Dist: validate-pyproject; extra == "develop"
Provides-Extra: docs
Requires-Dist: alabaster<1.1; extra == "docs"
Requires-Dist: myst-parser; extra == "docs"
Requires-Dist: sphinx<9,>=5; extra == "docs"
Requires-Dist: sphinx-autobuild; extra == "docs"
Requires-Dist: sphinx-copybutton; extra == "docs"
Requires-Dist: sphinx-design-elements; extra == "docs"
Provides-Extra: release
Requires-Dist: build; extra == "release"
Requires-Dist: twine; extra == "release"
Provides-Extra: test
Requires-Dist: flask; extra == "test"
Requires-Dist: mypy; extra == "test"
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Requires-Dist: pytest-mock; extra == "test"
Requires-Dist: pytest-rerunfailures; extra == "test"
Dynamic: license-file

# Responder

A familiar HTTP Service Framework for Python, powered by [Starlette](https://www.starlette.io/).

```python
import responder

api = responder.API()

@api.route("/{greeting}")
async def greet_world(req, resp, *, greeting):
    resp.text = f"{greeting}, world!"

if __name__ == "__main__":
    api.run()
```

    $ pip install responder

That's it. Supports Python 3.10+.

## The Basics

- `resp.text` sends back text. `resp.html` sends back HTML. `resp.content` sends back bytes.
- `resp.media` sends back JSON (or YAML, with content negotiation).
- `resp.file("path.pdf")` serves a file with automatic content-type detection.
- `req.headers` is case-insensitive. `req.params` gives you query parameters.
- Both sync and async views work — the `async` is optional.

## Highlights

```python
# Type-safe route parameters
@api.route("/users/{user_id:int}")
async def get_user(req, resp, *, user_id):
    resp.media = {"id": user_id}

# HTTP method filtering
@api.route("/items", methods=["POST"])
async def create_item(req, resp):
    data = await req.media()
    resp.media = {"created": data}

# Class-based views
@api.route("/things/{id}")
class ThingResource:
    def on_get(self, req, resp, *, id):
        resp.media = {"id": id}
    def on_post(self, req, resp, *, id):
        resp.text = "created"

# Before-request hooks (auth, rate limiting, etc.)
@api.route(before_request=True)
def check_auth(req, resp):
    if not req.headers.get("Authorization"):
        resp.status_code = 401
        resp.media = {"error": "unauthorized"}

# Custom error handling
@api.exception_handler(ValueError)
async def handle_error(req, resp, exc):
    resp.status_code = 400
    resp.media = {"error": str(exc)}

# Lifespan events
from contextlib import asynccontextmanager

@asynccontextmanager
async def lifespan(app):
    print("starting up")
    yield
    print("shutting down")

api = responder.API(lifespan=lifespan)

# GraphQL
import graphene
api.graphql("/graphql", schema=graphene.Schema(query=Query))

# WebSockets
@api.route("/ws", websocket=True)
async def websocket(ws):
    await ws.accept()
    while True:
        name = await ws.receive_text()
        await ws.send_text(f"Hello {name}!")

# Mount WSGI/ASGI apps
from flask import Flask
flask_app = Flask(__name__)
api.mount("/flask", flask_app)

# Background tasks
@api.route("/work")
def do_work(req, resp):
    @api.background.task
    def process():
        import time; time.sleep(10)
    process()
    resp.media = {"status": "processing"}
```

Built-in OpenAPI docs, cookie-based sessions, gzip compression, static file serving, Jinja2 templates, and a production uvicorn server.

Route convertors: `str`, `int`, `float`, `uuid`, `path`.

## Documentation

https://responder.kennethreitz.org
