{"id":14625,"library":"hyperscript","title":"hyperscript","description":"hyperscript is a lightweight Python library for generating HTML, heavily inspired by the JavaScript HyperScript. It is currently at version 0.3.0 and sees releases periodically for fixes and minor enhancements.","status":"active","version":"0.3.0","language":"en","source_language":"en","source_url":"https://github.com/vchan/hyperscript","tags":["html","markup","web","rendering"],"install":[{"cmd":"pip install hyperscript","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Unlike some other 'hyperscript' inspired libraries, this Python 'hyperscript' only exposes a generic 'h' function for creating elements, not individual functions for each HTML tag.","wrong":"from hyperscript import div, p","symbol":"h","correct":"from hyperscript import h"}],"quickstart":{"code":"from hyperscript import h\n\n# Basic element\nprint(h(\"p\", \"Hello world!\"))\n\n# Element with class and ID\nprint(h(\"div.container#main\", h(\"h1\", \"Welcome\"), h(\"p\", \"This is a paragraph.\")))\n\n# Element with attributes and style\nprint(h(\"a\", {\"href\": \"https://www.example.com\", \"style\": {\"color\": \"blue\"}}, \"Visit Example\"))\n\n# Boolean attribute handling\nprint(h(\"input\", {\"type\": \"checkbox\", \"checked\": True})) # renders checked\nprint(h(\"input\", {\"type\": \"checkbox\", \"checked\": False})) # omits checked attribute\nprint(h(\"input\", {\"type\": \"checkbox\", \"checked\": None})) # renders checked (same as True)\n","lang":"python","description":"This quickstart demonstrates how to create basic HTML elements, apply CSS classes and IDs directly in the tag name, add attributes and inline styles, and manage boolean attributes."},"warnings":[{"fix":"Review your HTML generation logic, especially how complex attributes or nested structures were previously defined. Consult the GitHub repository for any updated patterns if your code was affected.","message":"Version 0.3.0 introduced a breaking change by replacing 'pipe annotations'. Code relying on a previous, likely internal or specific, syntax using 'pipe annotations' for HTML generation will no longer work.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Always use `False` explicitly if you want to ensure a boolean attribute is *not* present in the rendered HTML. Use `True` or `None` if you intend for the attribute to be present.","message":"Boolean HTML attributes (e.g., `checked`, `selected`) are handled specifically: `True` renders the attribute, `False` omits it entirely, and `None` also renders the attribute (without a value). This can be a source of confusion if `None` is expected to omit the attribute.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"The `hyperscript` library by `vchan` only provides a single factory function, `h`. You must use `h(\"div\", ...)` or `h(\"p\", ...)` instead. Example: `from hyperscript import h; h(\"div\", \"Content\")`.","cause":"Attempting to import or use specific HTML tag functions (e.g., `div()`, `p()`) directly from the `hyperscript` module.","error":"AttributeError: module 'hyperscript' has no attribute 'div'"},{"fix":"HTML attributes should be passed either in the second argument as a dictionary (e.g., `h(\"p\", {\"class\": \"my-class\"})`) or by including class/id selectors directly in the tag string (e.g., `h(\"p.my-class#my-id\", \"Text\")`).","cause":"Attempting to pass HTML attributes like `class` as a direct keyword argument named `class` (which is a reserved Python keyword) or providing attributes both via a dictionary and keyword arguments.","error":"SyntaxError: invalid syntax (for `class` attribute in keyword arguments) or `TypeError: h() got multiple values for argument 'class'`"}],"ecosystem":"pypi"}