Skip to main content

On-the-go HTML Abstraction and Generator for Python

Project description

woshi

On-the-go HTML Abstraction and Generator for Python.

You're prototyping the next big thing and definitely writing the perfect HTML file is not on the priority.

Woshi lets you create HTML documents on the go and inside your Python scripts. It is built on top of lxml.html plus with another level of abstraction, so you can code with no trouble of messing up with closing tags--it is so quick and easy!

Here's a sample syntax:

page["tag#id"] = "tag #id.class property='10' > inner text"

And scroll down below for more examples.

Official Release

Woshi can now be used on your Python projects through PyPi by running pip command on a Python-ready environment.

pip install -U woshi

Current version is 1.0, but more updates are coming soon. It is compatible with Python 3.9+, but will require other third-party libraries during installation.

Usage

Import Package

from woshi import Woshi

Initialization

page = Woshi()
page = Woshi("home.html")

Creating elements with an inner text

page["head"] = "title > Woshi v1.0"

Creating other elements Basically, you set the parent selector to append the new element.

# create container box
page["body"] = "div #content"
page["#content"] = "div #box.container.light"

# create the popup text
page["#box"] = "div #title.header > Woshi"
page["#box"] = "div .message data-default='Lorem ipsum...' > Hello, world!"

# populate the action buttons
page["#box"] = "div #action.btn-list"
page["#action"] = "button #btn1.btn.btn-no style='background-color:#b22222;color:#fff;' > CLOSE"
page["#action"] = "button #btn2.btn.btn-maybe > LATER"

# using lxml xpath
page[".//div[@id='action']"] = "button #btn3.btn.btn-yes > CONTINUE"

Setting Properties

page["html"] = "lang=en" # not yet allowed in lxml
page["body"] = "#canvas"

Yield all matches

for element in page["button"]:
    print(element.tag)

Yield all matches as HTML string

for element in page.get("button", to_string=True):
    print(element)

Save to HTML file

page.save()
page.save("newFile.html")

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

woshi-1.0.2.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

woshi-1.0.2-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file woshi-1.0.2.tar.gz.

File metadata

  • Download URL: woshi-1.0.2.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for woshi-1.0.2.tar.gz
Algorithm Hash digest
SHA256 ec9e885444434581fa847647db07595fd2527f302982d40b7bcb73b8db4e0a2d
MD5 57b36842177de32cac4604c8c30e0087
BLAKE2b-256 16568676a6ccdace3fa53c853496a14821997d14dbee484ca06acbbad8b66fb0

See more details on using hashes here.

File details

Details for the file woshi-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: woshi-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for woshi-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1d266929d8fa278edbe0e1d9598d3fd865b183a4729c6766e1ff66c6a9847400
MD5 9b47cda7644d3c48197506571b985c40
BLAKE2b-256 7c6667075387723dfb666104d20f1e904a54f6b66d5af681460b9000391e511f

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