Top Related Projects
Jupyter Notebook Conversion
JupyterLab computational environment.
VS Code Jupyter extension
📘 The interactive computing suite for you! ✨
Create beautiful, publication-quality books and documents from computational content.
Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
Quick Overview
The fastai/nbdev
project is a tool that allows developers to create Python libraries directly from Jupyter Notebooks. It provides a streamlined workflow for building, testing, and publishing Python packages, making it easier to develop and maintain complex projects.
Pros
- Literate Programming:
nbdev
enables a literate programming approach, where code and documentation are tightly integrated within Jupyter Notebooks. - Rapid Prototyping: The notebook-driven development workflow allows for quick experimentation and iteration, speeding up the development process.
- Automated Documentation:
nbdev
automatically generates documentation from the Jupyter Notebooks, ensuring that the documentation stays up-to-date with the codebase. - Seamless Deployment: The project provides tools for building, testing, and publishing Python packages, simplifying the deployment process.
Cons
- Dependency on Jupyter Notebooks: The project is heavily reliant on Jupyter Notebooks, which may not be the preferred development environment for all developers.
- Learning Curve: Developers who are not familiar with Jupyter Notebooks may need to invest time in learning the tool and its associated workflows.
- Potential Performance Issues: Large Jupyter Notebooks can sometimes lead to performance issues, which may impact the development experience.
- Limited Tooling Integration: The project's focus on Jupyter Notebooks may limit its integration with other popular development tools and workflows.
Code Examples
Here are a few examples of how nbdev
can be used to create and manage Python libraries:
- Defining a Module:
# Notebook: my_module.ipynb
def say_hello(name):
"""
Say hello to the given name.
Args:
name (str): The name to greet.
Returns:
str: A greeting message.
"""
return f"Hello, {name}!"
- Exporting a Function:
# Notebook: my_module.ipynb
#export
def say_goodbye(name):
"""
Say goodbye to the given name.
Args:
name (str): The name to bid farewell.
Returns:
str: A farewell message.
"""
return f"Goodbye, {name}!"
- Running Tests:
# Notebook: test_my_module.ipynb
from my_module import say_hello, say_goodbye
def test_say_hello():
assert say_hello("Alice") == "Hello, Alice!"
def test_say_goodbye():
assert say_goodbye("Bob") == "Goodbye, Bob!"
Getting Started
To get started with fastai/nbdev
, follow these steps:
- Install the
nbdev
package:
pip install nbdev
- Create a new Jupyter Notebook and add the following code to define a module:
# Notebook: my_module.ipynb
#export
def say_hello(name):
"""
Say hello to the given name.
Args:
name (str): The name to greet.
Returns:
str: A greeting message.
"""
return f"Hello, {name}!"
- Run the
nbdev_build_lib
command to generate the Python package:
nbdev_build_lib
- Test the generated package:
from my_module import say_hello
print(say_hello("Alice")) # Output: "Hello, Alice!"
- (Optional) Configure the project settings and publish the package using the provided
nbdev
commands.
For more detailed instructions and advanced usage, please refer to the fastai/nbdev repository on GitHub.
Competitor Comparisons
Jupyter Notebook Conversion
Pros of nbconvert
- Widely adopted and well-established in the Jupyter ecosystem
- Supports conversion to multiple output formats (HTML, PDF, LaTeX, etc.)
- Extensive documentation and community support
Cons of nbconvert
- Primarily focused on notebook conversion, not full project development
- Limited built-in features for code quality and testing
- Requires additional tools for version control and collaboration
Code comparison
nbconvert:
!jupyter nbconvert --to html my_notebook.ipynb
nbdev:
!nbdev_build_lib
!nbdev_clean_nbs
!nbdev_build_docs
Key differences
- nbconvert is primarily a conversion tool, while nbdev is a full development system
- nbdev integrates testing, documentation, and version control more tightly
- nbconvert has broader format support, while nbdev focuses on Python library development
- nbdev emphasizes literate programming and notebook-driven development
- nbconvert is more suitable for one-off conversions, while nbdev is designed for ongoing project maintenance
Both tools serve different purposes within the Jupyter ecosystem, with nbconvert focusing on notebook conversion and nbdev providing a comprehensive development workflow for notebook-based projects.
JupyterLab computational environment.
Pros of JupyterLab
- More comprehensive IDE-like environment with file browser, text editor, and terminal
- Highly extensible with a rich ecosystem of extensions
- Supports multiple document types beyond notebooks (e.g., Markdown, CSV, images)
Cons of JupyterLab
- Steeper learning curve for new users
- Heavier resource usage, potentially slower for older machines
- Less focused on literate programming and code-to-docs workflow
Code Comparison
JupyterLab (Python cell in a notebook):
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
plt.show()
nbdev (Python in a notebook cell, with special comments):
#| export
def plot_sine_wave(x_range=(0, 10), num_points=100):
"Plot a sine wave using matplotlib"
x = np.linspace(*x_range, num_points)
y = np.sin(x)
plt.plot(x, y)
plt.show()
The nbdev example showcases its focus on creating exportable functions with documentation, while JupyterLab's example demonstrates its interactive data exploration capabilities.
VS Code Jupyter extension
Pros of vscode-jupyter
- Seamless integration with VS Code, providing a familiar IDE environment
- Robust debugging capabilities for Jupyter notebooks
- Extensive language support beyond Python (R, Julia, etc.)
Cons of vscode-jupyter
- Steeper learning curve for users new to VS Code
- Less focused on literate programming and documentation generation
- May require additional setup for advanced features
Code Comparison
vscode-jupyter:
# In a .ipynb file or Python Interactive window
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.show()
nbdev:
# In a .ipynb file
#hide
from nbdev.showdoc import *
def my_function(x, y):
"""Add two numbers together"""
return x + y
show_doc(my_function)
Key Differences
- vscode-jupyter focuses on notebook execution within VS Code
- nbdev emphasizes literate programming and documentation generation
- vscode-jupyter offers broader language support
- nbdev provides tools for creating Python libraries from notebooks
Use Cases
- vscode-jupyter: Ideal for data scientists working in VS Code
- nbdev: Best for developers creating Python libraries with extensive documentation
Both tools enhance the Jupyter notebook experience but cater to different workflows and priorities in the development process.
📘 The interactive computing suite for you! ✨
Pros of nteract
- More comprehensive interactive computing environment with support for multiple languages
- Offers a desktop application for a standalone notebook experience
- Provides a rich set of components for building custom notebook interfaces
Cons of nteract
- Steeper learning curve due to its broader scope and feature set
- May be overkill for users primarily focused on Python development
- Less integrated with software development workflows compared to nbdev
Code comparison
nteract (JavaScript):
import { ContentRef } from "@nteract/types";
import { actions } from "@nteract/core";
const contentRef: ContentRef = "some-content-ref";
dispatch(actions.fetchContent({ contentRef }));
nbdev (Python):
from nbdev.export import notebook2script
from nbdev.clean import clean_nb
notebook2script('my_notebook.ipynb')
clean_nb('my_notebook.ipynb')
Summary
nteract is a more comprehensive interactive computing platform supporting multiple languages and offering a desktop application. It provides rich components for building custom notebook interfaces but has a steeper learning curve. nbdev, on the other hand, is more focused on Python development and integrates better with software development workflows. The choice between the two depends on the specific needs of the project and the developer's preferences.
Create beautiful, publication-quality books and documents from computational content.
Pros of jupyter-book
- More comprehensive documentation and publishing features
- Supports multiple output formats (HTML, PDF, LaTeX)
- Integrates well with existing Jupyter ecosystem
Cons of jupyter-book
- Steeper learning curve for beginners
- Less focus on software development workflows
- May require additional tools for version control integration
Code comparison
nbdev:
#export
def say_hello(to):
"Say hello to somebody"
return f'Hello {to}!'
jupyter-book:
# _toc.yml
format: jb-book
root: intro
chapters:
- file: chapter1
- file: chapter2
The nbdev example shows a Python function with an export comment, while the jupyter-book example demonstrates a YAML configuration file for structuring the book's table of contents.
Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
Pros of Jupytext
- Lightweight and focused solely on notebook-script conversion
- Supports multiple programming languages (Python, R, Julia, etc.)
- Integrates well with version control systems
Cons of Jupytext
- Limited functionality beyond notebook-script conversion
- Requires manual setup and configuration for advanced use cases
- Less opinionated, which may lead to inconsistent project structures
Code Comparison
Jupytext:
# %% [markdown]
# # My Notebook
# This is a markdown cell
# %%
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3]})
nbdev:
# AUTOGENERATED! DO NOT EDIT! File to edit: notebooks/00_core.ipynb (unless otherwise specified).
__all__ = ['df']
# Cell
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3]})
Both tools aim to improve notebook workflows, but nbdev offers a more comprehensive solution for developing libraries and documentation from notebooks, while Jupytext focuses on seamless conversion between notebooks and script formats.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Getting Started
nbdev
is a notebook-driven development platform. Simply write
notebooks with lightweight markup and get high-quality documentation,
tests, continuous integration, and packaging for free!
nbdev
makes debugging and refactoring your code much easier than in
traditional programming environments since you always have live objects
at your fingertips. nbdev
also promotes software engineering best
practices because tests and documentation are first class.
- Documentation is automatically generated using
Quarto and hosted on GitHub
Pages. Docs support LaTeX, are searchable,
and are automatically hyperlinked (including out-of-the-box support
for many packages via
nbdev-index
) - Publish packages to PyPI and conda as well as tools to simplify
package releases. Python best practices are automatically followed,
for example, only exported objects are included in
__all__
- Two-way sync between notebooks and plaintext source code allowing you to use your IDE for code navigation or quick edits
- Tests written as ordinary notebook cells are run in parallel with a single command
- Continuous integration out-of-the-box with GitHub Actions that run your tests and rebuild your docs
- Git-friendly notebooks with Jupyter/Git hooks that clean unwanted metadata and render merge conflicts in a human-readable format
- ⦠and much more!
Install
nbdev works on macOS, Linux, and most Unix-style operating systems. It works on Windows under WSL, but not under cmd or Powershell.
You can install nbdev with pip:
pip install nbdev
⦠or with conda (or mamba):
conda install -c fastai nbdev
Note that nbdev
must be installed into the same Python environment
that you use for both Jupyter and your project.
How to use nbdev
The best way to learn how to use nbdev is to complete either the written walkthrough or video walkthrough:
Alternatively, thereâs a shortened version of the video
walkthrough with coding sections sped up
using the unsilence
Python library â itâs 27 minutes faster, but a bit
harder to follow.
You can also run nbdev_help
from the terminal to see the full list of
available commands:
!nbdev_help
nbdev_bump_version Increment version in settings.ini by one
nbdev_changelog Create a CHANGELOG.md file from closed and labeled GitHub issues
nbdev_clean Clean all notebooks in `fname` to avoid merge conflicts
nbdev_conda Create a `meta.yaml` file ready to be built into a package, and optionally build and upload it
nbdev_create_config Create a config file.
nbdev_docs Create Quarto docs and README.md
nbdev_export Export notebooks in `path` to Python modules
nbdev_filter A notebook filter for Quarto
nbdev_fix Create working notebook from conflicted notebook `nbname`
nbdev_help Show help for all console scripts
nbdev_install Install Quarto and the current library
nbdev_install_hooks Install Jupyter and git hooks to automatically clean, trust, and fix merge conflicts in notebooks
nbdev_install_quarto Install latest Quarto on macOS or Linux, prints instructions for Windows
nbdev_merge Git merge driver for notebooks
nbdev_migrate Convert all markdown and notebook files in `path` from v1 to v2
nbdev_new Create an nbdev project.
nbdev_prepare Export, test, and clean notebooks, and render README if needed
nbdev_preview Preview docs locally
nbdev_proc_nbs Process notebooks in `path` for docs rendering
nbdev_pypi Create and upload Python package to PyPI
nbdev_readme Create README.md from readme_nb (index.ipynb by default)
nbdev_release_both Release both conda and PyPI packages
nbdev_release_gh Calls `nbdev_changelog`, lets you edit the result, then pushes to git and calls `nbdev_release_git`
nbdev_release_git Tag and create a release in GitHub for the current version
nbdev_requirements Writes a `requirements.txt` file to `directory` based on settings.ini.
nbdev_sidebar Create sidebar.yml
nbdev_test Test in parallel notebooks matching `path`, passing along `flags`
nbdev_trust Trust notebooks matching `fname`
nbdev_update Propagate change in modules matching `fname` to notebooks that created them
nbdev_update_license Allows you to update the license of your project.
FAQ
Q: What is the warning âFound a cell containing mix of imports and computations. Please use separate cellsâ?
A: You should not have cells that are not exported, and contain a mix
of import
statements along with other code. For instance, donât do
this in a single cell:
import some_module
some_module.something()
Instead, split this into two cells, one which does import some_module
,
and the other which does some_module.something()
.
The reason for this is that when we create your documentation website,
we ensure that all of the signatures for functions you document are up
to date, by running the imports, exported cells, and
show_doc
functions
in your notebooks. When you mix imports with other code, that other code
will be run too, which can cause errors (or at least slowdowns) when
creating your website.
Q: Why is nbdev asking for root access? How do I install Quarto without root access?
A: When you setup your first project, nbdev will attempt to automatically download and install Quarto for you. This is the program that we use to create your documentation website.
Quartoâs standard installation process requires root access, and nbdev will therefore ask for your root password during installation. For most people, this will work fine and everything will be handled automatically â if so, you can skip over the rest of this section, which talks about installing without root access.
If you need to install Quarto without root access on Linux, first cd
to wherever you want to store it, then download
Quarto, and type:
dpkg -x quarto*.deb .
mv opt/quarto ./
rmdir opt
mkdir -p ~/.local/bin
ln -s "$(pwd)"/quarto/bin/quarto ~/.local/bin
To use this non-root version of Quarto, youâll need ~/.local/bin
in
your PATH
environment
variable.
(Alternatively, change the ln -s
step to place the symlink somewhere
else in your path.)
Q: Someone told me not to use notebooks for âseriousâ software development!
A: Watch this video. Donât worry, we
still get this too, despite having used nbdev
for a wide range of
âvery seriousâ software projects over the last three years, including
deep learning libraries, API
clients, Python language
extensions, terminal user
interfaces, and more!
Contributing
If you want to contribute to nbdev
, be sure to review the
contributions
guidelines.
This project adheres to fastaiâs code of
conduct.
By participating, you are expected to uphold this code. In general, we
strive to abide by generally accepted best practices in open-source
software development.
Make sure you have nbdev
âs git hooks installed by running
nbdev_install_hooks
in the cloned repository.
Copyright
Copyright © 2019 onward fast.ai, Inc. Licensed under the Apache License, Version 2.0 (the âLicenseâ); you may not use this projectâs files except in compliance with the License. A copy of the License is provided in the LICENSE file in this repository.
Top Related Projects
Jupyter Notebook Conversion
JupyterLab computational environment.
VS Code Jupyter extension
📘 The interactive computing suite for you! ✨
Create beautiful, publication-quality books and documents from computational content.
Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot