django-notebook-config


Namedjango-notebook-config JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/WazedKhan/django-notebook-config
SummaryA utility to easily use Django in IDEs Jupyter Notebooks.
upload_time2024-11-28 06:01:26
maintainerNone
docs_urlNone
authorAbdul Wajed Khan
requires_python>=3.6
licenseMIT
keywords django jupyter notebook development helper debugger
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-notebook-config

Easily run Django queries and tasks within Jupyter Notebooks in IDEs.

## Overview

`vscode-django-notebook` simplifies the process of initializing Django projects directly in Jupyter Notebook cells. This is particularly useful for quick debugging, querying, and testing in a flexible notebook environment.

---

## Features

- **Convenient Django Initialization**: Avoid repetitive setup steps in Jupyter Notebooks.
- **Interactive Django ORM Access**: Use Django models and utilities interactively.
- **VS Code Compatible**: Tailored for the Jupyter extension in IDEs.

---

## Installation

Install the package via pip:

```bash
pip install django-notebook-config
```

---

## **Setup Guide**

### Step 1: Create a Folder for Notebooks

On the same level as `manage.py`, create a folder to organize your Jupyter Notebooks. For example:

```ini
your_project/
├── manage.py
├── config/
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── notebook/
│   ├── __init__.py
│   └── user.ipynb
```

* **Folder Name** : You can name this folder anything you like (e.g., `notebooks`, `playground`, `testing`). In this example, we use `notebook`.
* **Notebook File Name** : The notebook file (e.g., `user.ipynb`) can also have any name, depending on its purpose.

---

### Step 2: Select the Project's Environment in VS Code

1. Open the `user.ipynb` notebook in VS Code.
2. In the top-right corner of the Jupyter Notebook interface, click on the  **kernel selection dropdown** .
3. Choose the Python environment where your Django project dependencies are installed.

---

### Step 3: Install and Initialize django-notebook-config

2. Add the following code at the top of your notebook to initialize Django:

```python
from django-notebook-config import init_django

# Initialize Django by specifying the project name
init_django(project_name="config")
```

Replace `"config"` with the name of your Django project module (where `settings.py` is located).

---

### Step 4: Write Complex Queries or Debug Utilities

Once initialized, you can interact with Django models, run complex queries, or debug utilities directly in the notebook. Here's an example:

#### Example: Testing a Query

```python
# Import Django models
from myapp.models import User, Order

# Write and test complex queries
users_with_recent_orders = User.objects.filter(
    id__in=Order.objects.filter(date__gte="2024-01-01").values_list("user_id", flat=True)
)

# Inspect the results
print(users_with_recent_orders)
```

#### Example: Writing and Debugging Utilities

```python
# Utility function to calculate total revenue for a user
def calculate_user_revenue(user_id):
    from myapp.models import Order
    return Order.objects.filter(user_id=user_id).aggregate(total_revenue=Sum("amount"))["total_revenue"]

# Test the utility
test_user_id = 1
print(f"Total revenue for user {test_user_id}: {calculate_user_revenue(test_user_id)}")
```

---

### Benefits of This Workflow

* **Interactive Testing** : Test Django ORM queries and helper functions interactively.
* **Debugging Made Easy** : Debug utilities or inspect data before adding them to the project.
* **Reusable Code** : Refine and reuse tested code in the actual project.

---

### Troubleshooting

* **Jupyter Kernel Not Working** : Ensure you’ve selected the correct Python environment in VS Code.
* __Initialization Error__ : Verify that the `project_name` in `init_django()` matches the folder containing your `settings.py`.

