Skip to main content

A Python package providing helper functions to programmatically import Jupyter notebook content into Cloud platforms via REST APIs.

Reason this release was yanked:

Fabric API call error handling issue.

Project description

Code2cloudNB

A Python package providing helper functions to programmatically import Jupyter notebook content into Azure Databricks, Azure Synapse and Microsoft Fabric workspaces via REST APIs.

Features

  • Create folders and import Jupyter notebooks into Azure Databricks workspace.
  • Import Jupyter notebooks into Azure Synapse Analytics workspace with support for Big Data Pools.
  • Create folders and import Jupyter notebooks into Microsoft Fabric workspace, linked to Azure Fabric Capacity.
  • Handles authentication using Personal Access Tokens (PAT) for Databricks, Azure AD DefaultAzureCredential for Synapse and Azure AD ManagedIdentityCredential for Fabric.
  • Returns detailed responses for success and error scenarios.

Installation

Install via PyPI once published:

pip install Code2cloudNB

Usage

Importing a notebook into Azure Databricks

import base64
from Code2cloudNB import import_code_to_databricks

# Your Databricks workspace info
host = "https://<databricks-instance>"
token = "<your-databricks-pat>"
domain_name = "<your-domain-or-username>"
target_path = "target/folder/path"
filename = "my_notebook"

# Load your notebook JSON file content and encode to base64
with open("notebook.ipynb", "rb") as f:
    notebook_content = f.read()
encoded_string = base64.b64encode(notebook_content).decode()

response = import_code_to_databricks(host, token, domain_name, target_path, filename, encoded_string)

print(response)

Importing a notebook into Azure Synapse Analytics

from Code2cloudNB import import_code_to_synapse
import json

wName = "<your-synapse-workspace-name>"
target_path = "target_folder"
filename = "my_notebook"
pool_name = "<your-big-data-pool-name>"
api_version = "2021-06-01" # example API version

# Load notebook JSON content as Python dict
with open("notebook.ipynb", "r") as f:
    notebook_json = json.load(f)

response = import_code_to_synapse(wName, target_path, filename, pool_name, notebook_json, api_version)

print(response)

Importing a notebook into Microsoft Fabric

import base64
from Code2cloudNB import import_code_to_fabric

wID = "<your-fabric-workspace-id>"
target_path = "<target-folder>"
filename = "my_notebook"
api_version = "v1" # example API version

# Load your notebook JSON file content and encode to base64
with open("notebook.ipynb", "rb") as f:
    notebook_content = f.read()
encoded_string = base64.b64encode(notebook_content).decode('utf-8')

response = import_code_to_fabric(wID, target_path, filename, api_version, encoded_string)

print(response)

Prerequisites

  • For Databricks import:

    • A valid Personal Access Token (PAT) with workspace permissions.
    • Databricks workspace URL.
  • For Synapse import:

  • For Fabric import:

    • Azure environment or VM's Managed Identity configured for Azure authentication.
    • An active(running) Azure Fabric Capacity, linked to the Fabric workspace.
    • azure-identity Python package installed for ManagedIdentityCredential support.
    • Appropriate Role assignments for accessing Fabric workspace :
      • create an Azure Security Group.
      • add your VM's object/principal ID (Managed Identity) as the member of the group and keep yourself as the owner.
      • under the Fabric's manage workspaces tab, click add people + group, add your Security Group and grant it the Contributor role.
      • give it some time (~10-20mins) to propagate these permissions.
    • [Resource]
pip install azure-identity requests

Error Handling

Each of the functions return dictionaries including HTTP status codes, results and error messages if any operation fails. Use these to troubleshoot or log issues.

License

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

Contributing

Feel free to open issues or submit pull requests to improve the package.

Author

Antick Mazumder — antick.majumder@gmail.com

Project details


Download files

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

Source Distribution

code2cloudnb-0.1.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

code2cloudnb-0.1.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file code2cloudnb-0.1.2.tar.gz.

File metadata

  • Download URL: code2cloudnb-0.1.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.1

File hashes

Hashes for code2cloudnb-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1818e343f17831a5690e1114bcfda6e17fd78b6faae6662adaa631835e93177f
MD5 182f43f73a67c60742b1e155494987bc
BLAKE2b-256 9eb7eb9766b8b5daf73e4a18fc642a7ad4fcdce74e2e6a2eba8bc96ee6db6cab

See more details on using hashes here.

File details

Details for the file code2cloudnb-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: code2cloudnb-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.1

File hashes

Hashes for code2cloudnb-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5d011e51b142471e012a3b798365b564abafffeb0cc1ceb401af32d2d827a4b0
MD5 8924271db9b23da3011a5c5834c1593a
BLAKE2b-256 128235ca78a2749c446b994ed4df97683c9b5ac8daf0f2d95eb80a6816ee81de

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