Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pydanny/dj-notebook
Django + shell_plus + Jupyter notebooks made easy.
https://github.com/pydanny/dj-notebook
django django-extensions jupyter-notebook notebook
Last synced: about 17 hours ago
JSON representation
Django + shell_plus + Jupyter notebooks made easy.
- Host: GitHub
- URL: https://github.com/pydanny/dj-notebook
- Owner: pydanny
- License: gpl-3.0
- Created: 2023-09-12T14:13:11.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-08T14:56:22.000Z (8 months ago)
- Last Synced: 2024-12-14T21:06:38.423Z (8 days ago)
- Topics: django, django-extensions, jupyter-notebook, notebook
- Language: Jupyter Notebook
- Homepage: https://dj-notebook.readthedocs.io/
- Size: 3.04 MB
- Stars: 135
- Watchers: 4
- Forks: 20
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Django + shell_plus + Jupyter notebooks made easy
---
A Jupyter notebook with access to objects from the Django ORM is a powerful tool to introspect data and run ad-hoc queries.
Full documentation available at [dj-notebook](https://dj-notebook.readthedocs.io/)
---
## Features
The ever-growing list of features:
- Easy Jupyter notebooks with Django
- Built-in integration with the imported objects from django-extensions `shell_plus`
- Saves the state between sessions so you don't need to remember what you did
- Inheritance diagrams on any object, including ORM models
- Converts any Django QuerySet to Pandas Dataframe
- Handy function for displaying MermaidJS charts
- Generates visual maps of model relations
- Works in the browser, VSCode, PyCharm, Emacs, Vim, and more!## Installation
Use your installation tool of choice, here we use venv and pip:
```bash
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`, or another directory of your choosing. 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:
```python
from dj_notebook import activateplus = activate()
# If you have created your notebook in a different directory, instead do:
# plus = activate(search_dir="/path/to/your/project")# If that throws an error, try one of the following:
# DJANGO_SETTINGS_MODULE_VALUE aka "book_store.settings"
# plus = activate("DJANGO_SETTINGS_MODULE_VALUE")# Point to location of dotenv file with Django settings
# plus = activate(dotenv_file='.env')
```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:
```python
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:
```python
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:
```python
plus.diagram(plus.User)
```Generates this image
Here's another useful diagram:
```python
plus.model_graph(plus.User)
```## QuerySet to Dataframe
Want to convert a Django query to a Pandas Dataframe? We got you covered.
```python
plus.read_frame(plus.User.objects.all())
```## More things you can do!
[dj-notebook official documentation](https://dj-notebook.readthedocs.io/)
## Contributors
Daniel Roy Greenfeld
Cody Antunez
Geoff Beier
Nick Powell
Saransh Sood
Anna Zhydko
Tejo Kaushal
Simon Davy
Null
Dave Parr
Siew-Yit Yong
## Special thanks
These are people who aren't in our formal git history but should be.
- [Tom Preston](https://github.com/prestto) did seminal work on Python paths that later became the foundation of dj-notebook
- [Evie Clutton](https://github.com/evieclutton) was co-author of a pull request and they don't show up in the contributor list above
- [Tim Schilling](https://github.com/tim-schilling) assisted with the `model_graph` method
- [Charlie Denton](https://github.com/meshy) is responsible for django-schema-graph, which we leverage as part of the `model_graph` feature
- [Christopher Clarke](https://github.com/chrisdev) built `django-pandas`, which dj-notebook uses
- [Stephen Moore](https://github.com/delfick) for some early work done on the internals of dj-notebook before it was open sourced.
- [django-extensions](django-extensions) for providing so many useful tools over the years, and being one of the backbones of this project
Tom Preston
Null
Tim Schilling
Charlie Denton
Christopher Clarke
Stephen Moore
## Construction
This package was created with [Cookiecutter](https://github.com/cookiecutter/cookiecutter) and the [simplicity](https://github.com/pydanny/simplicity) project template.