Now you're ready to streamline your Django development workflow using Jupyter Notebooks! 🚀

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/WazedKhan/django-notebook-config",
    "name": "django-notebook-config",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "django jupyter notebook development helper debugger",
    "author": "Abdul Wajed Khan",
    "author_email": "wajed.abdul.khan@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c9/6e/36ecb31c4afd89b9588546c3249626d7bab96b586ee85ad8fe1556259d8a/django_notebook_config-0.1.1.tar.gz",
    "platform": null,
    "description": "# django-notebook-config\n\nEasily run Django queries and tasks within Jupyter Notebooks in IDEs.\n\n## Overview\n\n`vscode-django-notebook` simplifies the process of initializing Django projects directly in Jupyter Notebook cells. This is particularly useful for quick debugging, querying, and testing in a flexible notebook environment.\n\n---\n\n## Features\n\n- **Convenient Django Initialization**: Avoid repetitive setup steps in Jupyter Notebooks.\n- **Interactive Django ORM Access**: Use Django models and utilities interactively.\n- **VS Code Compatible**: Tailored for the Jupyter extension in IDEs.\n\n---\n\n## Installation\n\nInstall the package via pip:\n\n```bash\npip install django-notebook-config\n```\n\n---\n\n## **Setup Guide**\n\n### Step 1: Create a Folder for Notebooks\n\nOn the same level as `manage.py`, create a folder to organize your Jupyter Notebooks. For example:\n\n```ini\nyour_project/\n\u251c\u2500\u2500 manage.py\n\u251c\u2500\u2500 config/\n\u2502   \u251c\u2500\u2500 __init__.py\n\u2502   \u251c\u2500\u2500 settings.py\n\u2502   \u251c\u2500\u2500 urls.py\n\u2502   \u2514\u2500\u2500 wsgi.py\n\u251c\u2500\u2500 notebook/\n\u2502   \u251c\u2500\u2500 __init__.py\n\u2502   \u2514\u2500\u2500 user.ipynb\n```\n\n* **Folder Name** : You can name this folder anything you like (e.g., `notebooks`, `playground`, `testing`). In this example, we use `notebook`.\n* **Notebook File Name** : The notebook file (e.g., `user.ipynb`) can also have any name, depending on its purpose.\n\n---\n\n### Step 2: Select the Project's Environment in VS Code\n\n1. Open the `user.ipynb` notebook in VS Code.\n2. In the top-right corner of the Jupyter Notebook interface, click on the  **kernel selection dropdown** .\n3. Choose the Python environment where your Django project dependencies are installed.\n\n---\n\n### Step 3: Install and Initialize django-notebook-config\n\n2. Add the following code at the top of your notebook to initialize Django:\n\n```python\nfrom django-notebook-config import init_django\n\n# Initialize Django by specifying the project name\ninit_django(project_name=\"config\")\n```\n\nReplace `\"config\"` with the name of your Django project module (where `settings.py` is located).\n\n---\n\n### Step 4: Write Complex Queries or Debug Utilities\n\nOnce initialized, you can interact with Django models, run complex queries, or debug utilities directly in the notebook. Here's an example:\n\n#### Example: Testing a Query\n\n```python\n# Import Django models\nfrom myapp.models import User, Order\n\n# Write and test complex queries\nusers_with_recent_orders = User.objects.filter(\n    id__in=Order.objects.filter(date__gte=\"2024-01-01\").values_list(\"user_id\", flat=True)\n)\n\n# Inspect the results\nprint(users_with_recent_orders)\n```\n\n#### Example: Writing and Debugging Utilities\n\n```python\n# Utility function to calculate total revenue for a user\ndef calculate_user_revenue(user_id):\n    from myapp.models import Order\n    return Order.objects.filter(user_id=user_id).aggregate(total_revenue=Sum(\"amount\"))[\"total_revenue\"]\n\n# Test the utility\ntest_user_id = 1\nprint(f\"Total revenue for user {test_user_id}: {calculate_user_revenue(test_user_id)}\")\n```\n\n---\n\n### Benefits of This Workflow\n\n* **Interactive Testing** : Test Django ORM queries and helper functions interactively.\n* **Debugging Made Easy** : Debug utilities or inspect data before adding them to the project.\n* **Reusable Code** : Refine and reuse tested code in the actual project.\n\n---\n\n### Troubleshooting\n\n* **Jupyter Kernel Not Working** : Ensure you\u2019ve selected the correct Python environment in VS Code.\n* __Initialization Error__ : Verify that the `project_name` in `init_django()` matches the folder containing your `settings.py`.\n\nNow you're ready to streamline your Django development workflow using Jupyter Notebooks! \ud83d\ude80\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A utility to easily use Django in IDEs Jupyter Notebooks.",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/WazedKhan/django-notebook-config"
    },
    "split_keywords": [
        "django",
        "jupyter",
        "notebook",
        "development",
        "helper",
        "debugger"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9a253b76f403a6b8ba651b2566b2456fb764162b74f299ca574ea6c53b528998",
                "md5": "3f2c7895a8d0e8f3c8d8e88a6617221c",
                "sha256": "a9fbb406c5f19500a50432f22b06afcb1b697789a679bca6ee45d2da45c18374"
            },
            "downloads": -1,
            "filename": "django_notebook_config-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3f2c7895a8d0e8f3c8d8e88a6617221c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 4970,
            "upload_time": "2024-11-28T06:01:24",
            "upload_time_iso_8601": "2024-11-28T06:01:24.269642Z",
            "url": "https://files.pythonhosted.org/packages/9a/25/3b76f403a6b8ba651b2566b2456fb764162b74f299ca574ea6c53b528998/django_notebook_config-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c96e36ecb31c4afd89b9588546c3249626d7bab96b586ee85ad8fe1556259d8a",
                "md5": "8abf06993ec4d9a472a1fdb00eda5748",
                "sha256": "857a09c0e7cdbdd1f4553431d0a03219ecfce70af88193a953aae7876bda3ea1"
            },
            "downloads": -1,
            "filename": "django_notebook_config-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8abf06993ec4d9a472a1fdb00eda5748",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4402,
            "upload_time": "2024-11-28T06:01:26",
            "upload_time_iso_8601": "2024-11-28T06:01:26.322660Z",
            "url": "https://files.pythonhosted.org/packages/c9/6e/36ecb31c4afd89b9588546c3249626d7bab96b586ee85ad8fe1556259d8a/django_notebook_config-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-28 06:01:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "WazedKhan",
    "github_project": "django-notebook-config",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "django-notebook-config"
}
        
Elapsed time: 0.60226s