A Rust HTTP server for Python applications
Find a file
2023-05-04 10:31:48 +02:00
.github Bump maturin version in CI workflows 2023-03-21 14:16:07 +01:00
benchmarks Update benchmarks 2023-03-14 10:43:56 +01:00
docs/spec Add rationale to RSGI spec (#60) 2023-02-06 03:07:03 +01:00
granian Bump version to 0.4.0 2023-05-04 10:31:48 +02:00
src Simplify WSGI handlers 2023-05-02 18:20:36 +02:00
tests Review websockets protocols close flow 2023-02-15 14:46:37 +01:00
.gitignore first implementation 2022-04-15 18:45:01 +02:00
build.rs Add PyPy support 2023-01-03 12:52:22 +01:00
Cargo.lock Bump version to 0.4.0 2023-05-04 10:31:48 +02:00
Cargo.toml Bump version to 0.4.0 2023-05-04 10:31:48 +02:00
LICENSE first implementation 2022-04-15 18:45:01 +02:00
pyproject.toml Review build configuration (#72) 2023-03-21 14:41:00 +01:00
README.md Update benchmarks results 2022-12-24 18:04:30 +01:00
setup.py review package meta 2022-04-18 20:08:21 +02:00

Granian

A Rust HTTP server for Python applications.

Rationale

The main reasons behind Granian design are:

  • Have a single, correct HTTP implementation, supporting versions 1, 2 (and eventually 3)
  • Provide a single package for several platforms
  • Avoid the usual Gunicorn + uvicorn + http-tools dependency composition on unix systems
  • Provide stable performance when compared to existing alternatives

Features

  • Supports ASGI/3, RSGI and WSGI interface applications
  • Implements HTTP/1 and HTTP/2 protocols
  • Supports HTTPS
  • Supports Websockets over HTTP/1 and HTTP/2

Quickstart

You can install Granian using pip:

$ pip install granian

Create an ASGI application in your main.py:

async def app(scope, receive, send):
    assert scope['type'] == 'http'

    await send({
        'type': 'http.response.start',
        'status': 200,
        'headers': [
            [b'content-type', b'text/plain'],
        ],
    })
    await send({
        'type': 'http.response.body',
        'body': b'Hello, world!',
    })

and serve it:

$ granian --interface asgi main:app

You can also create an app using the RSGI specification:

async def app(scope, proto):
    assert scope.proto == 'http'

    proto.response_str(
        status=200,
        headers=[
            ('content-type', 'text/plain')
        ],
        body="Hello, world!"
    )

and serve it using:

$ granian --interface rsgi main:app

Project status

Granian is currently under active development.

Granian is compatible with Python 3.7 and above versions on unix platforms and 3.8 and above on Windows.

License

Granian is released under the BSD License.