Skip to main content

A management command to start production servers/workers with a consistent interface

Project description

Django prodserver

CI Status Documentation Status Test coverage percentage

uv Ruff pre-commit

PyPI Version Supported Python versions License


Documentation: https://django-prodserver.readthedocs.io

Source Code: https://github.com/nanorepublica/django-prodserver


A management command to start production servers/workers with a consistent interface

Installation

Install this via pip (or your favourite package manager):

pip install django-prodserver

Add the app to your INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    "django_prodserver",
]

Configuration

Add the PRODUCTION_PROCESSES setting to your settings.py. Below shows an example with a web process and worker process defined.

The comments show other available backend processes that are available to use.

PRODUCTION_PROCESSES = {
    "web": {
        "BACKEND": "django_prodserver.backends.servers.gunicorn.GunicornServer",
        "ARGS": {"bind": "0.0.0.0:8111"},
    },
    # "web": {
    #     "BACKEND": "django_prodserver.backends.servers.granian.GranianASGIServer",
    #     "ARGS": {"address": "0.0.0.0", "port": "8000", "workers": "4"},
    # },
    # "web": {
    #     "BACKEND": "django_prodserver.backends.servers.granian.GranianWSGIServer",
    #     "ARGS": {"address": "0.0.0.0", "port": "8000", "workers": "4"},
    # },
    # "web": {
    #     "BACKEND": "django_prodserver.backends.servers.waitress.WaitressServer",
    #     "ARGS": {},
    # },
    # "web": {
    #     "BACKEND": "django_prodserver.backends.servers.uvicorn.UvicornServer",
    #     "ARGS": {},
    # },
    # "web": {
    #     "BACKEND": "django_prodserver.backends.servers.uvicorn.UvicornWSGIServer",
    #     "ARGS": {},
    # },
    "worker": {
        "BACKEND": "django_prodserver.backends.workers.celery.CeleryWorker",
        "APP": "tests.celery.app",
        "ARGS": {},
    },
    # "worker": {
    #     "BACKEND": "django_prodserver.backends.workers.django_tasks.DjangoTasksWorker",
    #     "ARGS": {},
    # },
    # "beat": {
    #     "BACKEND": "django_prodserver.backends.workers.celery.CeleryBeat",
    #     "APP": "tests.celery.app",
    #     "ARGS": {},
    # },
    # "flower": {
    #     "BACKEND": "django_prodserver.backends.servers.flower.CeleryFlower",
    #     "APP": "tests.celery.app",
    #     "ARGS": {"port": "5555", "address": "0.0.0.0"},
    # },
}

Usage

Once the PRODUCTION_PROCESSES setting has been configured you can then start the processes.

Use the server command to start a web/ASGI/WSGI process:

python manage.py server web

Use the worker command to start a background task worker process:

python manage.py worker worker

Both commands read from the same PRODUCTION_PROCESSES setting; server only accepts server backends and worker only accepts worker backends. If you point one at the wrong kind of backend it will tell you which command to use instead. Run either command with --list to see the configured process names.

Deprecated: python manage.py prodserver continues to work as an alias but is deprecated and will be removed in django-prodserver 4.0.0. Use python manage.py server instead.

Creating a new backend.

Creating a backend is fairly simple. Subclass BaseServerBackend (for a web server) or BaseWorkerBackend (for a background task worker) from django_prodserver.backends.base, then implement the start_server method which should call the underlying process in the best possible way for a production setting. You can also optionally override the prep_server_args method to aid with this to provide any default arguments or formatting to the start_server command.

See django_prodserver.backends.servers (production server backends), django_prodserver.backends.workers (worker backends), and django_prodserver.backends.dev (development runserver-style backends) for examples of existing backends for inspiration. Pull Request's are welcome for additional backends.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

Credits

Copier

This package was created with Copier and the browniebroke/pypackage-template project template.

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_prodserver-3.0.0.tar.gz (36.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_prodserver-3.0.0-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

Details for the file django_prodserver-3.0.0.tar.gz.

File metadata

  • Download URL: django_prodserver-3.0.0.tar.gz
  • Upload date:
  • Size: 36.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_prodserver-3.0.0.tar.gz
Algorithm Hash digest
SHA256 5e23ccd7338c26f2da203172b8ad2905ed4f2ae6b8f63b0e26c415dc5f9b2cfa
MD5 d6d5cb76924275790e22846242471c14
BLAKE2b-256 e967732369cba62af180f224f20bf7ec02e95ad596b4e32d88eb6a8d2c67f312

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_prodserver-3.0.0.tar.gz:

Publisher: ci.yml on nanorepublica/django-prodserver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_prodserver-3.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_prodserver-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00a8173b58c639d24733c397ff49153c6bde32f375834254f82b20651be21ed8
MD5 58ef5ae0e61b534dac550ff1efabb79e
BLAKE2b-256 57c2141a7c3a067571f1c759925e8fb630f5fe3ad63814b5de5f703fcdaa7fdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_prodserver-3.0.0-py3-none-any.whl:

Publisher: ci.yml on nanorepublica/django-prodserver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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