Giter Club home page Giter Club logo

nb2py's Introduction

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]
  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

CLI Tool

Installation

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

pip install cli-nb2py

Usage

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

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 file for more details.

Contact

nb2py's People

Contributors

bardiakh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.