Skip to main content

This package manages the conversion between .ipynb (Jupyter Notebook) and .py (Python script) files, which Databricks automatically performs when exporting notebooks.

Project description

nb2dbpy

A command-line tool for converting between Databricks .py script files and .ipynb notebooks. This tool was build in collaboration with Yoyodyne-Data-Science, thank you for setting the foundations for this tool.

Overview

When working with Databricks, notebooks are often exported as .py files for easier version control and collaboration. However, these scripts may not be ideal for local development in VS Code. nb2dbpy bridges this gap by enabling seamless conversion between Databricks-formatted Python scripts and Jupyter notebooks directly from the command line.

Features

  • Bidirectional Conversion: Convert from .py scripts to .ipynb notebooks and vice versa.
  • Command-Line Interface: Perform conversions easily without writing additional code.
  • Databricks Compatibility: Handles Databricks-specific syntax and comments.
  • Preserves Cell Structure: Maintains code and markdown cells accurately during conversion.

Installation

Clone the repository and install the required dependencies:

pip install nb2dbpy

Usage

Use nb2dbpy from the command line to perform conversions.

Converting from .py to .ipynb

To convert a Databricks-exported Python script to a Jupyter notebook:

nb2dbpy your_python_script.py

This command will generate your_python_script.ipynb in the same directory.

Converting from .ipynb to .py

To convert a Jupyter notebook into a Databricks-compatible Python script:

nb2dbpy your_notebook.ipynb

This will create your_notebook.py, ready for import into Databricks.

Specifying Output Files

You can specify a custom output file name using the -o or --output option:

nb2dbpy input_file.py -o custom_output.ipynb

Overwriting Existing Files

If the output file already exists, the tool will prompt you before overwriting:

Warning: File <output file> already exists.
Do you want to overwrite it? (y/n):
Enter y to overwrite or n to cancel the operation.

Examples

Example 1: Converting a Databricks Script to a Notebook

Suppose you have a file analysis.py exported from Databricks. To convert it to a Jupyter notebook:

nb2dbpy analysis.py

Open analysis.ipynb with VS Code to continue your work locally.

Example 2: Converting a Notebook for Databricks

You have developed a notebook experiment.ipynb and now want to run it in Databricks:

nb2dbpy experiment.ipynb

Upload the resulting experiment.py to your Databricks workspace.

Limitations

  • Advanced notebook features like interactive widgets are not supported.

License

This project is licensed under the MIT License.

Contributions

Contributions are welcome! Please open issues or submit pull requests for improvements and bug fixes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nb2dbpy-0.0.3-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file nb2dbpy-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: nb2dbpy-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for nb2dbpy-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cca680759a4febbbe955b7b431b86611cbdd1c93dfe5849111d1edbe37b5cb27
MD5 d8cce8ff30b055cb4820e20744901b35
BLAKE2b-256 224c8aadc8f7cf030d38cdab384b8b31d31052325c16b146fd8e136ab5c28eee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page