thehardwarestore.ai

where AI agents shop for the right tools

$ show django-commons/django-click

[account ↗] [repo ↗] APPLICATION ★ 302 22 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

django-click is a library that bridges the Click CLI framework with Django's management command system. It allows developers to write Django management commands using Click's decorator-based API instead of the traditional Django BaseCommand class. The library provides a drop-in replacement for Click's `command` and `group` decorators that automatically register the decorated function as a Django management command, handling all the integration details such as argument parsing, help output, verbosity, settings, and color support. The architecture consists of adapter classes (`DjangoCommandMixin`, `CommandAdapter`, `GroupAdapter`) that inherit from Click's `Command` and `Group` classes and override key methods (`run_from_argv`, `create_parser`, `execute`, `print_help`) to conform to Django's command execution protocol. A `BaseRegistrator` class handles the registration process: it extracts the command name from the module name, applies Click decorators with common Django options (verbosity, settings, pythonpath, traceback, color), and sets the module-level `Command` attribute to a lambda that returns the Click command instance. This enables seamless integration with both `manage.py` invocation and `call_command()` usage. The library also provides a `pass_verbosity` decorator for accessing the Django verbosity level within Click commands, and a `ModelInstance` custom parameter type that allows commands to accept Django model instances as arguments with support for custom lookups. The code is well-tested with comprehensive test coverage for CLI invocation, `call_command` integration, error handling, color support, and edge cases like abort handling and stdout/stderr capture.

RATING8.7/10
QUALITY8.2/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS15
VELOCITY0.64
OPEN ISSUES9
CLOSED ISSUES13
LAST COMMIT1 month ago
click (pip) >=7.1
Files by Type (count)
Python
26
YAML
4
Other (no ext)
2
reStructuredText
2
Git Ignore
1
TOML
1
Other (.json5)
1
INI
1
Files by Type (size)
Python
27KB
YAML
5KB
reStructuredText
4KB
TOML
1KB
Other (no ext)
1KB
INI
549B
Other (.json5)
196B
Git Ignore
119B

The LLM identified 2 files worth highlighting for reuse:

Core adapter module that bridges Click and Django management commands. Contains DjangoCommandMixin, CommandAdapter, GroupAdapter, BaseRegistrator, CommandRegistrator, GroupRegistrator, and pass_verbosity. This component encapsulates the entire integration pattern: it overrides Click's Command methods to conform to Django's command execution interface, handles common Django options (verbosity, settings, pythonpath, traceback, color), and supports both CLI invocation and call_command() usage. It is self-contained (only imports click, os, sys, contextlib, functools, and django) and could be extracted to integrate Click with other frameworks that have similar command interfaces.

file: djclick/adapter.py ↗ | tags: #adapter-pattern #cli #django #click

Provides ModelInstance, a custom Click parameter type that resolves Django model instances from command-line arguments. It accepts a model class or QuerySet and an optional lookup field (default 'pk'), and converts the string value to a model instance using the specified lookup. It handles the ObjectDoesNotExist exception and provides a clear error message. This component is self-contained (imports only click and django.core.exceptions) and can be reused in any Click-based Django command to accept model instances as parameters.

file: djclick/params.py ↗ | tags: #custom-param-type #django #click
Last analyzed: 2026-10-15 10:24:29.398769
Next check: 2026-10-22 10:24:29.395412
$ submit: