Skip to main content

Framework-free browser form layer for pytypehint

Project description

pytypehintweb

PyPI version Python License

Python schemas in. Portable form plans and browser widgets out.

pytypehintweb is a framework-free browser form layer for pytypehint. It converts compiled Python type schemas into self-contained, JSON-serializable form plans and renders them with plain JavaScript widgets. The browser runtime also consumes hand-written plans or plans from another backend, so Python is not required at render time. Everything around the form — routing, static-file delivery, authentication, submission, function execution — belongs to the host application. (For the whole request/response cycle instead of the rendering layer, see FuncToWeb.)

Pre-1.0: the API is still settling, so breaking changes are expected between releases.

Features

  • Self-contained, JSON-serializable plans from plain functions, dataclass types or compiled Signature/Struct schemas — and hand-written plans need no Python.
  • Framework-free browser runtime (plain HTML, CSS and JS modules), with widgets usable directly or from a plan; browser files ship inside the Python package under pytypehintweb.STATIC.
  • Optional stylesheet scoped to a .pth-root container, with a light/dark theme that follows the system or is forced with data-pth-theme — pure CSS, no theme JavaScript and no flash. Its icons are plain .svg files served beside it, so no img-src data: is needed.
  • str, int, float, date, time, bool and enum composing through lists, optional fields, unions and nested dataclasses, with constraints, static choices, integer sliders, and configurable validation messages and labels.
  • file fields (single, optional or list[File], and inside dataclasses) that mint an upload reference the host redeems through its own channel, and that accept an existing reference as a plan default or through setValue().
  • Centralized plan normalization and validation before any widget is built, and plain / inline / wrapped union transport.
  • Plan text is always rendered as text, never parsed as markup.

Installation

pip install pytypehintweb            # library
pip install "pytypehintweb[demo]"    # + the local demo (pytypehintweb-demo)
# Demo with all widgets, served by a local HTTP server on port 8000:
pytypehintweb-demo

There is no npm package: the browser modules live under pytypehintweb.STATIC and can be served by any static-file mount.

Quick start

from typing import Annotated

from pytypehint import Label, Min
from pytypehintweb import plan_of


def create_user(
    username: Annotated[str, Min(3), Label("Username")],
    age: Annotated[int, Min(0), Label("Age")],
) -> None:
    pass


plan = plan_of(create_user)

plan_of() returns ordinary Python dictionaries and lists — a single, fully expanded, self-contained document where every non-conditional property is present with an explicit value (default appears exactly when hasDefault is true), carrying a top-level "v": 1:

{
  "v": 1,
  "kind": "form",
  "name": "create_user",
  "description": null,
  "fields": [
    {
      "name": "username",
      "label": "Username",
      "description": null,
      "optional": false,
      "enabled": true,
      "hasDefault": false,
      "node": {
        "kind": "str",
        "options": {
          "minLength": 3,
          "maxLength": null,
          "pattern": null,
          "patternMessage": "Invalid format",
          "minMessage": "Must contain at least {value} characters",
          "maxMessage": "Must contain at most {value} characters",
          "placeholder": null,
          "password": false,
          "rows": null,
          "choices": null
        }
      }
    },
    {
      "name": "age",
      "label": "Age",
      "description": null,
      "optional": false,
      "enabled": true,
      "hasDefault": false,
      "node": {
        "kind": "int",
        "options": {
          "min": 0,
          "max": null,
          "multipleOf": null,
          "step": null,
          "slider": false,
          "showValue": false,
          "placeholder": null,
          "choices": null,
          "safeMessage": "Must be a safe integer",
          "invalidMessage": "Enter a valid integer",
          "minMessage": "Must be at least {value}",
          "maxMessage": "Must be at most {value}",
          "multipleOfMessage": "Must be a multiple of {value}",
          "increaseLabel": "Increase",
          "decreaseLabel": "Decrease"
        }
      }
    }
  ]
}

Transporting that document to the browser and compiling it with compileForm() is walked through end to end in Getting started.

Documentation

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

pytypehintweb-0.0.3.tar.gz (69.2 kB view details)

Uploaded Source

Built Distribution

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

pytypehintweb-0.0.3-py3-none-any.whl (72.2 kB view details)

Uploaded Python 3

File details

Details for the file pytypehintweb-0.0.3.tar.gz.

File metadata

  • Download URL: pytypehintweb-0.0.3.tar.gz
  • Upload date:
  • Size: 69.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pytypehintweb-0.0.3.tar.gz
Algorithm Hash digest
SHA256 a8955256bfdd22fbc493e2c6d9747be5ba1c94d566d5f85b6193857a2f66e0c5
MD5 4d7c4d37d90d2a7a79790ad790ffb950
BLAKE2b-256 0260b31acd81f7ad4c9e5cc6056012eb6b958b181428d309a52e4c890dcfbb52

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytypehintweb-0.0.3.tar.gz:

Publisher: publish.yml on offerrall/pytypehintweb

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

File details

Details for the file pytypehintweb-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pytypehintweb-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 72.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pytypehintweb-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5c8b37a1eb5ce2ffb4cd9f4e823ca40e8151e1416f3841e9ee94d1a3eaaf15c4
MD5 43191769a5811392b157c9b434d6335e
BLAKE2b-256 de254c1338cdb474657d004547f2f6cbbc425d2673831997907785ab5ec715cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytypehintweb-0.0.3-py3-none-any.whl:

Publisher: publish.yml on offerrall/pytypehintweb

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