form_submit: HTML Form Submission for Google Colab A Python package designed to simplify displaying HTML forms in Google Colab notebooks, capturing user submissions, and securely sending the collected data (including file attachments) via email.
Features Easy HTML Form Display: Render interactive forms directly within your Colab cells. Secure Email Submission: Send form data, including attached files, to a specified email address using an app password. Attachment Handling: Supports decoding and attaching base64 encoded files from the form. Installation Install the package directly from PyPI:
%pip install form_submit Usage
- Displaying the Form First, import the display_feedback_form function and call it in a code cell. This will render the HTML form in your Colab output.
from form_submit import display_feedback_form
display_feedback_form() 2. Handling Form Submissions To capture and process form submissions, you need to set up a JavaScript listener that sends the form data back to Python. The handle_form_submission function in this package is designed to receive this data and send an email.
Here's an example of how you might set up the JavaScript in a Colab notebook (this assumes you've displayed the form and want to handle its submission):
from google.colab import output from form_submit import handle_form_submission
Define a Python function to be called from JavaScript
def _handle_js_form_data(data): email = data.get('enter_your_email', 'N/A') full_name = data.get('enter_your_full_name', 'N/A') phone_number = data.get('enter_your', 'N/A') # Note: original form input name was 'enter_your' feedback = data.get('give_your_feedback_about_the_library', 'N/A') troubleshoots_choice = data.get('any_trobleshoots_in_the_library', 'N/A')
file_input = data.get('upload_your_poblem_in_a_file_pdf_content', None)
file_data = None
if file_input and isinstance(file_input, dict):
file_data = {
'filename': file_input.get('filename'),
'content': file_input.get('content'), # Base64 encoded content
'mimetype': file_input.get('mimetype')
}
handle_form_submission(
email=email,
full_name=full_name,
phone_number=phone_number,
feedback=feedback,
troubleshoots_choice=troubleshoots_choice,
file_data=file_data
)
Expose the Python function to JavaScript
output.register_callback('handle_colab_form', _handle_js_form_data)
JavaScript to intercept form submission and send data to Python
js_code = """
<script> document.addEventListener('DOMContentLoaded', function() { const form = document.querySelector('form'); // Adjust selector if multiple forms if (form) { form.addEventListener('submit', function(event) { event.preventDefault(); // Prevent default form submission const formData = new FormData(form); const data = {}; for (let [key, value] of formData.entries()) { if (value instanceof File) { if (value.size > 0) { const reader = new FileReader(); reader.onload = function(e) { data[key] = { filename: value.name, content: btoa(e.target.result), // Base64 encode file content mimetype: value.type }; google.colab.kernel.invokeFunction('handle_colab_form', [data], {}); }; reader.readAsBinaryString(value); return; // Stop and wait for file read } } else { data[key] = value; } } google.colab.kernel.invokeFunction('handle_colab_form', [data], {});Metadata
Release files for form-submit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| form_submit-0.1.0.tar.gz | 5.1 kB | Without provenance | Details for form_submit-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| form_submit-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for form_submit-0.1.0-py3-none-any.whl |
Total release size: 10.8 kB
Release files / form_submit-0.1.0.tar.gz
| Download URL | form_submit-0.1.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c8ab6e1fa6d9f22b9862dce1268b224b23e28080019e6648ac3373f55b779785
|
|
BLAKE2b-256 checksum How to use checksums |
dfbb23d9cdc4d0e318677744ac20351d2484a5da0d289579a676c88cf39efa08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.0
|
Release files / form_submit-0.1.0-py3-none-any.whl
| Download URL | form_submit-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
12933512e9258d523e023d62d2d307f958877b33b9dc8233279033a201724dd2
|
|
BLAKE2b-256 checksum How to use checksums |
abf051cfc2e0948832b31ef7f9169200da6da7828e5b9cb330c43a51b13323aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.0
|
Security for form-submit 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.