Skip to main content

uWSGI as a Django management command

Project description

django-pyuwsgi

Run pyuwsgi (aka uWSGI) as a Django management command.


build status pypi pyversions

Usage

  1. Install:

    pip install django-pyuwsgi
    
  2. Add to INSTALLED_APPS:

    INSTALLED_APPS = [
       # ...
       "django_pyuwsgi",
       # ...
    ]
    
  3. Run:

    manage.py pyuwsgi --socket=:8000 ...
    

Configuration

Pyuwsgi already knows the Python interpreter and virtualenv (if applicable) to use from the Django management command environment. By default, it will run with the following flags (using settings.WSGI_APPLICATION to determine the module):

--strict --need-app --module={derived}

If you have STATIC_URL defined with a local URL, it will also add --static-map, derived from STATIC_URL and STATIC_ROOT.

You can pass any additional arguments uWSGI accepts in from the command line.

But uWSGI has a lot of flags, and many of them, you want every time you run the project. For that scenario, you can configure your own defaults using the optional setting, PYUWSGI_ARGS. Here's an example you might find helpful:

PYUWSGI_ARGS = [
    "--master",
    "--strict",
    "--need-app",
    "--module".
    ":".join(WSGI_APPLICATION.rsplit(".", 1)),
    "--no-orphans",
    "--vacuum",
    "--auto-procname",
    "--enable-threads",
    "--offload-threads=4",
    "--thunder-lock",
    "--static-map",
    "=".join([STATIC_URL.rstrip("/"), STATIC_ROOT]),
    "--static-expires",
    "/* 7776000",
]

Don't forget to also set something like --socket=:8000 or --http=:8000 so your app listens on a port. Depending on your setup, it may make more sense to pass this in via the command line than hard-coding it in your settings.

Motivation

In some scenarios, it is beneficial to distribute a Django project with a single entrypoint for command-line interaction. This can come in handy when building Docker containers or self-contained Python apps with something like shiv.

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

django-pyuwsgi-1.1.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

django_pyuwsgi-1.1.1-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-pyuwsgi-1.1.1.tar.gz.

File metadata

  • Download URL: django-pyuwsgi-1.1.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.0

File hashes

Hashes for django-pyuwsgi-1.1.1.tar.gz
Algorithm Hash digest
SHA256 ae83b8b7caf85b299b56a6100a5a3ba3758a6d91604dbb9cedc1e7f46b21dd3e
MD5 dddd97c8777fb407e0acc498fb09d02a
BLAKE2b-256 a74bbd750b825d455e031b3e025134c86bb1d59172bfe796d94a0ad41fe19c1b

See more details on using hashes here.

File details

Details for the file django_pyuwsgi-1.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: django_pyuwsgi-1.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.0

File hashes

Hashes for django_pyuwsgi-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8a4413bb6f12dc5ba8031a9151f2eec5a8f77756e7ea0fb593c53b00d7a9f49e
MD5 2a8321529e0b5f7f19e2dc7433de9cda
BLAKE2b-256 bab1bd98df4d2ce93b6ac22515a79aaf2f746015e0266227ca76bc09f1971fa0

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