Skip to main content

django-command-center

Run Django management commands from the admin - without SSH.

  • Every command, found automatically. Your project's commands and Django's own appear by themselves; you decide which ones, in settings or in the command's code.
  • Runs in the background, in its own process. A command that crashes, leaks memory or hangs cannot take your worker down.
  • Live output. Watch it as it prints; download the full log afterwards.
  • Cancel and time limits that work. The process is stopped, children and all.
  • History. Who ran what, with which arguments, when, for how long, and how it ended.
  • Permissions. Running and cancelling are model permissions; a command can require one more of its own.

Background runs go through django.tasks (Django 6.0+) or the django-tasks backport, or are queued for manage.py command_center_worker.

Install

pip install django-command-center            # Django 6.0+
pip install "django-command-center[tasks]"   # Django 5.2, with background runs
INSTALLED_APPS = [..., "command_center"]
python manage.py migrate command_center

Then open Command center > Command runs > Run a command in the admin.

Choose the commands

Every installed command is offered except the defaults in EXCLUDE: servers, shells, interactive commands, code generators, and flush.

from command_center.conf import DEFAULT_EXCLUDE

COMMAND_CENTER = {
    # Only these (fnmatch patterns). None offers everything not excluded.
    "INCLUDE": None,
    # Never offered - extend the defaults rather than replace them.
    "EXCLUDE": [*DEFAULT_EXCLUDE, "send_newsletter"],
    # Extra groups on the run page, besides one per app.
    "TAGS": {"Reports": ["check", "showmigrations", "report_*"]},
    # Per command. Naming an excluded command here offers it anyway.
    "COMMANDS": {
        "migrate": {"confirm": "Applies migrations to this database.", "timeout": 600},
        "clearsessions": {"tags": ["Maintenance"]},
        "rebuild_index": {"permission": "search.change_index", "timeout": 7200},
    },
}

Or describe a command where it is written; settings override it:

class Command(BaseCommand):
    command_center = {"tags": ["Reports"], "timeout": 120}

    # or keep it out of the admin entirely:
    # command_center = False
Option
confirm A warning the user must accept before it runs
timeout Seconds before it is stopped (default TIMEOUT, 3600)
permission "app_label.codename" needed to see and run it
tags Groups it appears under
description Replaces the command's help on the run page

Settings

Setting Default
TIMEOUT 3600 Default time limit in seconds
STORAGE "default" Alias in STORAGES full logs are saved to
LOCATION "command_center/" Folder within that storage
LOG_TAIL_CHARS 20000 Output kept on the run for the live view
HEARTBEAT_SECONDS 2 How often a run reports progress
LOST_AFTER_SECONDS 120 Silence after which a run counts as lost
RETENTION_DAYS 90 Used by command_center_prune
RUNNER auto "tasks" or "worker"
TASK_BACKEND "default" Task backend alias for "tasks"

Permissions

  • command_center.add_commandrun - run commands
  • command_center.cancel_commandrun - cancel runs
  • command_center.view_commandrun - see the history and logs
  • plus any permission a command declares

How a command runs

Each run starts python -m django <command> <arguments> with the same settings module and import path as the worker. Its standard input is closed: a command that asks a question fails at once instead of waiting forever, so pass --no-input where a command supports it. Output is read line by line; every HEARTBEAT_SECONDS the run's page gets the latest of it, and a cancel or an expired time limit stops the process group with SIGTERM, then SIGKILL. A run whose worker dies is marked lost after LOST_AFTER_SECONDS.

Without a task framework

COMMAND_CENTER = {"RUNNER": "worker"}
python manage.py command_center_worker          # keeps polling
python manage.py command_center_worker --once   # from cron

Housekeeping

python manage.py command_center_prune   # deletes runs older than RETENTION_DAYS

Development

python runtests.py

License

BSD-3-Clause.

Metadata

Release files for django-command-center 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-command-center 0.1.0
File Size Uploaded Provenance Actions
django_command_center-0.1.0.tar.gz 21.5 kB Without provenance Details for django_command_center-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-command-center 0.1.0
File Interpreter ABI Platform Actions
django_command_center-0.1.0-py3-none-any.whl Python 3 none any Details for django_command_center-0.1.0-py3-none-any.whl

Total release size: 43.0 kB

Release files / django_command_center-0.1.0.tar.gz

Download URL django_command_center-0.1.0.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f2b8b65f776ef9ee3373dad2bad9a0879fdffa3273e212901a2cd134aea2f7ef
BLAKE2b-256 checksum
How to use checksums
e44218db00c0419d2e3a81da5a4879389dfe97ba076cb5905d8e0cee7815e35b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / django_command_center-0.1.0-py3-none-any.whl

Download URL django_command_center-0.1.0-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
521720577cbc9edaaa8acf1cfd0e965041c3cbe2151fc144a9748edca166978b
BLAKE2b-256 checksum
How to use checksums
18d6f8db8ccde6fa22e47ca6b37c9b316b790f9788aae9f2b7c779c41b6dd986
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for django-command-center 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page