Skip to main content

django-usermgmt

logo

logo

A production-oriented command line toolkit for managing users, groups and permissions in any Django project.

Stock manage.py only ships createsuperuser and changepassword. There is no built-in way to create a regular user, list users, inspect permissions, manage groups or import accounts in bulk. django-usermgmt adds a single management command, usermgr, that covers all of that, with safety guards, audit logging and scriptable output.

python manage.py usermgr create-user john --email john@example.com --group editors --create-missing-groups
python manage.py usermgr list-users --active --format json
python manage.py usermgr who-can blog.add_post

Highlights

  • 26 actions across users, permissions, groups and bulk import/export.
  • Custom user model support: the login field is read from USERNAME_FIELD; extra fields via --field KEY=VALUE.
  • Safe password handling: interactive prompt, stdin or environment variable; validated against AUTH_PASSWORD_VALIDATORS; never logged.
  • Safety guards: the last active superuser cannot be deleted, deactivated or demoted without --force; destructive actions ask for confirmation.
  • Atomic and auditable: every mutation runs in a transaction and writes a line to the usermgmt.audit logger.
  • Automation friendly: table, json and csv output, stable exit codes, no prompts when stdin is not a TTY.
  • Layered design: all logic lives in usermgmt.services; the command is a thin CLI wrapper you can bypass.

Requirements

Component Version
Python 3.9 or newer
Django 4.2 or newer

No third-party dependencies.

Installation

  1. pip install django-usermgmt or Copy the usermgmt/ directory into your project, next to manage.py.

  2. Add it to INSTALLED_APPS:

    INSTALLED_APPS = [
        # ...
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "usermgmt",
    ]
    
  3. Verify:

    python manage.py usermgr -h
    

See examples/settings_snippet.py for an audit-log configuration.

Quick tour

# Create users
python manage.py usermgr create-user john --email john@example.com          # prompts for a password
echo "$PW" | python manage.py usermgr create-user sari --password-stdin
python manage.py usermgr create-user svc-sso --no-password                   # unusable password (SSO / API only)
python manage.py usermgr create-user ops --staff --group operators --create-missing-groups

# Inspect
python manage.py usermgr list-users --active --stale-days 90 --format csv
python manage.py usermgr show-user john --all-perms
python manage.py usermgr check-user john --perm auth.view_user

# Permissions and groups
python manage.py usermgr create-group editors --perm blog.add_post --perm blog.change_post
python manage.py usermgr add-to-group john editors
python manage.py usermgr grant-perm john "reports.*"
python manage.py usermgr who-can blog.add_post

# Lifecycle
python manage.py usermgr set-password john --revoke-sessions
python manage.py usermgr deactivate john --revoke-sessions

# Bulk
python manage.py usermgr import-users examples/users.csv --dry-run
python manage.py usermgr export-users --format csv --output users.csv

Action overview

mindmap
  root((usermgr))
    Users
      create-user
      list-users
      show-user
      check-user
      update-user
      set-password
      set-flags
      activate
      deactivate
      delete-user
      revoke-sessions
    Permissions
      grant-perm
      revoke-perm
      list-perms
      who-can
    Groups
      create-group
      delete-group
      rename-group
      list-groups
      show-group
      group-grant
      group-revoke
      add-to-group
      remove-from-group
    Bulk
      import-users
      export-users

Action overview

How it fits together

flowchart LR
    Admin["Operator / script / CI"] -->|"manage.py usermgr ..."| CLI["usermgr command<br/>(argparse, output, prompts)"]
    CLI --> SVC["usermgmt.services<br/>(business logic)"]
    Py["Your Python code<br/>(Celery, shell, tests)"] --> SVC
    SVC --> ORM["Django ORM<br/>auth.User / Group / Permission"]
    SVC --> LOG["usermgmt.audit logger"]
    ORM --> DB[("Database")]

How it fits together

Documentation

Document Purpose
User guide Task-oriented walkthroughs and recipes
Command reference Every action, argument, output and exit code
Architecture Design, data model and flow diagrams
Security guide Threat model, password handling, audit logging, hardening checklist
Developer guide Using the service layer, extending the command, running tests
Troubleshooting Common errors and fixes
Changelog Release history

Running the tests

python manage.py test usermgmt

Known limitations

  • Operates on the default database connection only (no --database option yet).
  • revoke-sessions supports database-backed sessions (django.contrib.sessions) only.
  • who-can evaluates permissions the way Django's ModelBackend does (superuser, direct, via group). Custom authentication backends with their own permission logic are not consulted.
  • Passwords in import files are plain text; protect and delete those files (see the security guide).

for cli's color, install pip install rchf

👤 Author

Hadi Cahyadi

Buy Me a Coffee

Donate via Ko-fi

Support me on Patreon

Metadata

Release files for django-usermgmt 1.0.7

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-usermgmt 1.0.7
File Size Uploaded Provenance Actions
django_usermgmt-1.0.7.tar.gz 39.4 kB With provenance Details for django_usermgmt-1.0.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-usermgmt 1.0.7
File Interpreter ABI Platform Actions
django_usermgmt-1.0.7-py3-none-any.whl Python 3 none any Details for django_usermgmt-1.0.7-py3-none-any.whl

Total release size: 61.5 kB

Release files / django_usermgmt-1.0.7.tar.gz

Download URL django_usermgmt-1.0.7.tar.gz
Size 39.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0c51d1de3c618fc8e06ca9cb60155be635c0c90ca411375a2adc64188a67cc2e
BLAKE2b-256 checksum
How to use checksums
ecf174518e3d4f61a6d54b319ea53948a1f7e9c5f356179b89496486d0522c20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / django_usermgmt-1.0.7-py3-none-any.whl

Download URL django_usermgmt-1.0.7-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c8527923977ecc839e213914283981c271560342c8a55fab4b96602bf034522
BLAKE2b-256 checksum
How to use checksums
77c9c5a16c776a9b7c51e32dea0ecabb8cc52c1195945957ce13b1470ad043c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for django-usermgmt 1.0.7

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_usermgmt-1.0.7.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

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

1.0.7 This release

2 release files Full 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