Skip to main content

An extended Django shell

Project description

django-shell-extended

Provides a sh management-command that can be customized via django settings.

Quick start

  1. Install with pip install django-shell-extended

  2. Add "sh" to your INSTALLED_APPS setting like this::

    INSTALLED_APPS = [
        # ...
        "sh",
    ]
    
  3. Have a look at sh/settings.py for available customizations

  4. Override any of the settings in your project's settings.py, prepending the names with DJANGO_SH_

  5. 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")'

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

django_shell_extended-0.0.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

django_shell_extended-0.0.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file django_shell_extended-0.0.1.tar.gz.

File metadata

  • Download URL: django_shell_extended-0.0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for django_shell_extended-0.0.1.tar.gz
Algorithm Hash digest
SHA256 77c13b28be13b1760ea9da299291e7d83fc8a6a0f3dea759bd7659abfa655fb2
MD5 790cff1fc9e353a1f7e1414559546088
BLAKE2b-256 0bad240955664e43786e42a3f7e1f8e35650afd746ae0fa5ed660531d1732df9

See more details on using hashes here.

File details

Details for the file django_shell_extended-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_shell_extended-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 58fce8e4a0273fc874b2b227508f5c1928e5260eb93ecb7b25338083e09e53c2
MD5 8ae7f29037e81c273a1afd298e52f16e
BLAKE2b-256 de9c03d46544367bf5a9fbaf9ca05a1fdcdb563d49b938e83907c6928924b2a8

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