Skip to main content

WSGI HTTP Server for UNIX

Project description

About

Gunicorn ‘Green Unicorn’ is a Python WSGI HTTP Server for UNIX. It’s a pre-fork worker model ported from Ruby’s Unicorn project. The Gunicorn server is broadly compatible with various web frameworks, simply implemented, light on server resource usage, and fairly speedy.

Feel free to join us in #gunicorn on freenode.

Build Status

Documentation

http://docs.gunicorn.org

Installation

Gunicorn requires Python 2.x >= 2.6 or Python 3.x >= 3.1.

Install from sources:

$ python setup.py install

Or from Pypi:

$ pip install -U gunicorn

You may also want to install Eventlet or Gevent if you expect that your application code may need to pause for extended periods of time during request processing. If you’re on Python 3 you may also consider one othe Asyncio workers. Check out the FAQ for more information on when you’ll want to consider one of the alternate worker types.

To install eventlet:

$ pip install -U eventlet

If you encounter errors when compiling the extensions for Eventlet or Gevent you most likely need to install a newer version of libev or libevent.

Basic Usage

After installing Gunicorn you will have access to the command line script gunicorn.

Commonly Used Arguments

  • -c CONFIG, --config=CONFIG - Specify the path to a config file or python module.

  • -b BIND, --bind=BIND - Specify a server socket to bind. Server sockets can be any of $(HOST), $(HOST):$(PORT), or unix:$(PATH). An IP is a valid $(HOST).

  • -w WORKERS, --workers=WORKERS - The number of worker processes. This number should generally be between 2-4 workers per core in the server. Check the FAQ for ideas on tuning this parameter.

  • -k WORKERCLASS, --worker-class=WORKERCLASS - The type of worker process to run. You’ll definitely want to read the production page for the implications of this parameter. You can set this to egg:gunicorn#$(NAME) where $(NAME) is one of sync, eventlet, gevent, or tornado, gthread, gaiohttp`. ``sync is the default.

  • -n APP_NAME, --name=APP_NAME - If setproctitle is installed you can adjust the name of Gunicorn process as they appear in the process system table (which affects tools like ps and top).

    sync=gunicorn.workers.sync:SyncWorker eventlet=gunicorn.workers.geventlet:EventletWorker gevent=gunicorn.workers.ggevent:GeventWorker tornado

There are various other parameters that affect user privileges, logging, etc. You can see the complete list with the expected:

$ gunicorn -h

gunicorn

The first and most basic script is used to serve ‘bare’ WSGI applications that don’t require a translation layer. Basic usage:

$ gunicorn [OPTIONS] APP_MODULE

Where APP_MODULE is of the pattern $(MODULE_NAME):$(VARIABLE_NAME). The module name can be a full dotted path. The variable name refers to a WSGI callable that should be found in the specified module.

Example with test app:

$ cd examples
$ gunicorn --workers=2 test:app

Integration

We also provide integration for both Django and Paster applications.

Django

gunicorn just needs to be called with a the location of a WSGI application object.:

gunicorn [OPTIONS] APP_MODULE

Where APP_MODULE is of the pattern MODULE_NAME:VARIABLE_NAME. The module name should be a full dotted path. The variable name refers to a WSGI callable that should be found in the specified module.

So for a typical Django project, invoking gunicorn would look like:

gunicorn myproject.wsgi:application

(This requires that your project be on the Python path; the simplest way to ensure that is to run this command from the same directory as your manage.py file.)

You can use the –env option to set the path to load the settings. In case you need it you can also add your application path to PYTHONPATH using the –pythonpath option.

Paste

If you are a user/developer of a paste-compatible framework/app (as Pyramid, Pylons and Turbogears) you can use the gunicorn –paste option to run your application.

For example:

gunicorn –paste development.ini -b :8080 –chdir /path/to/project

It is all here. No configuration files nor additional python modules to write !!

Instrumentation

Gunicorn provides an optional instrumentation of the arbiter and workers using the statsD protocol over UDP. Thanks to the gunicorn.instrument.statsd module, Gunicorn becomes a statsD client The use of UDP cleanly isolates Gunicorn from the receiving end of the statsD metrics so that instrumentation does not cause Gunicorn to be heldeup by a slow statsD consumer.

To use statsD, just tell gunicorn where the statsD server is:

$ gunicorn –statsd-host=localhost:8125 …

The Statsd logger overrides gunicorn.glogging.Logger to track all requests. The following metrics are generated:

  • gunicorn.requests: request rate per second

  • gunicorn.request.duration: histogram of request duration (in millisecond)

  • gunicorn.workers: number of workers managed by the arbiter (gauge)

  • gunicorn.log.critical: rate of critical log messages

  • gunicorn.log.error: rate of error log messages

  • gunicorn.log.warning: rate of warning log messages

  • gunicorn.log.exception: rate of exceptional log messages

To generate new metrics you can log.info with a few additional keywords:

log.info("...", extra={"metric": "my.metric", "value": "1.2", "mtype": "gauge"})

LICENSE

Gunicorn is released under the MIT License. See the LICENSE file for more 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

gunicorn-19.1.1.tar.gz (385.2 kB view details)

Uploaded Source

Built Distribution

gunicorn-19.1.1-py2.py3-none-any.whl (104.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file gunicorn-19.1.1.tar.gz.

File metadata

  • Download URL: gunicorn-19.1.1.tar.gz
  • Upload date:
  • Size: 385.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for gunicorn-19.1.1.tar.gz
Algorithm Hash digest
SHA256 82715511fb6246fad4ba66d812eb93416ae8371b464fa88bf3867c9c177daa14
MD5 eaa72bff5341c05169b76ce3dcbb8140
BLAKE2b-256 dfaec2cdd886a282df6eeaca90f8719d23eda51e4945ce55556e00b25f4acd2c

See more details on using hashes here.

File details

Details for the file gunicorn-19.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for gunicorn-19.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ffb411757de374d05c759c929908d2397c66e3bcf6f35dee41a6ef9eb851497b
MD5 905b2a090447c82bd66e62ee29b2287c
BLAKE2b-256 eee2dbe1f12d527b060bc0340b9df47926b9c80d54bca13482b5611d41773e26

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