### Install uv and Preview Notebook Source: https://nbpreview.readthedocs.io/en/latest/installation.html Installs uv and then uses it to preview a notebook. Ensure uv is installed before running the second command. ```shell % curl -LsSf https://astral.sh/uv/install.sh | sh ``` ```shell % curl https://raw.githubusercontent.com/paw-lu/nbpreview/refs/heads/main/docs/example_notebook_cells/hero_notebook.ipynb | uvx nbpreview ``` -------------------------------- ### Install Development Requirements Source: https://nbpreview.readthedocs.io/en/latest/contributing.html Install the package with development requirements using Poetry. ```bash $ poetry install ``` -------------------------------- ### Run Command-Line Interface Source: https://nbpreview.readthedocs.io/en/latest/contributing.html Execute the nbpreview command-line interface after installing development requirements. ```bash $ poetry run nbpreview ``` -------------------------------- ### Install nbpreview with uv Source: https://nbpreview.readthedocs.io/en/latest/installation.html Installs nbpreview using the uv package manager. This is the recommended method for ease of use. ```shell % uv tool install nbpreview ``` -------------------------------- ### Run Interactive Python Session Source: https://nbpreview.readthedocs.io/en/latest/contributing.html Start an interactive Python session after installing development requirements. ```bash $ poetry run python ``` -------------------------------- ### Install nbpreview with pip Source: https://nbpreview.readthedocs.io/en/latest/installation.html Installs nbpreview using pip, a standard Python package installer. Use this if you prefer not to use uv. ```python % python -m pip install nbpreview ``` -------------------------------- ### Markdown rendering example Source: https://nbpreview.readthedocs.io/en/latest/features.html Example of Markdown content including tables, math equations, and images rendered by nbpreview. ```markdown # Lorem ipsum Lorem ipsum dolor sit amet, consectetur **adipiscing** elit, sed do eiusmod tempor incididunt ut labore et dolore magna [aliqua](https://github.com/paw-lu/nbpreview). $$ \alpha \sim \text{Normal(0, 1)} $$ _Ut enim ad minim veniam_, quis nostrud exercitation ullamco Excepteur sint occaecat `cupidatat` non proident, sunt in culpa qui. ![Turtle](emoji_u1f422.png) ``` -------------------------------- ### Install Pre-commit Git Hook Source: https://nbpreview.readthedocs.io/en/latest/contributing.html Install pre-commit as a Git hook for linting and code formatting checks before committing. ```bash $ nox --session=pre-commit -- install ``` -------------------------------- ### Markdown rendering example Source: https://nbpreview.readthedocs.io/en/latest/_sources/features.md.txt Example of markdown content including headers, bold text, links, math equations, code blocks, and tables. ```markdown # Lorem ipsum Lorem ipsum dolor sit amet, consectetur **adipiscing** elit, sed do eiusmod tempor incididunt ut labore et dolore magna [aliqua](https://github.com/paw-lu/nbpreview). $$ \alpha \sim \text{Normal(0, 1)} $$ _Ut enim ad minim veniam_, quis nostrud exercitation ullamco Excepteur sint occaecat `cupidatat` non proident, sunt in culpa qui. ![Turtle](emoji_u1f422.png) ## At ultrices ```python def add(x: float, y: float) -> float: """Add two numbers.""" return x + y ``` | Lorep | ipsum | doret | | ----- | ----- | ----- | | 1 | 2 | 3 | | 4 | 5 | 6 | ``` -------------------------------- ### Render Pandas DataFrame with nbpreview Source: https://nbpreview.readthedocs.io/en/latest/features.html Use the nbpreview command-line tool to render a Pandas DataFrame within a notebook. This example demonstrates creating a DataFrame with multi-level columns and index, which nbpreview then displays as a formatted table. ```bash % nbpreview --theme material notebook.ipynb ``` ```python pd.DataFrame( [ [38.0, 2.0, 18.0, 22.0], [19, 439, 6, 452], ], index=pd.Index( ["Tumour (Positive)", "Non-Tumour (Negative)"], name="Actual Label:", ), columns=pd.MultiIndex.from_product( (["Decision Tree", "Regression"], ["Tumour", "Non-Tumour"]), names=["Model:", "Predicted:"], ), ) ``` -------------------------------- ### Render VegaLite visualization Source: https://nbpreview.readthedocs.io/en/latest/features.html Example of a VegaLite chart definition used within a notebook cell. ```json ╭───────────────────────────────────────────────────────────────────────╮ [6]: │ VegaLite( │ │ { │ │ "$schema": "https://vega.github.io/schema/vega-lite/v5.json", │ │ "width": 300, │ │ "height": 200, │ │ "data": { │ │ "url": "https://raw.githubusercontent.com/vega/vega-data… │ │ }, │ │ "mark": "area", │ │ "encoding": { │ │ "x": {"timeUnit": "yearmonth", "field": "date", "axis": … │ │ "y": {"aggregate": "sum", "field": "count"}, │ │ "color": {"field": "series", "scale": {"scheme": "catego… │ │ }, │ │ } │ ``` -------------------------------- ### Display DataFrame output Source: https://nbpreview.readthedocs.io/en/latest/features.html Example of a DataFrame output rendered in the terminal with a link to view the full HTML. ```text ╭───────────────────────────────────────────────────────────────────────╮ [20]: │ df.head() │ ╰───────────────────────────────────────────────────────────────────────╯ [20]: 🌐 Click to view HTML [20]: sepalLength sepalWidth petalLength petalWidth species ─────────────────────────────────────────────────────────────────── 0 5.1 3.5 1.4 0.2 setosa 1 4.9 3.0 1.4 0.2 setosa 2 4.7 3.2 1.3 0.2 setosa 3 4.6 3.1 1.5 0.2 setosa 4 5.0 3.6 1.4 0.2 setosa ``` -------------------------------- ### Display Seaborn plot output Source: https://nbpreview.readthedocs.io/en/latest/features.html Example of a Seaborn plot rendered in the terminal with a link to view the image. ```text ╭───────────────────────────────────────────────────────────────────────╮ [21]: │ df.pipe( │ │ (sns.kdeplot, "data"), │ │ x="petalLength", │ │ hue="species", │ │ fill=True, │ │ alpha=1, │ │ ) │ ╰───────────────────────────────────────────────────────────────────────╯ [21]: 🖼 Click to view Image ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▄▄▄ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▄ ▄ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▄ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀ ▀▀▀▀ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀ ▀▀ ▀▀ ▀▄▀ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀ ▀ ▀▀▀▀▀ ▄▄▄ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▄ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▄ ▄ ▄ ▄ ▄ ▄ ▄ ▀ ▀ ▀▀ ▀ ▀ ▀ ▄▄▄▄▄▄▄▄▄▄▄ ▀▀▀▀▀▀▀▀▀▀ ``` -------------------------------- ### Display nbpreview Help and Environment Variables Source: https://nbpreview.readthedocs.io/en/latest/configure.html Run this command to view the help message for nbpreview, which includes available options, their descriptions, and associated environment variables. ```bash % nbpreview --help ``` -------------------------------- ### Preview Notebook with Themes Source: https://nbpreview.readthedocs.io/en/latest/features.html Commands to render a notebook file using specific color themes. ```bash % nbpreview --theme monokai notebook.ipynb ``` ```bash % nbpreview --theme paraiso-light notebook.ipynb ``` ```bash % nbpreview --theme rainbow_dash notebook.ipynb ``` -------------------------------- ### View help and environment variables Source: https://nbpreview.readthedocs.io/en/latest/_sources/configure.md.txt Display the help message to identify available options and their associated environment variables. ```console % nbpreview --help â‹® -t, --theme The theme to use for syntax highlighting. Call '--list-themes' to preview all available themes. [env var: NBPREVIEW_THEME; default: dark] ``` -------------------------------- ### Display nbpreview help information Source: https://nbpreview.readthedocs.io/en/latest/_sources/usage.rst.txt Run this command to view all available options, their effects, accepted values, and related environmental variables for nbpreview. ```console % nbpreview --help ``` -------------------------------- ### Run nbpreview from the command line Source: https://nbpreview.readthedocs.io/en/latest/index.html Execute the nbpreview command with specific theme and image drawing settings. ```bash nbpreview --theme material --image-drawing braille notebook.ipynb ``` -------------------------------- ### Render a notebook with nbpreview Source: https://nbpreview.readthedocs.io/en/latest/features.html Command-line usage for rendering a notebook with a specific theme and image drawing mode. ```bash nbpreview --theme material --image-drawing character notebook.ipynb ``` -------------------------------- ### Render Vega-Lite Chart with nbpreview Source: https://nbpreview.readthedocs.io/en/latest/features.html Use the nbpreview command-line tool to render a Vega-Lite chart from a notebook. Specify the theme and image drawing mode. The output includes a static preview and a link to an interactive version. ```bash % nbpreview --theme material --image-drawing character notebook.ipynb ╭───────────────────────────────────────────────────────────────────────╮ [12]: │ VegaLite( │ { │ "$schema": "https://vega.github.io/schema/vega-lite/v5.json", │ "description": "Google's stock price over time.", │ "data": {"url": "https://raw.githubusercontent.com/vega/vega… │ "transform": [{"filter": "datum.symbol==='GOOG'"}], │ "mark": { │ "type": "area", │ "line": {"color": "darkgreen"}, │ "color": { │ "x1": 1, │ "y1": 1, │ "x2": 1, │ "y2": 0, │ "gradient": "linear", │ "stops": [ │ {"offset": 0, "color": "white"}, │ {"offset": 1, "color": "darkgreen"}, │ ], │ }, │ }, │ "encoding": { │ "x": {"field": "date", "type": "temporal"}, │ "y": {"field": "price", "type": "quantitative"}, │ }, │ } │ ) ╰───────────────────────────────────────────────────────────────────────╯ 📊 Click to view Vega chart ?? ? ? ? ? ? G ? P?P ? ??G ? !??P G G PP ? G??? G ?P ? P??? G? ?? ? ? : !!!!? ?!! G!!P? ? P: ?!!!!!!G !!P !!!!! ? ?!!G:P!!!!!!!! !!!P P!!!!! G ? : !!!!!!!!!!!!!!!!!!!P :!!!!!!! @ P ?? ? P! GGP G!!!!!!!!!!!!!!!!!!!P !!!!!!!!! ! ? G!!G!!!!?!!!!!!!!!!!!!!!!!!!!!! P!!!!!!!!! ? ?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!G G!!!!!!!!!! ? G::::::::::::::::::::::::::::::::G:::::::::::: ? GPG::::::::::::::::::::::::::::::::!::::::::::::: ? G::::::::::::::::::::::::::::::::::::::::::::::::: ? !::::::::::::::::::::::::::::::::::::::::::::::::: P:!!:??:::P:P:::::::::::::::::::::::::::::::::::::::::::::::::: ?:::::::::::::::::::::::::::::::::::::::::::::::::::::::: ?G::::::::::::::::::::::::::::::::::::::::::::::::::::::: G : : : P ?@ : P! : :?G: ! ?@ !G ?@ @? :! : ``` -------------------------------- ### Run Full Test Suite with Nox Source: https://nbpreview.readthedocs.io/en/latest/contributing.html Execute the entire test suite for the project using Nox. ```bash $ nox ``` -------------------------------- ### fgrep with plain output Source: https://nbpreview.readthedocs.io/en/latest/_sources/features.md.txt Demonstrates how nbpreview's plain output improves readability when piping to other command-line tools like fgrep. ```console % fgrep parietal notebook.ipynb ``` ```console % nbpreview notebook.ipynb | fgrep parietal ``` -------------------------------- ### Render multiple notebooks Source: https://nbpreview.readthedocs.io/en/latest/_sources/features.md.txt Provide multiple file paths or a glob pattern to render several notebooks at once. ```console % nbpreview notebook1.ipynb notebook2.ipynb ``` ```console % nbpreview notebooks/*.ipynb ``` -------------------------------- ### Set theme via command-line argument Source: https://nbpreview.readthedocs.io/en/latest/_sources/configure.md.txt Specify the theme directly when running the nbpreview command. ```console % nbpreview --theme='material' notebook.ipynb ``` -------------------------------- ### Run nbpreview with a notebook file Source: https://nbpreview.readthedocs.io/en/latest/_sources/usage.rst.txt Use this command to preview a single Jupyter notebook file. The `FILE` argument expects the path to the notebook. ```console % nbpreview notebook.ipynb ``` -------------------------------- ### List Available Themes Source: https://nbpreview.readthedocs.io/en/latest/features.html Command to display all supported themes for the terminal preview. ```bash --list-themes ``` -------------------------------- ### Render notebooks using a glob pattern Source: https://nbpreview.readthedocs.io/en/latest/features.html Use a glob pattern to specify a set of notebook files for rendering. ```bash % nbpreview notebooks/*.ipynb ``` -------------------------------- ### Render Notebook Tracebacks with nbpreview Source: https://nbpreview.readthedocs.io/en/latest/features.html Displays a notebook file using the material theme, which includes syntax-highlighted traceback rendering. ```bash % nbpreview --theme material notebook.ipynb ╭────────────────────────────────────────────────────────────────────────╮ [1]: │ 1 / 0 │ ╰────────────────────────────────────────────────────────────────────────╯ ------------------------------------------------------------------------… ZeroDivisionError Traceback (most recent call last) in ----> 1 1 / 0 ZeroDivisionError: division by zero ``` -------------------------------- ### Search notebook content with fgrep (nbpreview preprocessed) Source: https://nbpreview.readthedocs.io/en/latest/features.html Shows how nbpreview can preprocess a notebook before piping to fgrep, resulting in more human-readable output. ```bash % nbpreview notebook.ipynb | fgrep parietal ``` -------------------------------- ### Render notebook with multi-language support Source: https://nbpreview.readthedocs.io/en/latest/features.html Shows detection and rendering of non-Python languages like Julia. ```bash % nbpreview --theme material notebook.ipynb ╭────────────────────────────────────────────────────────────────────────╮ [2]: │ function printx(x) │ │ println("x = $x") │ │ return nothing │ │ end │ ╰────────────────────────────────────────────────────────────────────────╯ ``` -------------------------------- ### List available themes Source: https://nbpreview.readthedocs.io/en/latest/_sources/features.md.txt Use the --list-themes option to view all available syntax highlighting themes and their appearance in the terminal. ```console % nbpreview --list-themes ``` -------------------------------- ### Set nbpreview Theme via Command Line Source: https://nbpreview.readthedocs.io/en/latest/configure.html Use this command to set the theme for syntax highlighting when running nbpreview. This is a temporary setting for a single execution. ```bash % nbpreview --theme='material' notebook.ipynb ``` -------------------------------- ### List Available Nox Sessions Source: https://nbpreview.readthedocs.io/en/latest/contributing.html Display all available Nox sessions that can be run. ```bash $ nox --list-sessions ``` -------------------------------- ### Render notebook with cell magic Source: https://nbpreview.readthedocs.io/en/latest/features.html Demonstrates syntax highlighting adjustment for bash cell magic. ```bash % nbpreview --theme material notebook.ipynb ╭────────────────────────────────────────────────────────────────────────╮ [ ]: │ %%bash │ │ for file in *.csv; do │ │ echo "$file" │ │ awk -F ',' '{print $5}' "$file" | sort | uniq -c │ │ done │ ╰────────────────────────────────────────────────────────────────────────╯ ``` -------------------------------- ### Search notebook content with fgrep (default output) Source: https://nbpreview.readthedocs.io/en/latest/features.html Demonstrates the default output of fgrep when searching a notebook file, which can be difficult to parse due to decorations. ```bash % fgrep parietal notebook.ipynb ``` -------------------------------- ### Render notebook from stdin Source: https://nbpreview.readthedocs.io/en/latest/_sources/features.md.txt Pipe notebook content from stdin to nbpreview for rendering. Useful for processing notebooks from web sources or filtering cells. ```console % curl https://raw.githubusercontent.com/paw-lu/nbpreview/main/tests/unit/assets/notebook.ipynb | nbpreview ``` -------------------------------- ### Apply Syntax Highlighting Themes Source: https://nbpreview.readthedocs.io/en/latest/features.html Use the --theme option to specify a theme for notebook rendering. Themes like 'material', 'dracula', and 'one-dark' can be applied to change the appearance of code blocks. ```bash % nbpreview --theme material notebook.ipynb ``` ```bash % nbpreview --theme dracula notebook.ipynb ``` ```bash % nbpreview --theme one-dark notebook.ipynb ``` -------------------------------- ### Set NBPREVIEW_PLAIN environment variable Source: https://nbpreview.readthedocs.io/en/latest/_sources/features.md.txt Configure the default rendering to be plain by setting the NBPREVIEW_PLAIN environment variable. ```console % export NBPREVIEW_PLAIN=1 ``` -------------------------------- ### Notebook from File Source: https://nbpreview.readthedocs.io/en/latest/reference.html Create a Notebook object from a Jupyter Notebook file with various customization options. ```APIDOC ## Notebook from File ### Description Create a Notebook from a notebook file. ### Method from_file ### Endpoint N/A (Class method) ### Parameters #### Path Parameters - **file** (Union[Path, IO[AnyStr], KeepOpenFile]) - Required - A path to a Jupyter Notebook file. #### Query Parameters - **theme** (str) - Optional - The theme to use for syntax highlighting. May be 'ansi_light', 'ansi_dark', or any Pygments theme. By default 'ansi_dark'. - **plain** (bool | None) - Optional - Only show plain style. No decorations such as boxes or execution counts. If set to None will autodetect. By default None. - **unicode** (bool | None) - Optional - Whether to use unicode characters to render the notebook. If set to None will autodetect. By default None. - **hide_output** (bool) - Optional - Do not render the notebook outputs. By default False. - **nerd_font** (bool) - Optional - Use nerd fonts when appropriate. By default False. - **files** (bool) - Optional - Create files when needed to render HTML content. By default True. - **negative_space** (bool) - Optional - Whether render character images in negative space. By default True. - **hyperlinks** (bool | None) - Optional - Whether to use hyperlinks. If False will explicitly print out path. If set to None will autodetect. By default None. - **hide_hyperlink_hints** (bool) - Optional - Hide text hints of when content is clickable. By default False. - **images** (bool | None) - Optional - Whether to render images. If set to None will autodetect. By default None. - **image_drawing** (Union[ImageDrawingEnum, Literal['block', 'character', 'braille'], None]) - Optional - The characters used to render images. Options are 'block', 'character', 'braille' or None. If set to None will autodetect. By default None. - **color** (bool | None) - Optional - Whether to use color. If set to None will autodetect. By default None. - **line_numbers** (bool) - Optional - Whether to render line numbers in code cells. By default False. - **code_wrap** (bool) - Optional - Whether to wrap code if it does not fit. By default False. ### Request Example ```python # Example usage (assuming notebook_file_path is defined) # notebook = Notebook.from_file(notebook_file_path, theme='ansi_light', hide_output=True) ``` ### Response #### Success Response (200) - **Notebook object** (Notebook) - A Notebook object created from the file. #### Response Example ```python # A Notebook object instance ``` ### Error Handling - **InvalidNotebookError** - If the file is not a valid Jupyter notebook. ``` -------------------------------- ### Render multiple Jupyter notebooks Source: https://nbpreview.readthedocs.io/en/latest/features.html Provide multiple file paths to render several Jupyter notebooks at once. ```bash % nbpreview notebook1.ipynb notebook2.ipynb ``` -------------------------------- ### Render notebook with wrapping and line numbers Source: https://nbpreview.readthedocs.io/en/latest/features.html Enables code wrapping and line numbers for better readability of long code cells. ```bash % nbpreview --theme material --code-wrap --line-numbers notebook.ipynb ╭────────────────────────────────────────────────────────────────────────╮ [5]: │ 1 ( │ │ 2 df.loc[lambda _df: (_df["sepal.length"] < 6.0) & │ │ (_df["petal.length"] < 3.5)] │ │ 3 .groupby("variety")["petal.width"] │ │ 4 .mean() │ │ 5 ) │ ╰────────────────────────────────────────────────────────────────────────╯ ``` -------------------------------- ### Notebook Constructor Source: https://nbpreview.readthedocs.io/en/latest/reference.html Construct a Notebook object to render Jupyter Notebooks with various customization options. ```APIDOC ## Notebook Constructor ### Description Construct a Notebook object to render Jupyter Notebooks. ### Method __init__ ### Parameters #### Path Parameters - **notebook_node** (NotebookNode) - Required - A NotebookNode of the notebook to render. #### Query Parameters - **theme** (str) - Optional - The theme to use for syntax highlighting. May be 'ansi_light', 'ansi_dark', or any Pygments theme. By default 'ansi_dark'. - **plain** (bool | None) - Optional - Only show plain style. No decorations such as boxes or execution counts. If set to None will autodetect. By default None. - **unicode** (bool | None) - Optional - Whether to use unicode characters to render the notebook. If set to None will autodetect. By default None. - **hide_output** (bool) - Optional - Do not render the notebook outputs. By default False. - **nerd_font** (bool) - Optional - Use nerd fonts when appropriate. By default False. - **files** (bool) - Optional - Create files when needed to render HTML content. By default True. - **negative_space** (bool) - Optional - Whether render character images in negative space. By default True. - **hyperlinks** (bool | None) - Optional - Whether to use hyperlinks. If False will explicitly print out path. If set to None will autodetect. By default None. - **hide_hyperlink_hints** (bool) - Optional - Hide text hints of when content is clickable. By default False. - **images** (bool | None) - Optional - Whether to render images. If set to None will autodetect. By default None. - **image_drawing** (Union[ImageDrawingEnum, Literal['block', 'character', 'braille'], None]) - Optional - The characters used to render images. Options are 'block', 'character', 'braille' or None. If set to None will autodetect. By default None. - **color** (bool | None) - Optional - Whether to use color. If set to None will autodetect. By default None. - **relative_dir** (InitVar) - Optional - The directory to prefix relative paths to convert them to absolute. If None will assume current directory is relative prefix. By default None. - **line_numbers** (bool) - Optional - Whether to render line numbers in code cells. By default False. - **code_wrap** (bool) - Optional - Whether to wrap code if it does not fit. By default False. ### Request Example ```python # Example usage (assuming notebook_node is defined) # notebook = Notebook(notebook_node, theme='ansi_light', hide_output=True) ``` ### Response #### Success Response (200) - **Notebook object** (Notebook) - A Notebook object created with the specified parameters. #### Response Example ```python # A Notebook object instance ``` ``` -------------------------------- ### CLI Usage: nbpreview Source: https://nbpreview.readthedocs.io/en/latest/_sources/usage.rst.txt Basic usage of the nbpreview command to render Jupyter notebooks. ```APIDOC ## CLI Command: nbpreview ### Description Executes the nbpreview tool to display the contents of a Jupyter notebook file in the terminal. ### Usage `nbpreview [FILE]` or `nbp [FILE]` ### Arguments - **FILE** (string) - Required - The path to the Jupyter notebook (.ipynb) file. Can accept multiple paths or input from stdin. ### Example `nbpreview notebook.ipynb` ## CLI Command: nbpreview --help ### Description Displays the help documentation for all available options, their effects, and environmental variables. ### Usage `nbpreview --help` ``` -------------------------------- ### Render LaTeX in Notebooks Source: https://nbpreview.readthedocs.io/en/latest/features.html Use the nbpreview command-line tool to render LaTeX expressions within a notebook as unicode characters. ```bash nbpreview --theme material notebook.ipynb ``` -------------------------------- ### Import required libraries for notebook analysis Source: https://nbpreview.readthedocs.io/en/latest/index.html Standard imports for data analysis and visualization using ArviZ, Matplotlib, Pandas, and PyMC. ```python from typing import Optional import arviz as az import matplotlib.pyplot as plt import pandas as pd import pymc as pm from arviz import InferenceData from matplotlib.axes import Axes from matplotlib.axes._subplots import Subplot from pandas import DataFrame import plots ``` -------------------------------- ### Run nbpreview using its alias 'nbp' Source: https://nbpreview.readthedocs.io/en/latest/_sources/usage.rst.txt This command uses the convenient alias 'nbp' for nbpreview to preview a Jupyter notebook file. It functions identically to the full command. ```console % nbp notebook.ipynb ``` -------------------------------- ### Set theme via environment variable Source: https://nbpreview.readthedocs.io/en/latest/_sources/configure.md.txt Export an environment variable to set a persistent default theme for the current shell session. ```console % export NBPREVIEW_THEME='material' ``` -------------------------------- ### Force plain output Source: https://nbpreview.readthedocs.io/en/latest/_sources/features.md.txt Manually force plain rendering using the --plain or -p option. ```console % nbpreview --plain notebook.ipynb ``` -------------------------------- ### Include Project Dependencies Source: https://nbpreview.readthedocs.io/en/latest/_sources/dependencies.md.txt This snippet shows how to include project dependencies from a pyproject.toml file using literalinclude. ```toml [tool.poetry.dependencies] python = "^3.9" black = "^23.1.0" flake8 = "^6.0.0" ``` -------------------------------- ### Enable Image Rendering in nbpreview Source: https://nbpreview.readthedocs.io/en/latest/features.html Control image rendering in nbpreview using command-line options. Use --images to enable and --no-images to disable. Rendering many images can affect performance. ```bash nbpreview --images ``` ```bash nbpreview --no-images ``` -------------------------------- ### Render notebook with braille drawing Source: https://nbpreview.readthedocs.io/en/latest/features.html Use the braille drawing mode to render images within the terminal. ```bash % nbpreview --theme material --image-drawing braille notebook.ipynb ``` -------------------------------- ### Render notebook with block drawing Source: https://nbpreview.readthedocs.io/en/latest/features.html Use the block drawing mode to render images within the terminal. ```bash % nbpreview --theme material --image-drawing block notebook.ipynb ``` -------------------------------- ### Run Specific Nox Session (Unit Tests) Source: https://nbpreview.readthedocs.io/en/latest/contributing.html Invoke a specific Nox session, such as the unit test suite. ```bash $ nox --session=tests ``` -------------------------------- ### Render images using block drawing Source: https://nbpreview.readthedocs.io/en/latest/features.html Use the block drawing method to render images in the terminal. ```bash % nbpreview --theme material --image-drawing block notebook.ipynb ╭────────────────────────────────────────────────────────────────────────╮ [4]: │ ( │ │ sns.load_dataset("penguins").pipe( │ │ (sns.kdeplot, "data"), │ │ x="flipper_length_mm", │ │ hue="species", │ │ multiple="stack", │ │ ) │ │ ) │ ╰────────────────────────────────────────────────────────────────────────╯ [4]: 🖼 Click to view Image ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▀▀▀ ▀ ▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀ ▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▄▄▄▄▄ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀ ▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀ ▀▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀ ▀▀ ▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀▀ ▄ ▄ ▄▄▄ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀ ▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀ ▀▄▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀▀ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀ ▀▀▀▀▀▀ ▄▄▄▄▄ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀ ▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄ ▀▀▀▀ ▀▀ ▀▀ ▀ ``` -------------------------------- ### Force manual paging Source: https://nbpreview.readthedocs.io/en/latest/_sources/features.md.txt Manually force paging using the --paging or -g option. This can also be configured via the NBPREVIEW_PAGING environment variable. ```console % nbpreview --paging notebook.ipynb ``` -------------------------------- ### Force decorated output Source: https://nbpreview.readthedocs.io/en/latest/_sources/features.md.txt Manually force decorated rendering using the --decorated or -d option. ```console % nbpreview --decorated notebook.ipynb ``` -------------------------------- ### Load and aggregate baby growth data Source: https://nbpreview.readthedocs.io/en/latest/index.html Read a CSV dataset from a URL, rename columns, and perform aggregation by month. ```python babies_data = pd.read_csv( "https://github.com/aloctavodia/BAP/blob/master/code/data/babies.csv" ).rename(columns={"Lenght": "Length"}) months_of_interest = list(range(0, 13, 4)) ( babies_data.groupby("Month") .agg( mean_length=("Length", "mean"), median_length=("Length", "median"), mean_std=("Length", "std"), measurement_count=("Month", "count"), ) .loc[months_of_interest] ) ``` -------------------------------- ### Render Notebook Cell Output Source: https://nbpreview.readthedocs.io/en/latest/index.html This code snippet demonstrates how to render the output of a notebook cell, including plots, using nbpreview. Ensure necessary libraries are imported. ```python color=color, ax=dist_ax, ).set(xticks=[], yticks=[]); ```