Skip to main content

html-writer

PyPI PyPI - Python Version PyPI - License

A simple html writer for python.

Description

You can write raw html with 'with' statements like:

html = Html()
with html.tag('div'):
    with html.tag('p') as h:
        h += 'Hello world!'
# Here html has '<div><p>Hello world!</p></div>'

'with' syntax also serves human-readable indentation:

html = Html()
with html.tag('div'):
    with html.tag('p') as h:
        h += 'Hello world!'
# Here html really has 
# <div>
#   <p>
#     Hello world!
#   </p>
# </div>

Installation

pip install html_writer

Example

from html_writer import Html
import datetime

head = Html()
head.self_close_tag('meta', attributes=dict(charset='utf-8'))
body = Html()
with body.tag('div'):
    with body.tag('p') as h:
        h += 'Hello World!'
with body.tag('dl'):
    body.tag_with_content('Today', name='dt')
    with body.tag('dt') as h:
        h += datetime.datetime.now().strftime('%y/%m/%d %H:%M:%S')
print(Html.html_template(head, body).to_raw_html(indent_size=2))

Requirements

  • Python >= 3.7.0

Frequently Asked Questions

Q. Isn't it reinventing the wheel? :) :) :)

A. Enjoy coding!

Release files for html-writer 1.1.1

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

Source distribution (sdist)

Source distribution for html-writer 1.1.1
File Size Uploaded
html_writer-1.1.1.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for html-writer 1.1.1
File Interpreter ABI Platform
html_writer-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / html_writer-1.1.1.tar.gz

Download URL html_writer-1.1.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1b2fe2311e53e3e1cb24b3ebd4f52e43817c104303837ab73d9f4250e8b17805
BLAKE2b-256 checksum
How to use checksums
0f42ea17cee1867a718b3d5022fec8c40761ca1e855d4b3e2c6ffbadf13ccaff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release files / html_writer-1.1.1-py3-none-any.whl

Download URL html_writer-1.1.1-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16fc5d4337d6a22de33abf6f2e0e2061a2415caa61bf2f77a12f58f41981bfbb
BLAKE2b-256 checksum
How to use checksums
a0253f2645a949a0cb8c385fcd5a5596e3b6a9b637c8b72f56ee73e99adc550c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1

2 release files

1.0

2 release files

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