cirospaciari / granian

A Rust HTTP server for Python applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

A Rust HTTP server for Python applications

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Rust 83.0%Language:Python 16.5%Language:Lua 0.2%Language:Makefile 0.2%Language:Shell 0.0%