Skip to main content

A simple HTML writer

Project description

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!

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

html_writer-1.1.1.tar.gz (6.8 kB view hashes)

Uploaded Source

Built Distribution

html_writer-1.1.1-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page