Skip to main content

Extension to render Google Colab Form on regular Jupyter Notebooks

Project description

ipyform

Extension to render Google Colab Form on regular Jupyter Notebooks.

example

pip install ipyform

# or with uv
uv add ipyform

Tested on: Jupyter notebooks, JupyterLab and Vscode.

The solution has no effect (does nothing) when running on Colab.

Usage

Auto detect

Add thoses 2 lines to the top of your notebook. Ipyform will detect automatically colab annotations and display widget forms. No other change is needed.

%load_ext ipyform
%form_config --auto-detect 1

Here is a reproduction of official Google Colab example example.

With cell magic

[!TIP] If you use vscode Pylance, use #! %%form instead of %%form. See Caveats

%%form --col 2
# @title This is a form { display-mode: "form" }

# @markdown ### Section 1

number_input = 10.0 # @param {type:"number"}
number_slider = 0 # @param {type:"slider", min:-1, max:1, step:0.1}
integer_input = 10 # @param {type:"integer"}
integer_slider = 1 # @param {type:"slider", min:0, max:100, step:1}

# @markdown ### Section 2

date_input = '2018-03-22' # @param {type:"date"}

Caveats

  • ipyform uses ipywidgets to render the forms. This means that the forms are not rendered in the static version of the notebook.

In Vscode

  • Hide code feature is not supported.
  • Sometimes the ipywidgets are duplicated. This is a known issue with ipywidgets and Vscode. Reload window will fix.
  • Pylance ignores cells with cell magic (%%form), and then warms about undefined variables. To avoid the issue, you can use #! %%form instead of %%form. This way pylance sees the cell as a python cell, and ipyform will still render the form.

Dev

uv sync
uv run pytest --inline-snapshot=review

# publish
rm -rf dist && uv build
uvx twine upload dist/*

Specs

When Field Type Data Types Default Datatype Additional properties
@param followed by options list Dropdown string, raw string allow-input, options
"type": "slider" Slider number, integer Determined by step min, max, step
Otherwise Input boolean, date, string, raw, number, integer raw placeholder

Input field

# datatype: raw
var_name = expression # @param

# datatype: number
var_name = expression # @param {"type": "number", "placeholder": "your number here"}

Dropdown field

# datatype: string
var_name = expression # @param [1, "2"]

# datatype: raw
var_name = expression # @param ["expression", 1, 2] {"type": "raw"}

Slider field

# datatype: integer. in range [0, 100]
var_name = expression # @param {"type": "slider"}

# datatype: number
var_name = expression # @param {"type": "slider", "min": 1, "max": 2, "step": 0.1}

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

ipyform-0.1.1.tar.gz (450.0 kB view details)

Uploaded Source

Built Distribution

ipyform-0.1.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file ipyform-0.1.1.tar.gz.

File metadata

  • Download URL: ipyform-0.1.1.tar.gz
  • Upload date:
  • Size: 450.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for ipyform-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d1ad29538d96f057fd8a3257b04c2a0b0af819fa206d30f03c140fe48f0afd74
MD5 d411186d9478471915bdb25c5f0df52b
BLAKE2b-256 98eff506ffb61943481650a21e844a8ae0df4121f1647264d646136f0bebd759

See more details on using hashes here.

File details

Details for the file ipyform-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ipyform-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for ipyform-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1916f8dca48dca20c50efcfffa67cc2f3bbc0f4334df5d4f74b68fbb1cc36186
MD5 d84b7acfdfd72212ee466a6a77ca8cb0
BLAKE2b-256 ab9b395e70de1edbc513e82dd08e115574c882a371ce0f40a7f5c683de841486

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page