Metadata-Version: 2.4
Name: django-prodserver
Version: 3.0.0
Summary: A management command to start production servers/workers with a consistent interface
Author-email: Andy Miller <info@akmiller.co.uk>
License: MIT
Project-URL: Bug Tracker, https://github.com/nanorepublica/django-prodserver/issues
Project-URL: Changelog, https://github.com/nanorepublica/django-prodserver/blob/main/CHANGELOG.md
Project-URL: documentation, https://django-prodserver.readthedocs.io
Project-URL: repository, https://github.com/nanorepublica/django-prodserver
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Framework :: Django
Classifier: Framework :: Django :: 5.2
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: django>=4.2
Provides-Extra: gunicorn
Requires-Dist: gunicorn>=23.0.0; extra == "gunicorn"
Provides-Extra: django-tasks
Requires-Dist: django-tasks>=0.7.0; extra == "django-tasks"
Provides-Extra: celery
Requires-Dist: celery>=5.5.2; extra == "celery"
Provides-Extra: flower
Requires-Dist: flower>=2.0; extra == "flower"
Requires-Dist: celery>=5.5.2; extra == "flower"
Provides-Extra: django-q2
Requires-Dist: django-q2>=1.6.0; extra == "django-q2"
Requires-Dist: django-picklefield; extra == "django-q2"
Provides-Extra: granian
Requires-Dist: granian>=1.0.0; extra == "granian"
Provides-Extra: uvicorn
Requires-Dist: uvicorn>=0.34.2; extra == "uvicorn"
Provides-Extra: waitress
Requires-Dist: waitress>=3.0.2; extra == "waitress"
Provides-Extra: daphne
Requires-Dist: daphne>=4.0; extra == "daphne"
Provides-Extra: werkzeug
Requires-Dist: werkzeug>=3.0; extra == "werkzeug"
Provides-Extra: runserver-plus
Requires-Dist: werkzeug>=3.0; extra == "runserver-plus"
Requires-Dist: pyOpenSSL; extra == "runserver-plus"
Requires-Dist: sqlparse; extra == "runserver-plus"
Requires-Dist: pygments; extra == "runserver-plus"
Dynamic: license-file

# Django prodserver

<p align="center">
  <a href="https://github.com/nanorepublica/django-prodserver/actions/workflows/ci.yml?query=branch%3Amain">
    <img src="https://img.shields.io/github/actions/workflow/status/nanorepublica/django-prodserver/ci.yml?branch=main&label=CI&logo=github&style=flat-square" alt="CI Status" >
  </a>
  <a href="https://django-prodserver.readthedocs.io">
    <img src="https://img.shields.io/readthedocs/django-prodserver.svg?logo=read-the-docs&logoColor=fff&style=flat-square" alt="Documentation Status">
  </a>
  <a href="https://codecov.io/gh/nanorepublica/django-prodserver">
    <img src="https://img.shields.io/codecov/c/github/nanorepublica/django-prodserver.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">
  </a>
</p>
<p align="center">
  <a href="https://github.com/astral-sh/uv">
    <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" alt="uv">
  </a>
  <a href="https://github.com/astral-sh/ruff">
    <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff">
  </a>
  <a href="https://github.com/pre-commit/pre-commit">
    <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">
  </a>
</p>
<p align="center">
  <a href="https://pypi.org/project/django-prodserver/">
    <img src="https://img.shields.io/pypi/v/django-prodserver.svg?logo=python&logoColor=fff&style=flat-square" alt="PyPI Version">
  </a>
  <img src="https://img.shields.io/pypi/pyversions/django-prodserver.svg?style=flat-square&logo=python&amp;logoColor=fff" alt="Supported Python versions">
  <img src="https://img.shields.io/pypi/l/django-prodserver.svg?style=flat-square" alt="License">
</p>

---

**Documentation**: <a href="https://django-prodserver.readthedocs.io" target="_blank">https://django-prodserver.readthedocs.io </a>

**Source Code**: <a href="https://github.com/nanorepublica/django-prodserver" target="_blank">https://github.com/nanorepublica/django-prodserver </a>

---

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`:

```python
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.

```py
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:

```sh
python manage.py server web
```

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

```sh
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](https://allcontributors.org/docs/en/emoji-key)):

<!-- prettier-ignore-start -->
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- markdownlint-disable -->
<!-- markdownlint-enable -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
<!-- prettier-ignore-end -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

## Credits

[![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json)](https://github.com/copier-org/copier)

This package was created with
[Copier](https://copier.readthedocs.io/) and the
[browniebroke/pypackage-template](https://github.com/browniebroke/pypackage-template)
project template.
