streamlit-notebook


Namestreamlit-notebook JSON
Version 0.0.26 PyPI version JSON
download
home_pagehttps://github.com/B4PT0R/streamlit_notebook
SummaryA notebook interface for Streamlit.
upload_time2025-02-01 19:38:05
maintainerNone
docs_urlNone
authorBaptiste Ferrand
requires_python>=3.9
licenseNone
keywords
VCS
bugtrack_url
requirements streamlit-notebook
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Streamlit Notebook

`streamlit_notebook` is a reactive notebook interface for Streamlit.

Pretty much like a Jupyter notebook, you can create and run Code cells (supporting rich display via Streamlit commands) or Markdown/HTML cells. These cells will be executed dynamically and their output will be rendered under each cell box.

The main feature of this notebook is to bridge the gap between a persistent python interactive session and a Streamlit app, to achieve selective reactivity in your notebook. 

Simply put, you can switch between using one-shot cells to run code just once, and looping cells, that will rerun based on the occurence of ui events.

The cell's code is run in a custom shell with its own internal namespace, preserved across reruns. The results of computations are therefore automatically stored in it, just like a regular python console. The added possibility to make chosen cells auto-rerun (possibly as fragments) allows to use streamlit code seamlessly and manage UI reactivity with adequate control. 

This notebook is meant to be fully compatible with Streamlit and doesn't introduce much complexity beyond standard Streamlit functionning. All Streamlit commands should work out of the box. If it's not the case, it should be reported as a bug.

I hope users already familiar with Streamlit will have great fun with this notebook.

## Features

- Switch to "App" mode by hiding code cells and notebook specific controls.
- Create and delete cells easily, move cells up and down, control how they execute.
- Create reactive Markdown or HTML cells by adding formatting tags `<<my_expression>>` that let you insert the current value of any global / state variable or evaluated expression into the text/code.
- Special `display` function that you can use even in one-shot cells to display python data in a pretty manner to the frontend (uses `st.write` as a default backend). 
- Automatic evaluation and display of single expressions. Can be selectively deactivated using semicolons at the end of the expression or by switching the display mode in the sidebar menu.
- Easily download / upload your notebooks as `.stnb` files (json format).
- The whole notebook UI can be controled dynamically from code cells. This feature will be refined as I advance this project, but can already be played with. You can refer to the notebook object as `notebook` from within the session and call its methods programmaticaly. For instance you can programmatically create, edit and run cells:

```python
# Create a new cell and run it
cell=notebook.new_cell(code="print('Hello!')",type="code")
cell.run()
```

```python
# Edit and existing cell and run it
cell=notebook.cells[1]
cell.code="print('Hello world!')"
cell.run()
```


## Screenshot

![In notebook mode](./streamlit_notebook/app_images/st_notebook_demo.png)


![In app mode](./streamlit_notebook/app_images/st_notebook_demo_2.png)

## Installation

```bash
pip install streamlit-notebook
```

## Usage

Once installed, you may open the notebook interface from anywhere by just running `st_notebook` in the terminal.

Or pass a notebook file to open it directly:
```bash
$ st_notebook my_notebook.stnb
```

In case you need to use the package programmatically, you may create a python script like so: 

```python 
# notebook.py
from streamlit_notebook import st_notebook

st_notebook()
```

and run it using `streamlit run notebook.py` from the terminal.

The `st_notebook()` function accepts a local `stnb` file or a serialized notebook string as parameter.

This function is complete app in itself rather than a single component, and only serves as an entry point.

The app is meant to be run locally on your computer, the browser only being used as a GUI interface. Performance is better and allows to use your file system and packages in your sessions. It can be deployed to be used online and share your notebooks as apps, but keep in mind that in this case, the code will run remotely in the cloud server and you will be able to use only preinstalled packages. 

It is discouraged to introduce any sensitive data in your web sessions, as there is no inherent limitation on the code that can be run in the notebook (appart from limitations on the python packages that can be used). The app doesn't provide any additional security beyond those already implemented by Streamlit. A clever malvolent user could potentially reach your data or spy your session.

