Skip to main content

WSGI server implemented in Rust.

Project description

Pyruvate WSGI server

https://gitlab.com/tschorr/pyruvate/badges/master/pipeline.svg https://codecov.io/gl/tschorr/pyruvate/branch/master/graph/badge.svg http://img.shields.io/pypi/v/pyruvate.svg

Pyruvate is a WSGI server implemented in Rust.

Features

Development Installation

  • Install Rust

  • Install and activate a Python 3 (> 3.5) virtualenv

  • Install setuptools_rust using pip:

    $ pip install setuptools_rust

  • Install pyruvate, e.g. using pip:

    $ pip install -e git+https://gitlab.com/tschorr/pyruvate.git#egg=pyruvate[test]

Using Pyruvate in your WSGI application

From Python

A hello world WSGI application using pyruvate listening on 127.0.0.1:7878 and using 2 worker threads looks like this:

import pyruvate

def application(environ, start_response):
    """Simplest possible application object"""
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers, None)
    return [b"Hello world!\n"]

pyruvate.serve(application, "127.0.0.1:7878", 2)

Using PasteDeploy

Again listening on 127.0.0.1:7878 and using 2 worker threads:

[server:main]
use = egg:pyruvate#main
socket = 127.0.0.1:7878
workers = 2

Configuration Options

socket

Required: The TCP socket Pyruvate should bind to. pyruvate also supports systemd socket activation If you specify None as the socket value, pyruvate will try to acquire a socket bound by systemd.

workers

Required: Number of worker threads to use.

write_blocking

Optional: Use a blocking connection for writing. Pyruvate currently supports two types of workers: The default worker will write in a non-blocking manner, registering WSGI responses for later processing if the socket isn’t available for writing immediately. By setting this option to True you can enable a worker that will instead set the connection into blocking mode for writing. Defaults to False.

max_number_headers

Optional: Maximum number of request headers that will be parsed. If a request contains more headers than configured, request processing will stop with an error indicating an incomplete request. The default is 16 headers.

Example Configurations

Django 2

After installing Pyruvate in your Django virtualenv, create or modify your wsgi.py file (one worker listening on 127.0.0.1:8000):

import os
import pyruvate

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_django_application.settings")

application = get_wsgi_application()

pyruvate.serve(application, "127.0.0.1:8000", 1)

You can now start Django + Pyruvate with:

$ python wsgi.py

Override settings by using the DJANGO_SETTINGS_MODULE environment variable when appropriate. Tested with Django 2.2.x.

Mapproxy

Create or modify config.py (2 workers listening on 127.0.0.1:8005):

from logging.config import fileConfig
import os.path
import pyruvate
fileConfig(r'/path/to/mapproxy/log.ini', {'here': os.path.dirname(__file__)})

from mapproxy.wsgiapp import make_wsgi_app
application = make_wsgi_app(r'/path/to/mapproxy/mapproxy.yml')

pyruvate.serve(application, "127.0.0.1:8005", 2)

Start from your virtualenv:

$ python config.py

Tested with Mapproxy 1.12.x.

Plone 5.2

Using zc.buildout and plone.recipe.zope2instance you can define an instance part using Pyruvate’s PasteDeploy <https://pastedeploy.readthedocs.io/en/latest/> _entry point:

[instance]
recipe = plone.recipe.zope2instance
http-address = 127.0.0.1:8080
eggs =
    Plone
    pyruvate
wsgi-ini-template = ${buildout:directory}/templates/pyruvate.ini.in

The server section of the template provided with the wsgi-ini-template option should look like this (3 workers listening on http-address as specified in the buildout [instance] part):

[server:main]
use = egg:pyruvate#main
socket = %(http_address)s
workers = 3

Tested with Plone 5.2.x.

Nginx settings

Like other WSGI servers pyruvate should be used behind a reverse proxy, e.g. Nginx:

....
location / {
    proxy_pass http://localhost:7878;
    ...
}
...

Changelog

0.5.2 (2020-07-15)

  • Fix testing for completed response in case of EAGAIN

  • Cargo update

0.5.1 (2020-07-07)

  • Fix handling of read events

  • Fix changelog

  • Cargo update

  • ‘Interrupted’ error is not a todo

  • Remove unused code

0.5.0 (2020-06-07)

  • Add support for systemd socket activation

0.4.0 (2020-06-29)

  • Add a new worker that does nonblocking write

  • Add default arguments

  • Add option to configure maximum number of request headers

  • Add Via header

0.3.0 (2020-06-16)

  • Switch to rust-cpython

  • Fix passing of tcp connections to worker threads

0.2.0 (2020-03-10)

  • Added some Python tests (using py.test and tox)

  • Improve handling of HTTP headers

  • Respect content length header when using sendfile

0.1.0 (2020-02-10)

  • Initial release

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

pyruvate-0.5.2.tar.gz (62.9 kB view details)

Uploaded Source

Built Distributions

pyruvate-0.5.2-cp38-cp38-manylinux1_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.8

pyruvate-0.5.2-cp37-cp37m-manylinux1_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.7m

pyruvate-0.5.2-cp36-cp36m-manylinux1_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.6m

File details

Details for the file pyruvate-0.5.2.tar.gz.

File metadata

  • Download URL: pyruvate-0.5.2.tar.gz
  • Upload date:
  • Size: 62.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for pyruvate-0.5.2.tar.gz
Algorithm Hash digest
SHA256 3219d9ef106e12a618fc758c2842ef810d6e50800ebe07548d093600082acf43
MD5 b5c013658ff4954280222e70d6efb52d
BLAKE2b-256 3911f50098c146c623c78528cc3dd0afe6f4f7d978bda8af6438e0dea647d412

See more details on using hashes here.

File details

Details for the file pyruvate-0.5.2-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyruvate-0.5.2-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 4.5 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for pyruvate-0.5.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6101705bf40861e2daf1108b12e73644d2bc4b9ffea2b1f5b852c37e9b072a12
MD5 effe5108c279c2b841630a4d5878dfc4
BLAKE2b-256 6460b7d75dd752f730f169a5feac6a7449b0c25a7fb863ac0235968d0ff85c0f

See more details on using hashes here.

File details

Details for the file pyruvate-0.5.2-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyruvate-0.5.2-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for pyruvate-0.5.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cd0607400ada0fa927ddf7f5cfff12af87b561a7b2142a45711d7893c58be273
MD5 59942b4b13255030d4932cf408376dbb
BLAKE2b-256 83d035f9033ac19850aeef1180fb98e28cf7e88f38d60f15e0a028b87ddf9100

See more details on using hashes here.

File details

Details for the file pyruvate-0.5.2-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyruvate-0.5.2-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for pyruvate-0.5.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f35db94b631b9bdbcc4001e1f323e760866e4b12a435255452de4391b3a37aeb
MD5 ed599c73a8a489dac8d785f449ab86d6
BLAKE2b-256 717e80fabc93a5fe3454192a2c32df399567ca0f94a6f1640e0b072b564105fa

See more details on using hashes here.

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