Skip to main content

Run, schedule, and audit Django management commands without SSH access

Project description

managecommand

Python client for ManageCommand - run, schedule, and audit Django management commands without SSH access.

Installation

pip install managecommand

Quick Start

  1. Add to your INSTALLED_APPS:
INSTALLED_APPS = [
    # ...
    'managecommand',
]
  1. Add your API key to settings.py:
MANAGECOMMAND_API_KEY = "dc_your_api_key_here"
  1. Start the runner:
python manage.py managecommand start

The runner will connect to ManageCommand, sync your available commands, and start polling for executions.

Configuration

API key

Your project's API key (get this from the ManageCommand dashboard)

MANAGECOMMAND_API_KEY = "dc_..."

Enabled (allowed) commands

Enable additional commands:

import managecommand
MANAGECOMMAND_ALLOWED_COMMANDS = tuple(
    *managecommand.DEFAULT_ALLOWED_COMMANDS,
    "my_custom_command",
    "another_command",
)

Or explicitly allow only specific commands (skip the default ones):

MANAGECOMMAND_ALLOWED_COMMANDS = (
    "my_custom_command",
    "another_command",
)

Order does not matter.

By default, only commands in DEFAULT_ALLOWED_COMMANDS can be executed remotely:

Default value:

DEFAULT_ALLOWED_COMMANDS = (
    # Database
    "migrate", "showmigrations", "dbbackup", "createcachetable",
    # Static files
    "collectstatic", "findstatic",
    # Maintenance
    "clearsessions", "check", "sendtestemail", "diffsettings",
    # Data
    "dumpdata", "inspectdb",
    # Testing
    "test",
    # django-extensions
    "show_urls", "validate_templates", "clear_cache",
    # Wagtail
    "fixtree", "publish_scheduled", "update_index",
)

DISCLAIMER: This list is not fully vetted. You are encouraged to only allow commands that you trust and have vetted yourself.

Alternative - Blocklist Mode

Alternative to the "ALLOWED" list is the "DISALLOWED" list.

In this mode all commands are allowed except for the ones in the blocklist.

This mode is inherently less secure because newly added commands are automatically allowed.

CAUTION: Any new commands will by allowed by default in this mode!

MANAGECOMMAND_USE_BLOCKLIST = True

Default value:

DEFAULT_DISALLOWED_COMMANDS = (
    # Database destruction
    "flush", "sqlflush", "reset_db", "dbrestore", "loaddata",
    # Interactive shells
    "shell", "shell_plus", "dbshell",
    # Development servers
    "runserver", "runserver_plus", "testserver",
    # Security sensitive
    "createsuperuser", "changepassword",
    # File modifications
    "makemigrations", "squashmigrations",
)

DISCLAIMER: This list is not exhaustive. You are responsible for ensuring that only safe commands are allowed.

Optional / Advanced Settings

# Server URL (default: https://app.managecommand.com)
MANAGECOMMAND_SERVER_URL = "https://app.managecommand.com"

# Runner heartbeat interval in seconds (default: 30, minimum: 5)
MANAGECOMMAND_HEARTBEAT_INTERVAL = 30

# HTTP request timeout in seconds (default: 30)
MANAGECOMMAND_REQUEST_TIMEOUT = 30

# Max retries for failed requests (default: 3)
MANAGECOMMAND_MAX_RETRIES = 3

# Hosts allowed to use HTTP instead of HTTPS (default: localhost only)
MANAGECOMMAND_ALLOW_HTTP_HOSTS = ['localhost', '127.0.0.1', '::1']

Metadata-Only Mode

For commands that produce sensitive output (credentials, PII) or very high-volume output, you can enable metadata-only mode. In this mode, the command executes normally but stdout/stderr are not captured or stored.

# Commands that always run in metadata-only mode
MANAGECOMMAND_METADATAONLY_COMMANDS = (
    "generate_api_keys",
    "export_user_data",
    "sync_large_dataset",
)

Additionally, the dashboard can also enable metadata-only mode on a per-command basis via the command configuration settings. Either the client setting or the dashboard setting will trigger metadata-only mode.

In metadata-only mode:

  • The command executes normally
  • Exit code and duration are still tracked
  • Output shows: "(metadata-only mode, no output captured)"

Running the Runner

Current architecture supports only 1 runner per project.

Foreground

python manage.py managecommand start

Starts the runner in the foreground. Press Ctrl+C to stop.

This is the recommended option for Kubernetes, systemd, Docker, and similar process managers that handle lifecycle and restarts.

Background (detached)

python manage.py managecommand start -d

Starts the runner in the background.

This is recommended for development and testing only. It can be used in production where other process managers are not available. YMMV.

Managing the Runner

Use these commands to manage a runner.

Works whether the runner is running in the foreground or background.

# Check if the runner is running
python manage.py managecommand status

# Stop the background runner
python manage.py managecommand stop [--force]

# Restart the runner
python manage.py managecommand restart [-d]

License

MIT

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

managecommand-0.1.0.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

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

managecommand-0.1.0-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file managecommand-0.1.0.tar.gz.

File metadata

  • Download URL: managecommand-0.1.0.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for managecommand-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ad208172231a8558d4c8a29a95a856d71c128509189860778dd4a4fb2667b84f
MD5 c88e3e648efe1f69316f142227769bcc
BLAKE2b-256 a245fee8f20ab92273c5c6ad7d41a0d18ac29e2bdb27d386394b311535925c86

See more details on using hashes here.

File details

Details for the file managecommand-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: managecommand-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for managecommand-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e9fb9c42a98545cf18d5828d33d4a5ccc4587652053bdff26aa29fb26092d49
MD5 ce8b30b4a8bf41af7fe4eefaf2cd40ae
BLAKE2b-256 b83b720176c903d169642f8377055386c3c9e66dc1902981bf8a6dd207b303c9

See more details on using hashes here.

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