The app is available online [here](https://st-notebook.streamlit.app/) as a demo.

## Contribution

This App is still in early stage of development and any feedbacks / contributions are welcome!

I think it has a lot of potential and would benefit greatly from community engagement.

In case you want to give feedback or report a bug / suggest an improvement. Please open an new issue.

If you wish to contribute to this project, you're welcome to:

1. Fork the repository
2. Create a branch for your feature (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Changelog

- june 11th 2024:
    - Added HTML cells
    - Enabled uploading / downloading the notebook as a json file
    - Added a demo notebook (more to come)
    - Fixed st.echo that didn't work in an interactive environment 

- june 24th 2024:
    - Introduced the custom shell object and redirection utilities to integrate the shell smoothly in the notebook, making the session persistent across reruns.
    - Introduced ast parsing with asttokens library to evaluate and selectively display chosen expressions on the frontend, based on the presence of a trailing semicolon.
    - Added the `display` function, used for rich display of data in the notebook (using `st.write` as a backend).

- july 2nd 2024:
    - Improved dynamic cell creation, edition, and execution.
    - Added a couple demo notebooks to showcase these features.

- july 3rd 2024:
    - Notebook files now have a .stnb extension (content is still in json format).
    - Improved the st_notebook function to accept a .stnb file, or a serialized notebook string as parameter. Also improved the terminal command to accept a .stnb file as parameter. 

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/B4PT0R/streamlit_notebook",
    "name": "streamlit-notebook",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Baptiste Ferrand",
    "author_email": "bferrand.maths@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f6/87/f2ceb40ef6f7e568981361600998f7dd5acac4645a4a9797fcb72eb7ac72/streamlit_notebook-0.0.26.tar.gz",
    "platform": null,
    "description": "\n# Streamlit Notebook\n\n`streamlit_notebook` is a reactive notebook interface for Streamlit.\n\nPretty much like a Jupyter notebook, you can create and run Code cells (supporting rich display via Streamlit commands) or Markdown/HTML cells. These cells will be executed dynamically and their output will be rendered under each cell box.\n\nThe main feature of this notebook is to bridge the gap between a persistent python interactive session and a Streamlit app, to achieve selective reactivity in your notebook. \n\nSimply put, you can switch between using one-shot cells to run code just once, and looping cells, that will rerun based on the occurence of ui events.\n\nThe cell's code is run in a custom shell with its own internal namespace, preserved across reruns. The results of computations are therefore automatically stored in it, just like a regular python console. The added possibility to make chosen cells auto-rerun (possibly as fragments) allows to use streamlit code seamlessly and manage UI reactivity with adequate control. \n\nThis notebook is meant to be fully compatible with Streamlit and doesn't introduce much complexity beyond standard Streamlit functionning. All Streamlit commands should work out of the box. If it's not the case, it should be reported as a bug.\n\nI hope users already familiar with Streamlit will have great fun with this notebook.\n\n## Features\n\n- Switch to \"App\" mode by hiding code cells and notebook specific controls.\n- Create and delete cells easily, move cells up and down, control how they execute.\n- Create reactive Markdown or HTML cells by adding formatting tags `<<my_expression>>` that let you insert the current value of any global / state variable or evaluated expression into the text/code.\n- Special `display` function that you can use even in one-shot cells to display python data in a pretty manner to the frontend (uses `st.write` as a default backend). \n- Automatic evaluation and display of single expressions. Can be selectively deactivated using semicolons at the end of the expression or by switching the display mode in the sidebar menu.\n- Easily download / upload your notebooks as `.stnb` files (json format).\n- The whole notebook UI can be controled dynamically from code cells. This feature will be refined as I advance this project, but can already be played with. You can refer to the notebook object as `notebook` from within the session and call its methods programmaticaly. For instance you can programmatically create, edit and run cells:\n\n```python\n# Create a new cell and run it\ncell=notebook.new_cell(code=\"print('Hello!')\",type=\"code\")\ncell.run()\n```\n\n```python\n# Edit and existing cell and run it\ncell=notebook.cells[1]\ncell.code=\"print('Hello world!')\"\ncell.run()\n```\n\n\n## Screenshot\n\n![In notebook mode](./streamlit_notebook/app_images/st_notebook_demo.png)\n\n\n![In app mode](./streamlit_notebook/app_images/st_notebook_demo_2.png)\n\n## Installation\n\n```bash\npip install streamlit-notebook\n```\n\n## Usage\n\nOnce installed, you may open the notebook interface from anywhere by just running `st_notebook` in the terminal.\n\nOr pass a notebook file to open it directly:\n```bash\n$ st_notebook my_notebook.stnb\n```\n\nIn case you need to use the package programmatically, you may create a python script like so: \n\n```python \n# notebook.py\nfrom streamlit_notebook import st_notebook\n\nst_notebook()\n```\n\nand run it using `streamlit run notebook.py` from the terminal.\n\nThe `st_notebook()` function accepts a local `stnb` file or a serialized notebook string as parameter.\n\nThis function is complete app in itself rather than a single component, and only serves as an entry point.\n\nThe app is meant to be run locally on your computer, the browser only being used as a GUI interface. Performance is better and allows to use your file system and packages in your sessions. It can be deployed to be used online and share your notebooks as apps, but keep in mind that in this case, the code will run remotely in the cloud server and you will be able to use only preinstalled packages. \n\nIt is discouraged to introduce any sensitive data in your web sessions, as there is no inherent limitation on the code that can be run in the notebook (appart from limitations on the python packages that can be used). The app doesn't provide any additional security beyond those already implemented by Streamlit. A clever malvolent user could potentially reach your data or spy your session.\n\nThe app is available online [here](https://st-notebook.streamlit.app/) as a demo.\n\n## Contribution\n\nThis App is still in early stage of development and any feedbacks / contributions are welcome!\n\nI think it has a lot of potential and would benefit greatly from community engagement.\n\nIn case you want to give feedback or report a bug / suggest an improvement. Please open an new issue.\n\nIf you wish to contribute to this project, you're welcome to:\n\n1. Fork the repository\n2. Create a branch for your feature (`git checkout -b feature/AmazingFeature`)\n3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push the branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Changelog\n\n- june 11th 2024:\n    - Added HTML cells\n    - Enabled uploading / downloading the notebook as a json file\n    - Added a demo notebook (more to come)\n    - Fixed st.echo that didn't work in an interactive environment \n\n- june 24th 2024:\n    - Introduced the custom shell object and redirection utilities to integrate the shell smoothly in the notebook, making the session persistent across reruns.\n    - Introduced ast parsing with asttokens library to evaluate and selectively display chosen expressions on the frontend, based on the presence of a trailing semicolon.\n    - Added the `display` function, used for rich display of data in the notebook (using `st.write` as a backend).\n\n- july 2nd 2024:\n    - Improved dynamic cell creation, edition, and execution.\n    - Added a couple demo notebooks to showcase these features.\n\n- july 3rd 2024:\n    - Notebook files now have a .stnb extension (content is still in json format).\n    - Improved the st_notebook function to accept a .stnb file, or a serialized notebook string as parameter. Also improved the terminal command to accept a .stnb file as parameter. \n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A notebook interface for Streamlit.",
    "version": "0.0.26",
    "project_urls": {
        "Homepage": "https://github.com/B4PT0R/streamlit_notebook"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e0c1fb115c125b8f5042059d5f1ecea445894cbb2177bd14779d793c5cf1d6fe",
                "md5": "b9ebc24f620ced29fa44b9fdefac756a",
                "sha256": "5e682d313aa1db862e37b86e70ae19aced555e4ce9e3a9d293150306a36c8982"
            },
            "downloads": -1,
            "filename": "streamlit_notebook-0.0.26-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b9ebc24f620ced29fa44b9fdefac756a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 278994,
            "upload_time": "2025-02-01T19:38:02",
            "upload_time_iso_8601": "2025-02-01T19:38:02.748025Z",
            "url": "https://files.pythonhosted.org/packages/e0/c1/fb115c125b8f5042059d5f1ecea445894cbb2177bd14779d793c5cf1d6fe/streamlit_notebook-0.0.26-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f687f2ceb40ef6f7e568981361600998f7dd5acac4645a4a9797fcb72eb7ac72",
                "md5": "49acf66fb4127db47514cf23b916133b",
                "sha256": "f66b024f535e438283b87736d26938469f10b2fb900ed450b2ef3e8d80838c41"
            },
            "downloads": -1,
            "filename": "streamlit_notebook-0.0.26.tar.gz",
            "has_sig": false,
            "md5_digest": "49acf66fb4127db47514cf23b916133b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 277577,
            "upload_time": "2025-02-01T19:38:05",
            "upload_time_iso_8601": "2025-02-01T19:38:05.784821Z",
            "url": "https://files.pythonhosted.org/packages/f6/87/f2ceb40ef6f7e568981361600998f7dd5acac4645a4a9797fcb72eb7ac72/streamlit_notebook-0.0.26.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-01 19:38:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "B4PT0R",
    "github_project": "streamlit_notebook",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "streamlit-notebook",
            "specs": []
        }
    ],
    "lcname": "streamlit-notebook"
}
        
Elapsed time: 0.48088s