jupyter-notepad


Namejupyter-notepad JSON
Version 0.0.2 PyPI version JSON
download
home_pageNone
SummaryA versioned code editor widget for Jupyter
upload_time2024-04-01 06:21:33
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseCopyright 2024 Cameron Feenstra Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords ipython jupyter widgets
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Jupyter Notepad

`jupyter_notepad` is a python library that provides you a code editor widget that automatically tracks change history right within Jupyter notebooks. This is useful when you're iterating on a particular piece of text such as some code or a prompt for an AI model and don't want to lose any of your history. To try it out, simple install using `pip`:
```bash
pip install jupyter_notepad
```
Then in a jupyter notebook cell, you can get started in just a couple lines of code:
```python
from jupyter_notepad import Repo

repo = Repo("./my-project")

prompt_file = repo.file("prompt.md")
prompt_file # This should be the last line of the cell
```
You should see an editor open in your notebook like below:

![Screenshot of the widget in a notebook](images/widget-1.png)

You can retrieve the contents of your file by simply calling `str(file)`:

```python
prompt_value = str(prompt_file)
```

You can use the "History" dropdown within the widget to restore old versions of your text:

![Screenshot of the widget in a notebook with the history dropdown expanded](images/widget-2.png)

`jupyter_notepad` saves a new version of your text automatically when you update your file, but you can also use `Cmd+S` or the "Save" button in the widget to save a new version of your work. If you disable the checkbox next to "Auto Save" in the widget, new versions will _only_ be created when you explicitly save your work using one of those two methods. The only exception is that when you restore an old version of your text, `jupyter_notepad` will always save a new version before restoring it (as long as there's a diff since the last saved version).

For simple usages of `jupyter_notepad`, those features should be all you need. Read on to learn about more advanced usages of `jupyter_notepad`.

## Table of Contents

- [Sharing Notebooks](#sharing-notebooks)
- [Editing multiple files at once](#editing-multiple-files-at-once)
- [Development](#development)
- [Support and feature requests](#support-and-feature-requests)

## Sharing notebooks

One of the side effects of using `jupyter_notepad` is that by default it makes sharing notebooks more difficult. `jupyter_notepad` offers a solution for this so that even without your `jupyter_notepad` repository, others can still run all of your code.

The solution is to use the `%load_from_repo` magic function. This will be registered automatically when you import `jupyter_notepad`. What this magic function does is load one of the files from your repository, and store the contents in a string literal in a cell of your notebook.

When using this magic function, you must provide three arguments:
- The variable name for the `jupyter_notepad.Repo` instance to load the file from.
- The file path within the repository to load, or the variable name that holds that path.
- The output variable that the contents of that variable will be assigned to.

For example:
```python
%load_from_repo repo prompt.md prompt_value
```
If you run a cell with those contents after the code block from the introduction, it will replace the contents of the cell with the following and execute it:
```python
%load_from_repo repo prompt.md prompt_value
# NOTE: The contents of this cell are generated. It's recommended that you 
# edit the contents of prompt.md using jupyter_notepad or directly rather 
# than editing this cell directly.
prompt_value = '# Hello\n\nAs you can see, there will be automatic syntax highlighting for most languages based on the file extension of the file name.\n\n```js\n// Code will even be highlighted in code blocks!\nconst a = 1;\n```\n'
```
The cell can be re-run, and the latest contents of the file will be loaded each time.

Now, when others run your notebook, you have two options:
- They can comment out the `%load_from_repo` line and just run the cell normally. In fact, if desired all of the `jupyter_notebook` code could be removed from the notebook by others if desired and they could still run the notebook.
- If they have an empty repository and `prompt.md` is not found, `%load_from_repo` will simply print a warning and still execute the python code below it.

## Editing Multiple Files at Once

When editing multiple files, you might want to have multiple tabs or multiple editors side-by-side. Luckly, the `ipywidgets` module makes this very straightforward. `jupyter_notepad` works seemlessly with `ipywidgets` widgets such as `VBox`, `HBox`, and `Tab`. You can use these to build more complex layouts composed of multiple individual editors. An illustrative example can be found below:
```python
import ipywidgets

ipywidgets.Tab(
    children=[
        repo.file("prompt.md"),
        ipywidgets.HBox([
            repo.file("fibonacci.js"),
            repo.file("fibonacci.py"),
        ])
    ],
    titles=[
        "prompt.md",
        "fibonacci",
    ]
)
```
Results in the following:

![Multiple jupyter_notepad file widgets composed into tabs and an HBox](images/widget-multiple-files.png)

Note that you can change the height for a particular file by setting the `height` property. It is a number, and the height of the widget will be set in `rem`. The default value is `18`. Example:
```python
my_file = repo.file("prompt.md")
my_file.height = 36
my_file
```

## Development

See [DEVELOPMENT.md](DEVELOPMENT.md).

## Support and feature requests

If you encounter a bug with `jupyter_notepad` or would like to request a new feature, please open an [issue](https://github.com/cfeenstra67/jupyter_notepad/issues) and I'll try to help you out as quickly as possible. Contributions are welcome if you'd like to contribute a feature or improve the documentation.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "jupyter-notepad",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "IPython, Jupyter, Widgets",
    "author": null,
    "author_email": "Cam Feenstra <me@camfeenstra.com>",
    "download_url": "https://files.pythonhosted.org/packages/e5/17/234cfe1b690fc322ab3d840135f4259c07b24c7ac0d81a7d510b87add5c0/jupyter_notepad-0.0.2.tar.gz",
    "platform": null,
    "description": "# Jupyter Notepad\n\n`jupyter_notepad` is a python library that provides you a code editor widget that automatically tracks change history right within Jupyter notebooks. This is useful when you're iterating on a particular piece of text such as some code or a prompt for an AI model and don't want to lose any of your history. To try it out, simple install using `pip`:\n```bash\npip install jupyter_notepad\n```\nThen in a jupyter notebook cell, you can get started in just a couple lines of code:\n```python\nfrom jupyter_notepad import Repo\n\nrepo = Repo(\"./my-project\")\n\nprompt_file = repo.file(\"prompt.md\")\nprompt_file # This should be the last line of the cell\n```\nYou should see an editor open in your notebook like below:\n\n![Screenshot of the widget in a notebook](images/widget-1.png)\n\nYou can retrieve the contents of your file by simply calling `str(file)`:\n\n```python\nprompt_value = str(prompt_file)\n```\n\nYou can use the \"History\" dropdown within the widget to restore old versions of your text:\n\n![Screenshot of the widget in a notebook with the history dropdown expanded](images/widget-2.png)\n\n`jupyter_notepad` saves a new version of your text automatically when you update your file, but you can also use `Cmd+S` or the \"Save\" button in the widget to save a new version of your work. If you disable the checkbox next to \"Auto Save\" in the widget, new versions will _only_ be created when you explicitly save your work using one of those two methods. The only exception is that when you restore an old version of your text, `jupyter_notepad` will always save a new version before restoring it (as long as there's a diff since the last saved version).\n\nFor simple usages of `jupyter_notepad`, those features should be all you need. Read on to learn about more advanced usages of `jupyter_notepad`.\n\n## Table of Contents\n\n- [Sharing Notebooks](#sharing-notebooks)\n- [Editing multiple files at once](#editing-multiple-files-at-once)\n- [Development](#development)\n- [Support and feature requests](#support-and-feature-requests)\n\n## Sharing notebooks\n\nOne of the side effects of using `jupyter_notepad` is that by default it makes sharing notebooks more difficult. `jupyter_notepad` offers a solution for this so that even without your `jupyter_notepad` repository, others can still run all of your code.\n\nThe solution is to use the `%load_from_repo` magic function. This will be registered automatically when you import `jupyter_notepad`. What this magic function does is load one of the files from your repository, and store the contents in a string literal in a cell of your notebook.\n\nWhen using this magic function, you must provide three arguments:\n- The variable name for the `jupyter_notepad.Repo` instance to load the file from.\n- The file path within the repository to load, or the variable name that holds that path.\n- The output variable that the contents of that variable will be assigned to.\n\nFor example:\n```python\n%load_from_repo repo prompt.md prompt_value\n```\nIf you run a cell with those contents after the code block from the introduction, it will replace the contents of the cell with the following and execute it:\n```python\n%load_from_repo repo prompt.md prompt_value\n# NOTE: The contents of this cell are generated. It's recommended that you \n# edit the contents of prompt.md using jupyter_notepad or directly rather \n# than editing this cell directly.\nprompt_value = '# Hello\\n\\nAs you can see, there will be automatic syntax highlighting for most languages based on the file extension of the file name.\\n\\n```js\\n// Code will even be highlighted in code blocks!\\nconst a = 1;\\n```\\n'\n```\nThe cell can be re-run, and the latest contents of the file will be loaded each time.\n\nNow, when others run your notebook, you have two options:\n- They can comment out the `%load_from_repo` line and just run the cell normally. In fact, if desired all of the `jupyter_notebook` code could be removed from the notebook by others if desired and they could still run the notebook.\n- If they have an empty repository and `prompt.md` is not found, `%load_from_repo` will simply print a warning and still execute the python code below it.\n\n## Editing Multiple Files at Once\n\nWhen editing multiple files, you might want to have multiple tabs or multiple editors side-by-side. Luckly, the `ipywidgets` module makes this very straightforward. `jupyter_notepad` works seemlessly with `ipywidgets` widgets such as `VBox`, `HBox`, and `Tab`. You can use these to build more complex layouts composed of multiple individual editors. An illustrative example can be found below:\n```python\nimport ipywidgets\n\nipywidgets.Tab(\n    children=[\n        repo.file(\"prompt.md\"),\n        ipywidgets.HBox([\n            repo.file(\"fibonacci.js\"),\n            repo.file(\"fibonacci.py\"),\n        ])\n    ],\n    titles=[\n        \"prompt.md\",\n        \"fibonacci\",\n    ]\n)\n```\nResults in the following:\n\n![Multiple jupyter_notepad file widgets composed into tabs and an HBox](images/widget-multiple-files.png)\n\nNote that you can change the height for a particular file by setting the `height` property. It is a number, and the height of the widget will be set in `rem`. The default value is `18`. Example:\n```python\nmy_file = repo.file(\"prompt.md\")\nmy_file.height = 36\nmy_file\n```\n\n## Development\n\nSee [DEVELOPMENT.md](DEVELOPMENT.md).\n\n## Support and feature requests\n\nIf you encounter a bug with `jupyter_notepad` or would like to request a new feature, please open an [issue](https://github.com/cfeenstra67/jupyter_notepad/issues) and I'll try to help you out as quickly as possible. Contributions are welcome if you'd like to contribute a feature or improve the documentation.\n",
    "bugtrack_url": null,
    "license": "Copyright 2024 Cameron Feenstra  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A versioned code editor widget for Jupyter",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://github.com/cfeenstra67/jupyter-notepad"
    },
    "split_keywords": [
        "ipython",
        " jupyter",
        " widgets"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7658cef3db759a45495568c9ec4b6083ae102bdc4239629cb751738ca6c876c9",
                "md5": "cb2c48a677eccf1c05a46c22b47a57d1",
                "sha256": "5f499219f2653227cec6909316fbca93093fe87377d8716991a2124041e20f6c"
            },
            "downloads": -1,
            "filename": "jupyter_notepad-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cb2c48a677eccf1c05a46c22b47a57d1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 3325230,
            "upload_time": "2024-04-01T06:21:31",
            "upload_time_iso_8601": "2024-04-01T06:21:31.118699Z",
            "url": "https://files.pythonhosted.org/packages/76/58/cef3db759a45495568c9ec4b6083ae102bdc4239629cb751738ca6c876c9/jupyter_notepad-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e517234cfe1b690fc322ab3d840135f4259c07b24c7ac0d81a7d510b87add5c0",
                "md5": "a7a0f76e93655c55f755d6c7c06cb579",
                "sha256": "930fc35456bbf359fc2a1015c594d9acb97bfb7fa4bd4e84bb410babd1636d45"
            },
            "downloads": -1,
            "filename": "jupyter_notepad-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "a7a0f76e93655c55f755d6c7c06cb579",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 1860505,
            "upload_time": "2024-04-01T06:21:33",
            "upload_time_iso_8601": "2024-04-01T06:21:33.506290Z",
            "url": "https://files.pythonhosted.org/packages/e5/17/234cfe1b690fc322ab3d840135f4259c07b24c7ac0d81a7d510b87add5c0/jupyter_notepad-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-01 06:21:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cfeenstra67",
    "github_project": "jupyter-notepad",
    "github_not_found": true,
    "lcname": "jupyter-notepad"
}
        
Elapsed time: 0.21376s