Skip to main content

A Rust HTTP server for Python applications

Project description

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

Options

You can check all the options provided by Granian with the --help command:

$ granian --help
Usage: granian [OPTIONS] APP

Arguments:
  APP  Application target to serve.  [required]

Options:
  --host TEXT                     Host address to bind to.  [default:
                                  127.0.0.1]
  --port INTEGER                  Port to bind to.  [default: 8000]
  --interface [asgi|rsgi|wsgi]    Application interface type.  [default: rsgi]
  --http [auto|1|2]               HTTP version.  [default: auto]
  --ws / --no-ws                  Enable websockets handling  [default:
                                  (enabled)]
  --workers INTEGER RANGE         Number of worker processes.  [default: 1;
                                  x>=1]
  --threads INTEGER RANGE         Number of threads.  [default: 1; x>=1]
  --threading-mode [runtime|workers]
                                  Threading mode to use.  [default: workers]
  --loop [auto|asyncio|uvloop]    Event loop implementation  [default: auto]
  --backlog INTEGER RANGE         Maximum number of connections to hold in
                                  backlog.  [default: 1024; x>=128]
  --log-level [critical|error|warning|warn|info|debug]
                                  Log level  [default: info]
  --log-config FILE               Logging configuration file (json)
  --ssl-keyfile FILE              SSL key file
  --ssl-certificate FILE          SSL certificate file
  --url-path-prefix TEXT          URL path prefix the app is mounted on
  --reload / --no-reload          Enable auto reload on application's files
                                  changes  [default: no-reload]
  --version                       Shows the version and exit.
  --install-completion [bash|zsh|fish|powershell|pwsh]
                                  Install completion for the specified shell.
  --show-completion [bash|zsh|fish|powershell|pwsh]
                                  Show completion for the specified shell, to
                                  copy it or customize the installation.
  --help                          Show this message and exit.

Project status

Granian is currently under active development.

Granian is compatible with Python 3.8 and above versions.

License

Granian is released under the BSD License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

granian-0.4.2.tar.gz (51.4 kB view hashes)

Uploaded Source

Built Distributions

granian-0.4.2-pp39-pypy39_pp73-win_amd64.whl (1.5 MB view hashes)

Uploaded PyPy Windows x86-64

granian-0.4.2-pp39-pypy39_pp73-musllinux_1_1_x86_64.whl (1.8 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ x86-64

granian-0.4.2-pp39-pypy39_pp73-musllinux_1_1_aarch64.whl (1.7 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARM64

granian-0.4.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

granian-0.4.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

granian-0.4.2-pp39-pypy39_pp73-macosx_11_0_arm64.whl (1.4 MB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

granian-0.4.2-pp39-pypy39_pp73-macosx_10_7_x86_64.whl (1.6 MB view hashes)

Uploaded PyPy macOS 10.7+ x86-64

granian-0.4.2-pp38-pypy38_pp73-musllinux_1_1_x86_64.whl (1.8 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ x86-64

granian-0.4.2-pp38-pypy38_pp73-musllinux_1_1_aarch64.whl (1.7 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARM64

granian-0.4.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

granian-0.4.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

granian-0.4.2-cp311-none-win_amd64.whl (1.5 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

granian-0.4.2-cp311-cp311-musllinux_1_1_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

granian-0.4.2-cp311-cp311-musllinux_1_1_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

granian-0.4.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

granian-0.4.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

granian-0.4.2-cp311-cp311-macosx_11_0_arm64.whl (1.4 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

granian-0.4.2-cp311-cp311-macosx_10_7_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 macOS 10.7+ x86-64

granian-0.4.2-cp310-none-win_amd64.whl (1.5 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

granian-0.4.2-cp310-cp310-musllinux_1_1_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

granian-0.4.2-cp310-cp310-musllinux_1_1_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

granian-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

granian-0.4.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

granian-0.4.2-cp310-cp310-macosx_11_0_arm64.whl (1.4 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

granian-0.4.2-cp310-cp310-macosx_10_7_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

granian-0.4.2-cp39-none-win_amd64.whl (1.5 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

granian-0.4.2-cp39-cp39-musllinux_1_1_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

granian-0.4.2-cp39-cp39-musllinux_1_1_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

granian-0.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

granian-0.4.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

granian-0.4.2-cp39-cp39-macosx_11_0_arm64.whl (1.4 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

granian-0.4.2-cp39-cp39-macosx_10_7_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

granian-0.4.2-cp38-none-win_amd64.whl (1.5 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

granian-0.4.2-cp38-cp38-musllinux_1_1_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

granian-0.4.2-cp38-cp38-musllinux_1_1_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

granian-0.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

granian-0.4.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

granian-0.4.2-cp38-cp38-macosx_11_0_arm64.whl (1.4 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

granian-0.4.2-cp38-cp38-macosx_10_7_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page