django-shell-extended
Provides a sh management-command that can be customized via django settings.
Quick start
- Install with
pip install django-shell-extended - Add
"django_shell_extended"to yourINSTALLED_APPSsetting like this:INSTALLED_APPS = [ # ... "django_shell_extended", ]
- (Optional) Change the settings described in the next section in your
settings.py - Start the shell via
python manage.py sh
Available settings
# The Path to a custom ipython directory.
# default: None
DJANGO_SH_IPYTHON_DIR = "/some/path/.ipython/"
# Tries to autodetect django apps with models and imports them as `from my_app.models import *`
# default: True
DJANGO_SH_AUTO_IMPORT_MODELS = True
# Defines additional modules that should be imported.
# Should be a tuple or list containing entries like `(module, imports)`.
# default: ()
DJANGO_SH_IMPORT_MODULES = (
('datetime', ('datetime', 'timedelta')), # -> from datetime import datetime, timedelta
('re', None), # -> import re
('decimal', 'Decimal'), # -> from decimal import Decimal
('foo.bar', '*') # -> from foo.bar import *
)
# A function that adds command line arguments to the `sh` command.
# default: None
def DJANGO_SH_HOOK_ADD_ARGUMENTS(parser: CommandParser) -> None:
parser.add_argument(...)
# A function that is called after importing models and modules.
# Can be used to further extend the `imported_objects` name space or to check command arguments. Example::
# default: None
def DJANGO_SH_HOOK_GET_IMPORTED_OBJECTS(imported_objects: dict, options: dict) -> None:
multiplier = int(options.get('multiplier', 0))
imported_objects['multiply'] = lambda x: x * multiplier
# Can be used to alter the command provided to `python manage.py sh -c '<command>'`
# default: None
def DJANGO_SH_HOOK_MODIFY_COMMAND(command: str) -> str:
return f'start=time.time()\\n{command}\\nprint("Command took", time.time() - start, "seconds")'
Metadata
Release files for django-shell-extended 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_shell_extended-1.0.0.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_shell_extended-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.8 kB
Release files / django_shell_extended-1.0.0.tar.gz
| Download URL | django_shell_extended-1.0.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
733f0936f6f332c32f3d7f48523e7210dcf4c3967fe0350628899077131bd619
|
|
BLAKE2b-256 checksum How to use checksums |
a527f1e5833dab288c7088b10b87de4910ce8a462703caa25d1d4b6ee0535452
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Release files / django_shell_extended-1.0.0-py3-none-any.whl
| Download URL | django_shell_extended-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b3fa6f1231badcbd9581c9089e0c77d64e24a8db8e17142e5f3a356fc28d3eb1
|
|
BLAKE2b-256 checksum How to use checksums |
eac6d2c42427461a5c6a7f522ed13b8e93f2e5ca37a33711d397f6ee2667459e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|