Skip to main content

ActivatedNotebookImporter

ActivatedNotebookImporter is a Python package developed and used internally by Activated AI (https://activated-ai.com) that allows you to import Jupyter notebooks as Python modules. This package is designed to seamlessly integrate Jupyter notebooks into your Python workflows.

Key Features

  • Import Jupyter notebooks as Python modules
  • Support for parameter substitution, enabling dynamic parameter setting
  • Ability to exclude specific cells from execution using tags
  • Automatic parameter detection from the first cell and cells tagged with "parameters"

Use Case

ActivatedNotebookImporter is particularly useful for workflows where you want to use Jupyter notebooks as reusable modules. Instead of converting your Jupyter notebooks to Python scripts, you can use them directly in your workflows:

  1. Set parameters using the params argument when importing the notebook
  2. Exclude specific cells in the notebook by tagging them with 'import-exclude'
  3. Import the notebook as a module
  4. Call functions from the imported module with your desired parameters
  5. Get the results directly, without intermediate steps

This approach allows for more flexible and maintainable code, keeping your exploratory work and reusable code closely aligned.

Installation

You can install ActivatedNotebookImporter using pip:

pip install activated-notebook-importer

Usage

Here's a basic example of how to use ActivatedNotebookImporter:

from activated_notebook_importer import import_notebook

# Import a notebook with parameter substitution
module = import_notebook('path/to/your/notebook.ipynb', 
                         {'param1': 'value1', 'param2': 'value2'})

# Assuming your notebook defines a 'my_function' function
result = module.my_function()
print(result)

In your Jupyter notebook:

# In the first cell or in cells tagged with "parameters"
param1 = 'default1'
param2 = 'default2'

# In a code cell
def my_function(param1=param1, param2=param2):
    # Your code here
    return some_result

# In another cell, tag this with 'import-exclude' in Jupyter
# This cell won't be executed when the notebook is imported
my_function()

Note:

  • The first cell of the notebook is assumed to contain parameters, which can be overwritten with the params argument when importing.
  • You can also tag cells with the "parameters" tag for them to be considered as parameter cells.

One potential use case is for hyperparameter search in machine learning models:

from activated_notebook_importer import import_notebook

hyperparameters = [
    {'learning_rate': 0.01, 'batch_size': 32},
    {'learning_rate': 0.001, 'batch_size': 64},
    {'learning_rate': 0.0001, 'batch_size': 128}
]

results = []
for params in hyperparameters:
    module = import_notebook('model_training.ipynb', params)
    results.append(module.train())

# Process and analyze results

Internal Use at Activated AI

ActivatedNotebookImporter is a tool used in various workflows at Activated AI. We use it to:

  • Integrate notebook-based code into larger systems
  • Easily reuse and parameterize notebook code
  • Maintain consistency between our exploratory notebooks and reusable code

By using this tool, we've improved our ability to leverage work done in Jupyter notebooks in our broader Python ecosystem.

Contributing

We welcome contributions! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About Activated AI

ActivatedNotebookImporter is developed and maintained by Activated AI. Visit our website at https://activated-ai.com to learn more about our AI research and development.

Metadata

Release files for activated-notebook-importer 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for activated-notebook-importer 1.0.0
File Size Uploaded
activated_notebook_importer-1.0.0.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for activated-notebook-importer 1.0.0
File Interpreter ABI Platform
activated_notebook_importer-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 kB

Release files / activated_notebook_importer-1.0.0.tar.gz

Download URL activated_notebook_importer-1.0.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6e46e306a5ad0ae92b1e1d51ef1c9b15522043f4820d79fdbb99af3f98a8d0ff
BLAKE2b-256 checksum
How to use checksums
e8fcc7d835229299db1e8bc82d3c97e9c649ee42b6223d185a51db344756dbd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.1

Release files / activated_notebook_importer-1.0.0-py3-none-any.whl

Download URL activated_notebook_importer-1.0.0-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b34c26a23ae2cf26f0d010d0f795ff5e81bf967f18cc48c57cbf98adfcb0ed1
BLAKE2b-256 checksum
How to use checksums
790ac94bcb6750d5e3e59315909aba69e53ec3d55514c4459b3fc651bc1142a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.1

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page