Skip to main content

File picker widget for the host filesystem in Jupyter.

Project description

Jupyter Host File Picker

Jupyter widget for picking files on the host machine.

This widget allows users to select files from the machine that Jupyter is running on. This can be the user's own machine in the case of a local Jupyter session, or it can be a remote system when using Jupyter Hub. In contrast, ipywidgets.FileUpload can only select files on the user machine.

Installation

Install with pip:

python -m pip install jupyter_host_file_picker

or with uv:

uv add jupyter_host_file_picker

Usage

See the example notebook for a complete usage example.

The HostFilePicker class is a dialog with a file browser on the host machine. You can create and display a HostFilePicker just like any other Jupyter widget:

from jupyter_host_file_picker import HostFilePicker

picker = HostFilePicker()
# At the end of a cell:
picker

In the dialog, navigate folders by double-clicking on a folder or by single-clicking and using the 'Open' button. Similarly, select a file by double-clicking or by using the 'Select' button.

Accessing the selected file

The selected file path is stored in

picker.selected

This attribute is a list of Path objects.

[!NOTE] Displaying the file picker will not block the Python kernel. So the selected list is empty until the user selects a file.

Callback

Alternatively to the selected attribute, you can register an observer function that will be called whenever the user selects a file:

def print_selected(change):
    print("Selected file", change["new"])


picker.observe(print_selected, names="selected")

Note that this will only print to the Jupyter log console.

Example with button and text field

Here is a more extensive example that uses a button to open the dialog and a text field to display the selected file:

import os
from pathlib import Path
from typing import Any

from IPython.display import display
from ipywidgets import Button, HBox, Layout, Output, Text
from jupyter_host_file_picker import HostFilePicker


selected_text = Text(layout=Layout(width="100%"))
browse_button = Button(description="Browse", icon="folder-open")
dialog_output = Output(layout=Layout(display="none"))


def sync_selected(change: dict[str, Any]) -> None:
    # Insert the selected path into the text field.
    selected: list[Path] = change["new"]
    if selected:
        path = selected[0]  # For now, there always is only one path.
        selected_text.value = os.fspath(path)


def browse_files(_: Button) -> None:
    # Open a dialog when the button is clicked.
    with dialog_output:  # Use the Output widget as a display context.
        dialog_output.clear_output()  # Remove old dialog, if any.
        picker = HostFilePicker()
        picker.observe(sync_selected, names="selected")
        display(picker)


browse_button.on_click(browse_files)

HBox([selected_text, browse_button, dialog_output])

We open the dialog from a callback of the button. This callback does not have a display context, and so we cannot simply show the dialog using display(picker). Instead, we use a dedicated Output widget to provide the necessary display context. (This widget hat Layout(display="none") because it does not need to be visible itself; it only provides access to the HTML document.)

Development

Requirements

Install the following:

These tools manage all dependencies and build the package.

Run development build

The first time you clone the repository, install JavaScript dependencies using

npm install

Run the following to build the TypeScript code. This will automatically rebuild after any changes in the js folder.

npm run dev

Then, launch Jupyter with the example notebook:

uv run jupyter lab example.ipynb

Uncomment the first code cell to enable hot-reloading of JavaScript and CSS code. If you make changes to the Python code, you need to restart the kernel.

Make a release

To make a release, create a new release on GitHub and select a tag name according to the calendar versioning scheme. GitHub actions will do the rest; you only have to approve the deployment to PyPI.

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

jupyter_host_file_picker-0.0.0.tar.gz (96.7 kB view details)

Uploaded Source

Built Distribution

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

jupyter_host_file_picker-0.0.0-py3-none-any.whl (97.2 kB view details)

Uploaded Python 3

File details

Details for the file jupyter_host_file_picker-0.0.0.tar.gz.

File metadata

  • Download URL: jupyter_host_file_picker-0.0.0.tar.gz
  • Upload date:
  • Size: 96.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jupyter_host_file_picker-0.0.0.tar.gz
Algorithm Hash digest
SHA256 26016f18fdf789d5c83e4fd93ba8d451ddcef797f481ecac25df4ed657b2d442
MD5 fc5db9a366066c0916a320910a734902
BLAKE2b-256 788f4e5ca75591d4a8859c67e5c22d279a0288f1d9b6e439a5c10e982727d388

See more details on using hashes here.

Provenance

The following attestation bundles were made for jupyter_host_file_picker-0.0.0.tar.gz:

Publisher: release.yml on jl-wynen/Jupyter-Host-File-Picker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jupyter_host_file_picker-0.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyter_host_file_picker-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62b8661bad02e38f5d1fbaa55a86bbc27556feb783f4a0152d7aab58493016de
MD5 bac0e51d43a3f444ee44d8d684712499
BLAKE2b-256 3750a31422a5b23bb201fd5d2101d5e4b68a3de24297ff42c02f2ba675e37c4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for jupyter_host_file_picker-0.0.0-py3-none-any.whl:

Publisher: release.yml on jl-wynen/Jupyter-Host-File-Picker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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