{"id":13937437,"url":"https://github.com/srittau/python-htmlgen","last_synced_at":"2025-10-25T21:04:18.770Z","repository":{"id":14751793,"uuid":"17472997","full_name":"srittau/python-htmlgen","owner":"srittau","description":"Python HTML 5 Generator","archived":false,"fork":false,"pushed_at":"2023-06-26T12:09:20.000Z","size":275,"stargazers_count":16,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2023-11-20T15:44:33.796Z","etag":null,"topics":["html","html5","python","python2","python3"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/srittau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-03-06T09:44:51.000Z","updated_at":"2024-05-02T23:04:08.606Z","dependencies_parsed_at":"2024-05-02T23:04:00.497Z","dependency_job_id":"68150aaa-f4b4-43a8-b5a3-75632879de2f","html_url":"https://github.com/srittau/python-htmlgen","commit_stats":{"total_commits":256,"total_committers":4,"mean_commits":64.0,"dds":0.15625,"last_synced_commit":"5ea217257aea029023bdcb42320e61895cefca4b"},"previous_names":[],"tags_count":21,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srittau%2Fpython-htmlgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srittau%2Fpython-htmlgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srittau%2Fpython-htmlgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srittau%2Fpython-htmlgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/srittau","download_url":"https://codeload.github.com/srittau/python-htmlgen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248083290,"owners_count":21045072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html","html5","python","python2","python3"],"created_at":"2024-08-07T23:03:35.540Z","updated_at":"2025-10-25T21:04:18.707Z","avatar_url":"https://github.com/srittau.png","language":"Python","funding_links":[],"categories":["Python","Libraries"],"sub_categories":["General HTML Generation"],"readme":"# Python HTML 5 Generator\n\n[![License](https://img.shields.io/pypi/l/htmlgen.svg)](https://pypi.python.org/pypi/htmlgen/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/htmlgen)](https://pypi.python.org/pypi/htmlgen/)\n[![Release](https://img.shields.io/github/release/srittau/python-htmlgen/all.svg)](https://github.com/srittau/python-htmlgen/releases/)\n[![PyPI](https://img.shields.io/pypi/v/htmlgen.svg)](https://pypi.python.org/pypi/htmlgen/)\n[![Travis CI](https://travis-ci.org/srittau/python-htmlgen.svg?branch=master)](https://travis-ci.org/srittau/python-htmlgen)\n\nLibrary to generate HTML from classes.\n\nBasic usage:\n\n    \u003e\u003e\u003e from htmlgen import Division, Span\n    \u003e\u003e\u003e Division(\"This is \", Span(\"important!\"), \"!\")\n\nA more verbose example:\n\n    \u003e\u003e\u003e span = Span(\"important\")\n    \u003e\u003e\u003e span.add_css_classes(\"important\")\n    \u003e\u003e\u003e div = Division()\n    \u003e\u003e\u003e div.id = \"my-block\"\n    \u003e\u003e\u003e div.append(\"This is \")\n    \u003e\u003e\u003e div.append(span)\n    \u003e\u003e\u003e div.append(\"!\")\n\nA tree constructed like this can be converted to a string:\n\n    \u003e\u003e\u003e str(div)\n    '\u003cdiv id=\"my-block\"\u003eThis is \u003cspan class=\"important\"\u003eimportant\u003c/span\u003e!\u003c/div\u003e'\n    \u003e\u003e\u003e \"\u003cp\u003eThis is {}!\u003c/p\u003e\".format(span)\n    '\u003cp\u003eThis is \u003cspan class=\"important\"\u003eimportant\u003c/span\u003e!\u003c/p\u003e'\n\nAlternatively, all elements can be used as iterators, for example to return\nthem from a WSGI callback:\n\n    \u003e\u003e\u003e def application(env, start_response):\n    ...     start_response(\"200 OK\", [(\"Content-Type\", \"text/html\")])\n    ...     return div\n\nThere are two different ways to render children of HTML elements. The tree\nconstruction approach shown above is mainly suitable for elements with few\nchildren. The disadvantage of this approach is that the whole tree must be\nconstructed in memory. An alternative way, best suited for custom sub-classes\nof elements, is to override the generate_children method of the Element class:\n\n    \u003e\u003e\u003e class MyBlock(Division):\n    ...     def __init__(self):\n    ...         super(MyBlock, self).__init__()\n    ...         self.id = \"my-block\"\n    ...     def generate_children(self):\n    ...         yield \"This is \"\n    ...         span = Span(\"important\")\n    ...         span.add_css_classes(\"important\")\n    ...         yield span\n    ...         yield \"!\"\n    \u003e\u003e\u003e str(MyBlock())\n    '\u003cdiv id=\"my-block\"\u003eThis is \u003cspan class=\"important\"\u003eimportant\u003c/span\u003e!\u003c/div\u003e'\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrittau%2Fpython-htmlgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrittau%2Fpython-htmlgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrittau%2Fpython-htmlgen/lists"}