Skip to main content

A Jupyter notebook with access to objects from the Django ORM is a powerful tool to introspect data and run ad-hoc queries.

Project description

dj-notebook

A Jupyter notebook with access to objects from the Django ORM is a powerful tool to introspect data and run ad-hoc queries. This works with modern Django and Python 3.9, 3.10, and 3.11.

Features

  • Easy ipython notebooks with Django
  • Built-in integration with the imported objects from django-extensions
  • Inheritance diagrams on any object, including ORM models

Installation

Use your installation tool of choice, here we use venv and pip:

python -m venv venv
source venv/bin/activate
pip install dj_notebook

Usage

First, find your project's manage.py file and open it. Copy whatever is being set to DJANGO_SETTINGS_MODULE into your clipboard.

Create an ipython notebook in the same directory as manage.py. In VSCode, simply add a new .ipynb file. If using Jupyter Lab, use the File -> New -> Notebook menu option.

Then in the first cell enter:

from dj_notebook import activate

plus = activate("DJANGO_SETTINGS_MODULE_VALUE")

In future cells, you can now load and run Django objects, including the ORM. This three line snippet should give an idea of what you can now do:

from django.contrib.auth import get_user_model
User = get_user_model()
User.objects.all()

Usage Plus

But wait, it gets better!

When you activated the Django environment, you instantiated a variable called 'plus'. The 'plus' variable is an object that contains everything loaded from django-extensions' shell_plus. Here's a demonstration, try running this snippet:

plus.User.objects.all()

We also provide a utility for introspection of classes, which can be useful in sophisticated project architectures. Running this code in a Jupyter notebook shell:

plus.diagram(plus.User)

Generates this image

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

dj_notebook-0.2.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

dj_notebook-0.2.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file dj_notebook-0.2.1.tar.gz.

File metadata

  • Download URL: dj_notebook-0.2.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for dj_notebook-0.2.1.tar.gz
Algorithm Hash digest
SHA256 79a183769965d120155a6a0dcdb1744e6c03c215da67ba14edd502e3ae1d64c2
MD5 825f2f33eeb2f806f9772cb0b461f325
BLAKE2b-256 19bd70293f2706e688b660a7b9188348e905e3675bb75d7ce6979ac04a654a77

See more details on using hashes here.

File details

Details for the file dj_notebook-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: dj_notebook-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for dj_notebook-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bbc951e25d3f57f8f5e77877c2fd081b3fb568614688fe63bb7b986282717db6
MD5 f40a2dfeb99dff418a7a2797752b4fe9
BLAKE2b-256 3848dbadc1c6a41de863f6b73d974fdb51e6b44f492b0c870ded5403bcefa70d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page