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 details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

Details for the file html_writer-1.1.1.tar.gz.

File metadata

  • Download URL: html_writer-1.1.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for html_writer-1.1.1.tar.gz
Algorithm Hash digest
SHA256 1b2fe2311e53e3e1cb24b3ebd4f52e43817c104303837ab73d9f4250e8b17805
MD5 a5e0e190f333fc7014d2ee8ab2b72c09
BLAKE2b-256 0f42ea17cee1867a718b3d5022fec8c40761ca1e855d4b3e2c6ffbadf13ccaff

See more details on using hashes here.

File details

Details for the file html_writer-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: html_writer-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for html_writer-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 16fc5d4337d6a22de33abf6f2e0e2061a2415caa61bf2f77a12f58f41981bfbb
MD5 9825bfda254614fb1be6807f1608c088
BLAKE2b-256 a0253f2645a949a0cb8c385fcd5a5596e3b6a9b637c8b72f56ee73e99adc550c

See more details on using hashes here.

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