Search code examples
pythondjangoipythonjupyterdjango-extensions

django-extensions shell_plus --kernel specify connection file


I would like to use jupyter-hub start and interact with django ipython kernels.

Django extensions allows me to create an ipython kernel via the manage.py shell_plus --kernel command line, however this doesn't allow me to specify the connection file, which is required for jupyter-hub kernel specification.

For example I would like to Specify my own custom kernel type similarly to this:

{
"display_name": "Django",
"language": "python",
"codemirror_mode": {
    "version": 3,
    "name": "ipython"
},
"argv": [
    "/home/me/.virtualenvs/django/bin/python",
    "/home/me/django/manage.py",
    "shell_plus",
    "--kernel",
    "-f",
    "{connection_file}"
    ]
}

However it doesn't look like the --kernel option allows me to pass additional kwags.

I've taken a quick look at the source for django-extensions and ipython, but can't see an easy fix. Anyone have any ideas.

I think it would be super useful to be able to connect to a django shell from Jupyter-hub, and it seems like the functionality is pretty close.

Thanks.


Solution

  • For anyone interested, I fixed this by adding a --connection_file option to the shell_plus command in django-extension, which then forwards the filename to the kernel. I can then define my django kernel for Jupyter-hub as the following.

    {
    "display_name": "Django",
    "language": "python",
    "codemirror_mode": {
        "version": 3,
        "name": "ipython"
    },
    "argv": [
        "/home/me/.virtualenvs/django/bin/python",
        "/home/me/django/manage.py",
        "shell_plus",
        "--kernel",
        "--connection_file",
        "{connection_file}"
        ]
    }
    

    See my branch on github for the changes.