Skip to main content
# Jupyter custom ipywidget: **ipyupload**

## 1 - Overview

This repo contains the source code and the building scripts for **ipyupload** a custom [ipywidget](https://ipywidgets.readthedocs.io/en/stable/).

It enables to upload a file from a Jupyter notebook - classic or JupyterLab.

It allows:

- single or multiple file upload
- to restrict the upload to certain file types
- to disable the file upload

Under the hood:

- The [FileReader](https://developer.mozilla.org/en-US/docs/Web/API/FileReader) Web API is used.
- Data is read throught the [readAsArrayBuffer()](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsArrayBuffer) method, then converted to a [DataView](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) before syncing back to Python.
- The convertion to Python bytes uses the ipywidgets deserializer [bytes_serialization](https://github.com/jupyter-widgets/ipywidgets/blob/a5709728f71e21c81a89e8d123dde2068dd1e74d/ipywidgets/widgets/trait_types.py#L196) already used for the [Media core widget](https://github.com/jupyter-widgets/ipywidgets/blob/a5709728f71e21c81a89e8d123dde2068dd1e74d/ipywidgets/widgets/widget_media.py#L36).
- The metadata are synced back as a `List(Dict)`.
- The file contents are synced back as a `List(Bytes)`.
- An `Int` counter is observed and upon change triggers the aggregation of the data and presentation to the user as a dict {filename: {metadata, file content in bytes}) in the `.value` property.

After an upload the button displays the number of files uploaded, to provide feedback to the user.

Naturally such an upload widget is mostly useful in a widgetized notebook and/or in a JupyterHub context, with a remote kernel.

## 2 - Install

## 2.1 - User Install

>From terminal:

```bash
# for notebook >= 5.3
$ pip install ipyupload

# for notebook < 5.3
$ pip install ipyupload
$ jupyter nbextension install ipyupload --py --sys-prefix
```

## 2.2 - Developer Install

>From terminal:

```bash
$ git clone https://gitlab.com/oscar6echo/ipyupload.git
$ cd ipyupload/js
$ npm install
$ cd ..
$ pip install -e .
$ jupyter nbextension install --py --symlink --sys-prefix ipyupload
$ jupyter nbextension enable --py --sys-prefix ipyupload
```

# 3 - Use

```python
from IPython.display import display
from ipyupload import FileUpload

w = FileUpload(
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-accept
# eg. '.txt', '.pdf', 'image/*', 'image/*,.pdf'
accept='', # default
# True to accept multiple files upload else False
multiple=False, # default
# True to disable the button else False to enable it
disabled=False, # default
# CSS transparently passed to button (in a fact a label element)
# e.g. 'color: darkblue; background-color: lightsalmon; width: 180px;'
style_button='' # default
)
display(w)
```

See the [demo notebook](https://nbviewer.jupyter.org/urls/gitlab.com/oscar6echo/ipyupload/blob/master/notebooks/demo-ipyupload.ipynb) for samples.


Metadata

Release files for ipyupload 0.1.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 ipyupload 0.1.0
File Size Uploaded Provenance Actions
ipyupload-0.1.0.tar.gz 210.2 kB Without provenance Details for ipyupload-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ipyupload 0.1.0
File Interpreter ABI Platform Actions
ipyupload-0.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for ipyupload-0.1.0-py2.py3-none-any.whl

Total release size: 632.9 kB

Release files / ipyupload-0.1.0.tar.gz

Download URL ipyupload-0.1.0.tar.gz
Size 210.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0a77ee81f6daec6f56d46c96dbd3f3db0f73cb4980b00ec93c5a34e995fd2783
BLAKE2b-256 checksum
How to use checksums
20817eed7df8c88342d75524bf6cbfd8fa9e9fa2faf76d35c2674de14de4975d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.1

Release files / ipyupload-0.1.0-py2.py3-none-any.whl

Download URL ipyupload-0.1.0-py2.py3-none-any.whl
Size 422.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5b2fc76802b82f663f569866a7d5aa65aa3a1b21cdc4a3da28fbef21316ccd61
BLAKE2b-256 checksum
How to use checksums
8857f89fc675b0c1b68dab6da3d2375f62ec8a5ea18dd70566d721c34613b775
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.1

Security for ipyupload 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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