Skip to main content
Release file added late

1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.

Python package

HTML Form to Dict

This is a tiny library which provides a method called html_form_to_dict().

This method takes a string containing HTML and returns a dictionary of the values of the first form.

The data returned by html_form_to_dict() is a FormDict which has the method submit(). This way you can submit the data like a real browser would.

This mean you can do simple end-to-end testing of form handling without a real browser (like selenium/puppeteer/playwright).

The submit() method supports the "action" and "method" attributes of forms and additionaly the htmx attributes hx-get, hx-post.

Example:

def test_foo(client):
    ...
    
    # client is a DjangoClient. But you could use
    # python-requests or a different URL-lib, too
    response = client.get(url)
    
    # This method parses the HTML in response.content to a dictionary.
    # This dictionary is like request.POST or request.GET.
    # It is a flat mapping from the input elements of the form
    # to their value.
    data = html_form_to_dict(response.content)
    
    # Now you can test the default values of the form.
    assert data == {'city': 'Chemnitz', 'name': 'Mr. X'}
    
    # You can edit the data. This is like a human (or Playwright/Selenium)
    # altering the HTML input fields
    data['name'] = 'Mrs. Y'
    
    # This submits the data to the server.
    # This methods uses the "action" attribute of the form.
    # The hx-get, hx-post attributes of htmx are supported, too
    response = data.submit(client)
    
    # If you use the Post/Redirect/Get pattern:
    assert response.status == 302, response.context['form'].errors

Above code uses pytest-django. See client fixture

The FormDict returned by html_form_to_dict() does not allow adding new keys, which are not in the dictionary yet. This way you get an error if your test sets the value for an input which (maybe due to refactoring) does not exist.

Above example uses Django, but the library is a pure Python library which does not depend on any particular web-framework.

This library was build for testing, but you can use it for all tasks where you want to parse and submit html forms.

This library does not evaluate JavaScript. If you need JS support, please use Playwright (or a similar tool).

Install

pip install html_form_to_dict

Development

You need to upload your ssh-pub-key to github first:

pip install -e git+ssh://git@github.com/guettli/html_form_to_dict#egg=html_form_to_dict
edit-the-code
pip install pytest
pytest
create Pull-Request

Alternatives

Deploy

via deploy-library.py

for py2 tgz package: python -m twine upload dist/html_form_to_dict-*.tar.gz

Metadata

Release files for html-form-to-dict 2022.10.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

File added late

1 file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release files before installing.

Source distribution (sdist)

Source distribution for html-form-to-dict 2022.10.1
File Size Uploaded Provenance Actions
html_form_to_dict-2022.10.1.tar.gz 5.7 kB File added late: Without provenance Details for html_form_to_dict-2022.10.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for html-form-to-dict 2022.10.1
File Interpreter ABI Platform Actions
html_form_to_dict-2022.10.1-py3-none-any.whl Python 3 none any Details for html_form_to_dict-2022.10.1-py3-none-any.whl

Total release size: 12.2 kB

Release files / html_form_to_dict-2022.10.1.tar.gz

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL html_form_to_dict-2022.10.1.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
974dbf0481a0b11ac3d8c4ae73b792a0d509a94d4a0b526cb6d9a779fa30da6a
BLAKE2b-256 checksum
How to use checksums
ffcd80203077f6afaaead328eaaa8c1c8e393b019e85dbc3007432aba02662ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release files / html_form_to_dict-2022.10.1-py3-none-any.whl

Download URL html_form_to_dict-2022.10.1-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d447930da03659d52e4b4994faf270ed749c5184cb10c9b17986845c83456e2
BLAKE2b-256 checksum
How to use checksums
75d54159d93df599d14ac7899225243cdeb50d8966e1c21049e61b3e3ed3e541
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Security for html-form-to-dict 2022.10.1

Upload timing

Release file added late

1 file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.


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