notebook-prototyping


Namenotebook-prototyping JSON
Version 0.1.11 PyPI version JSON
download
home_pagehttps://github.com/rlhjansen/nbprototyping
Summary
upload_time2023-06-29 19:43:39
maintainer
docs_urlNone
authorReitze Jansen
requires_python
licenseMIT
keywords jupyter notebook tooling
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            

# Notebook prototyping

This repo makes prototyping via notebooks easier, by providing a way to strip them of experimental function calls.
In this manner, jupyter notebooks can be used to write, check, experiment, etc. with code while writing it while taking away the hassle of pasting all definitions into a new file.

With this you can:
- import notebooks directly
- strip notebooks to their bare class and function definitions.


# Usage

```
pip install notebook-prototyping
```

### importing the entire notebook contents

While developing it might be useful to import notebooks contents into other notebooks. This can be done via a pseudo import. currently the check for recursion is based on a heuristic trace stack depth

Running this makes objects that would be created in the secondary notebook available in a new notebook or script, but it should be noted that these exist *in a separate process*. as such it is strongly recommended to use convert_to_module + a normal import statement wherever possible instead
```
from notebook_import import import_notebook
import os

te = import_notebook('third_example', path=os.path.join('nested', 'directory'))
# alt import calls
# te = import_notebook('third_example.ipynb', path=os.path.join('nested', 'directory'))
# te = import_notebook(os.path.join('nested', 'directory', 'third_example'))
# te = import_notebook('nested.directory.third_example.ipynb')


te.foobar()
```


### conversion to .py files

It is recommended to do the conversion on a per-notebook basis

- Using the notebook name:
```
from notebook_import import convert_to_module
convert_to_module("example", overwrite=True)
```
- importing different notebooks contents cleanly, without their instantiated objects:
```
from notebook_import import convert_to_module
convert_to_module("second_example", overwrite=True)
import second_example as se
print(se.bar())
```
- Like importing notebooks, converting can also be done with notebooks in nested directories:
```
from notebook_import import convert_to_module
convert_to_module("third_example", overwrite=True, path=os.path.join("nested", "directory"))
import nested.directory.third_example as te
te.foobar()
```
- If you just to copy/paste something at the end of the notebook to convert them if they sucesfully finish running this can be done by also using ipynb([using ipynbname](https://pypi.org/project/ipynbname/)):
```
from notebook_import import convert_to_module
import ipynbname
nb_fname = ipynbname.name()
convert_to_module(nb_fname, True)
```

# Todos

- Currently the check for recursion is based on a heuristic trace stack depth, find a better way
- Make it a [pypi package](https://packaging.python.org/en/latest/tutorials/packaging-projects/)
    - [add classifiers](https://pypi.org/classifiers/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rlhjansen/nbprototyping",
    "name": "notebook-prototyping",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "jupyter notebook,tooling",
    "author": "Reitze Jansen",
    "author_email": "rlh.jansen@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/f7/b2/806bbc851b8b6eabf0857bdb43b1638f4dd5e4b940704635fb35684d24ef/notebook_prototyping-0.1.11.tar.gz",
    "platform": null,
    "description": "\r\n\r\n# Notebook prototyping\r\n\r\nThis repo makes prototyping via notebooks easier, by providing a way to strip them of experimental function calls.\r\nIn this manner, jupyter notebooks can be used to write, check, experiment, etc. with code while writing it while taking away the hassle of pasting all definitions into a new file.\r\n\r\nWith this you can:\r\n- import notebooks directly\r\n- strip notebooks to their bare class and function definitions.\r\n\r\n\r\n# Usage\r\n\r\n```\r\npip install notebook-prototyping\r\n```\r\n\r\n### importing the entire notebook contents\r\n\r\nWhile developing it might be useful to import notebooks contents into other notebooks. This can be done via a pseudo import. currently the check for recursion is based on a heuristic trace stack depth\r\n\r\nRunning this makes objects that would be created in the secondary notebook available in a new notebook or script, but it should be noted that these exist *in a separate process*. as such it is strongly recommended to use convert_to_module + a normal import statement wherever possible instead\r\n```\r\nfrom notebook_import import import_notebook\r\nimport os\r\n\r\nte = import_notebook('third_example', path=os.path.join('nested', 'directory'))\r\n# alt import calls\r\n# te = import_notebook('third_example.ipynb', path=os.path.join('nested', 'directory'))\r\n# te = import_notebook(os.path.join('nested', 'directory', 'third_example'))\r\n# te = import_notebook('nested.directory.third_example.ipynb')\r\n\r\n\r\nte.foobar()\r\n```\r\n\r\n\r\n### conversion to .py files\r\n\r\nIt is recommended to do the conversion on a per-notebook basis\r\n\r\n- Using the notebook name:\r\n```\r\nfrom notebook_import import convert_to_module\r\nconvert_to_module(\"example\", overwrite=True)\r\n```\r\n- importing different notebooks contents cleanly, without their instantiated objects:\r\n```\r\nfrom notebook_import import convert_to_module\r\nconvert_to_module(\"second_example\", overwrite=True)\r\nimport second_example as se\r\nprint(se.bar())\r\n```\r\n- Like importing notebooks, converting can also be done with notebooks in nested directories:\r\n```\r\nfrom notebook_import import convert_to_module\r\nconvert_to_module(\"third_example\", overwrite=True, path=os.path.join(\"nested\", \"directory\"))\r\nimport nested.directory.third_example as te\r\nte.foobar()\r\n```\r\n- If you just to copy/paste something at the end of the notebook to convert them if they sucesfully finish running this can be done by also using ipynb([using ipynbname](https://pypi.org/project/ipynbname/)):\r\n```\r\nfrom notebook_import import convert_to_module\r\nimport ipynbname\r\nnb_fname = ipynbname.name()\r\nconvert_to_module(nb_fname, True)\r\n```\r\n\r\n# Todos\r\n\r\n- Currently the check for recursion is based on a heuristic trace stack depth, find a better way\r\n- Make it a [pypi package](https://packaging.python.org/en/latest/tutorials/packaging-projects/)\r\n    - [add classifiers](https://pypi.org/classifiers/)\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "",
    "version": "0.1.11",
    "project_urls": {
        "Homepage": "https://github.com/rlhjansen/nbprototyping"
    },
    "split_keywords": [
        "jupyter notebook",
        "tooling"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7b2806bbc851b8b6eabf0857bdb43b1638f4dd5e4b940704635fb35684d24ef",
                "md5": "ecd447ed8774c5550e164b1d63ffe48f",
                "sha256": "77282282b5b039c190b7c437ebc8f5ac676feeaf57235ccb10dd3ca71e3413b4"
            },
            "downloads": -1,
            "filename": "notebook_prototyping-0.1.11.tar.gz",
            "has_sig": false,
            "md5_digest": "ecd447ed8774c5550e164b1d63ffe48f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6412,
            "upload_time": "2023-06-29T19:43:39",
            "upload_time_iso_8601": "2023-06-29T19:43:39.221242Z",
            "url": "https://files.pythonhosted.org/packages/f7/b2/806bbc851b8b6eabf0857bdb43b1638f4dd5e4b940704635fb35684d24ef/notebook_prototyping-0.1.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-29 19:43:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rlhjansen",
    "github_project": "nbprototyping",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "notebook-prototyping"
}
        
Elapsed time: 0.08313s