Skip to main content

Easy form creation with ipywidgets in Jupyter

Project description

IpyFormKit

IpyFormKit is a Python library for creating dynamic, interactive forms using ipywidgets in Jupyter notebooks. It simplifies the process of building forms for data entry, configuration, or experimentation with minimal code.

Features

  • Dynamic Forms: Automatically generate forms from dictionaries with support for various input types (text, numbers, dropdowns, checkboxes, etc.).
  • Custom Widgets: Includes specialized widgets like FileAutocomplete for file selection and CollapsibleVBox for collapsible sections.
  • Validation and Logic: Add conditions to disable, hide, or validate fields dynamically based on user input.
  • Masonry Layout: Organize multiple forms in a responsive masonry-style layout.
  • Adaptive CSS Styling Seamless integration with Jupyter Notebook/Lab, Google Colab and VScode themes.
Jupyter Lab Light Example Jupyter Lab Dark Example VSCode Example Google Colab Example

Installation

pip install ipyformkit

For use in Google Colab one currently needs to downgrade ipywidgets as widgets are not displayed otherwise.

pip install ipyformkit
pip install "ipywidgets>=7,<8"

Example Usage

import ipyformkit as ifk

test = {'first name':'Zaphod',
        'last name':'Beeblebrox',
        ('age', 'gender'):(-200, ('two-headed', 'male', 'female', 'non-binary')),
        'height':2.05,
        'date of birth':'Unknown (he probably lied about it anyway)',
        ('Input 1', 'Input 2', 'Input 3', 'Input 4'):('president', 'of', 'the', 'galaxy'),
        ('street', 'house'):('Heart of Gold Spaceship', 1),
        'additional info':{'hobbies':'Kidnapping himself, avoiding responsibility, being outrageous',}
       }


mandatory = ['last name', 'age']
disable = {'last name': lambda d: d['first name'] == '',}
hide = {'house': lambda d: d['street'] == '',}
check = {'age': lambda d: d['age'] > 0,}
tooltips = {'first name':'What your mother calls you when you are in trouble.'}

form = ifk.Form(test, title='Test Form', mandatory=mandatory, disable=disable, hide=hide, check=check, tooltips=tooltips, max_width=400)
form.display()

Text input is converted into placeholders instead of values by default. One can set multiple values at once by supplying a dictionary to the .set_values() method. The dictionary keys should match the field names in the form. The values can be any type supported by ipywidgets.

form.set_values({'first name': 'Arthur', 'last name': 'Dent', 'age': 42})

Retrieve values:

values = form.get_values() # returns unchecked values
out = form.check_and_return_values() # return checked values and highlights missing mandatory inputs

Documentation

ifk.Form() is a class that creates a form using ipyipywidgets. It can be displayed using its .display() method. It takes a dictionary as input and generates the corresponding ipywidgets. The class also supports various features such as validation, conditional display, and custom styling. The arguments mandatory, disable, hide and check expect dictionaries with the affected field name as a key and a function as a value. The function takes the current form inputs as a dictionary and returns a boolean value. The function should return True if the field should be disabled, hidden or checked, and False otherwise. The .get_values() method returns the current values of each input field without applying any validation. The .check_and_return_values() method will return the current values but validate that all checks are passed.

Dictionary Value Type Created Widget Notes
bool ipywidgets.Checkbox A checkbox with the dictionary key as its description.
int ipywidgets.IntText A text box for integer input.
float ipywidgets.FloatText A text box for float input with step size based on decimal places.
pathlib.Path FileAutocomplete A custom widget for selecting files from the working directory.
str (contains "password") ipywidgets.Password A password input field.
str (ends with ...) ipywidgets.Textarea A multi-line text area with the placeholder text (excluding ...).
str (other cases) ipywidgets.Text A single-line text input field with the string as a placeholder.
list ipywidgets.Select A selection box with the list values as options.
tuple ipywidgets.Dropdown A dropdown menu with the tuple values as options.
callable ipywidgets.Button A button that calls the function when clicked.
dictionary ... A collapsible sub-form with the dictionary mapped according to this table.

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

ipyformkit-0.3.2.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

ipyformkit-0.3.2-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file ipyformkit-0.3.2.tar.gz.

File metadata

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

File hashes

Hashes for ipyformkit-0.3.2.tar.gz
Algorithm Hash digest
SHA256 f4a306ae208a7552c36d6fb0cf2b449727a8646d6f3b29a0dbe50d3beccb77ae
MD5 5b41ac38d87ac9c4ea46b73c8413064d
BLAKE2b-256 7f0c16f9bf3af8139bb6c286f24c2e52034ed5da47ca1c498e16a6b243853dc1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ipyformkit-0.3.2.tar.gz:

Publisher: python-publish.yml on RMHoppe/IpyFormKit

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

File details

Details for the file ipyformkit-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: ipyformkit-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ipyformkit-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 baab8add1bd9d1b96bf356a9473a21392acf81b025496ae51589cf3dbc92dc67
MD5 a1cf653d3cad2e49c6e9bb47956dcba8
BLAKE2b-256 037023b499aad6cead4ff6e31d5d8eb1d4328ac67564724139ea032082f5c25e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ipyformkit-0.3.2-py3-none-any.whl:

Publisher: python-publish.yml on RMHoppe/IpyFormKit

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