cli-nb2py


Namecli-nb2py JSON
Version 0.7.4 PyPI version JSON
download
home_pagehttps://github.com/BardiaKh/nb2py
SummaryReliable Notebook to Python converter
upload_time2024-05-03 19:14:31
maintainerNone
docs_urlNone
authorBardia Khosravi
requires_python>=3.6
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # nb2py

`nb2py` is a comprehensive tool designed to convert Jupyter Notebooks (.ipynb files) into Python scripts (.py files). This tool simplifies the process of transforming interactive notebook cells into a structured Python script, automatically separating import statements and wrapping executable code within an `if __name__ == '__main__':` guard to maintain the script's portability and usability.

This tool has two versions, a **command-line** version based on python and a **vscode extension**.

## Features

- **VSCode Extension**: A one-click solution for converting notebooks to python files.
- **Command-Line Simplicity**: Offers a straightforward command-line interface for easy conversion of notebooks to Python scripts.
- **Import Optimization**: Automatically moves all import statements to the top of the generated Python script.
- **Executable Wrap**: Wraps all executable code within an `if __name__ == '__main__':` block, ensuring that the script can be imported without unintended execution.
- **Markdown Conversion**: Converts markdown cells into Python comments, preserving the notebook's documentation in the script.
- **Handling Multiline Strings**: Converts `""" """` to multiple `" "\` so there is no spacing issues. Especially useful for prompting LLMs. (added in v0.7.0)

## VSCode Extension 

### Installation

You can install the `nb2py` extension directly from the Visual Studio Code Marketplace:

1. Open VS Code.
2. Navigate to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window.
3. Search for `nb2py`. [if not found here is the [link](https://marketplace.visualstudio.com/items?itemName=BardiaKhosravi.nb2py)]
4. Click on the Install button.

## Usage

After installation, open the Jupyter Notebook you wish to convert. You'll see a new icon in the editor title bar that looks like a Python logo. Click this icon to convert the currently open notebook.

The converted Python script will be saved in the same directory as the notebook with the extension of `.py`.

![Convert Notebook to Python Script Button](vscode_nb2py/assets/screenshot.png)

## CLI Tool 

### Installation

To install `nb2py`, run the following setup script. Ensure you have Python 3.6 or later installed on your system.

```bash
pip install cli-nb2py
```

### Usage

To convert a Jupyter Notebook to a Python script, use the following command:

```bash
nb2py input_notebook.ipynb output_script.py
```

If the output file name is not provided, `nb2py` will generate a Python script with the same name as the input notebook (replacing the `.ipynb` extension with `.py`).

## License

`nb2py` is released under the MIT License. See the [LICENSE](LICENSE) file for more details.

## Contact

- Developer: Bardia Khosravi
- Email: bardiakhosravi95@gmail.com
- GitHub: [https://github.com/BardiaKh/nb2py](https://github.com/BardiaKh/nb2py)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/BardiaKh/nb2py",
    "name": "cli-nb2py",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Bardia Khosravi",
    "author_email": "bardiakhosravi95@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6d/65/18919dec10a533832db08fd0b149cfb39e7961cf9537e262064dcaa0f5de/cli_nb2py-0.7.4.tar.gz",
    "platform": null,
    "description": "# nb2py\n\n`nb2py` is a comprehensive tool designed to convert Jupyter Notebooks (.ipynb files) into Python scripts (.py files). This tool simplifies the process of transforming interactive notebook cells into a structured Python script, automatically separating import statements and wrapping executable code within an `if __name__ == '__main__':` guard to maintain the script's portability and usability.\n\nThis tool has two versions, a **command-line** version based on python and a **vscode extension**.\n\n## Features\n\n- **VSCode Extension**: A one-click solution for converting notebooks to python files.\n- **Command-Line Simplicity**: Offers a straightforward command-line interface for easy conversion of notebooks to Python scripts.\n- **Import Optimization**: Automatically moves all import statements to the top of the generated Python script.\n- **Executable Wrap**: Wraps all executable code within an `if __name__ == '__main__':` block, ensuring that the script can be imported without unintended execution.\n- **Markdown Conversion**: Converts markdown cells into Python comments, preserving the notebook's documentation in the script.\n- **Handling Multiline Strings**: Converts `\"\"\" \"\"\"` to multiple `\" \"\\` so there is no spacing issues. Especially useful for prompting LLMs. (added in v0.7.0)\n\n## VSCode Extension \n\n### Installation\n\nYou can install the `nb2py` extension directly from the Visual Studio Code Marketplace:\n\n1. Open VS Code.\n2. Navigate to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window.\n3. Search for `nb2py`. [if not found here is the [link](https://marketplace.visualstudio.com/items?itemName=BardiaKhosravi.nb2py)]\n4. Click on the Install button.\n\n## Usage\n\nAfter installation, open the Jupyter Notebook you wish to convert. You'll see a new icon in the editor title bar that looks like a Python logo. Click this icon to convert the currently open notebook.\n\nThe converted Python script will be saved in the same directory as the notebook with the extension of `.py`.\n\n![Convert Notebook to Python Script Button](vscode_nb2py/assets/screenshot.png)\n\n## CLI Tool \n\n### Installation\n\nTo install `nb2py`, run the following setup script. Ensure you have Python 3.6 or later installed on your system.\n\n```bash\npip install cli-nb2py\n```\n\n### Usage\n\nTo convert a Jupyter Notebook to a Python script, use the following command:\n\n```bash\nnb2py input_notebook.ipynb output_script.py\n```\n\nIf the output file name is not provided, `nb2py` will generate a Python script with the same name as the input notebook (replacing the `.ipynb` extension with `.py`).\n\n## License\n\n`nb2py` is released under the MIT License. See the [LICENSE](LICENSE) file for more details.\n\n## Contact\n\n- Developer: Bardia Khosravi\n- Email: bardiakhosravi95@gmail.com\n- GitHub: [https://github.com/BardiaKh/nb2py](https://github.com/BardiaKh/nb2py)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Reliable Notebook to Python converter",
    "version": "0.7.4",
    "project_urls": {
        "Homepage": "https://github.com/BardiaKh/nb2py"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7b97076b0ada8218abfc477d7a6b313b7a56d0474108fe0eb84f4a24df613320",
                "md5": "e66a580a4f51e1ff0772d39b823de2d0",
                "sha256": "22f63752e606fb0e99141f639a562bde27aec2fddad653bf390d92c7e7a53b4c"
            },
            "downloads": -1,
            "filename": "cli_nb2py-0.7.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e66a580a4f51e1ff0772d39b823de2d0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 5287,
            "upload_time": "2024-05-03T19:14:29",
            "upload_time_iso_8601": "2024-05-03T19:14:29.287464Z",
            "url": "https://files.pythonhosted.org/packages/7b/97/076b0ada8218abfc477d7a6b313b7a56d0474108fe0eb84f4a24df613320/cli_nb2py-0.7.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6d6518919dec10a533832db08fd0b149cfb39e7961cf9537e262064dcaa0f5de",
                "md5": "83a03df5c9915efbbca391fadf8bacbe",
                "sha256": "55d5f1cc6c2889539bc4ecf8e5621048df9e394eb9c1e4e320d4d0e138c4c2da"
            },
            "downloads": -1,
            "filename": "cli_nb2py-0.7.4.tar.gz",
            "has_sig": false,
            "md5_digest": "83a03df5c9915efbbca391fadf8bacbe",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4815,
            "upload_time": "2024-05-03T19:14:31",
            "upload_time_iso_8601": "2024-05-03T19:14:31.061368Z",
            "url": "https://files.pythonhosted.org/packages/6d/65/18919dec10a533832db08fd0b149cfb39e7961cf9537e262064dcaa0f5de/cli_nb2py-0.7.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-03 19:14:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "BardiaKh",
    "github_project": "nb2py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cli-nb2py"
}
        
Elapsed time: 0.26115s