Skip to main content

# OOHTML Object Oriented HTML Construction Toolkit for Python

Simple Usage

you can construct HTML in two ways, first with feeding the Constructor:

>>> from OOHTML import *
>>> C = Constructor()
>>> C.feed(o('html'),                  #open HTML tag
             o('head'),                #open Head
             c('head'),                #close Head
             o('body'),
               o('div'),
                 r('Hello World!'),    #raw content
                 s('area'),            #singleton (self closing element)
               c('div'),
             c('body'),
            c('html'))

Or using class methods, the above example can be rewriten as:

>>> from OOHTML import *
>>> C = Constructor()
>>> C.open('html').open('head').close('head').open('body')
>>> C.open('div').raw('Hello World!').single('area').close('div')
>>> C.close('body').close('html')

to render the constructor as html, you can use render() method:

>>> C.render()

Each of opening, singleton or raw elements can have an id (not the HTML ID of the element) so they can be accessible:

>>> R = r('Hello World', 'message') #a raw element with id 'message'
>>> O = o('div', {}, 'menu')        #opening element with id 'menu'
>>> S = s('img', {}, 'bg')          #singleton with id 'bg'
>>> C.feed(R)
>>> C.getElementById('message')
>>> C.removeElementById('message')

You can insert a Constructor object inside another Constructor:

>>> sampleConstructor = Constructor()
>>> C.addAfterId('sampleID', sampleConstructor)

There are numerous methods for accessing elements and changing its data:

>>> C.getElementById('message').value          #Raw elements use .value to store their data
>>> C.getElementById('sample').attributes      #Opening and Singleton elements have .attribute
>>> C.getElementById('sample').tag             #Opening, Closing & Singleton elements have .tag
>>> C.getElementById('sample').id              #All elements have .id

Opening and Singleton Elements can have attributes:

>>> div = o('div', {'class':['message', 'floater']}, 'contents')
>>> C.feed(div)
>>> div.addAtributes({'id': ['sample']})

You can use this attributes to select elements:

>>> C.getElementsByAttributes({'class': ['test']})    #This returns a generator

To show you an example:

>>> from OOHTML import *
>>> C = Constructor()

>>> C.feed(o('html'),
         o('head'),
           o('script', {'type': ['text/javascript'], 'src':['script.js']}),
           c('script'),
           o('style', {'type': ['text/css'], 'src':['style.css']}),
           c('style'),
         c('head'),
         o('body'),
           o('div', {'class':['message']}),
             r('Hello World!!!', 'message'),
             s('img', {'alt': ['Hello'], 'src':['img.jpeg']}),
           c('div'),
           o('div', {'class':['message', 'floater']}, 'contents'), c('div'),
         c('body'),
       c('html'))

>>> C.getElementById('message').value = "HTML CONSTRUCTOR!!!"
>>> C.addAfterId('contents', Constructor().open('div').raw('OOHTML').single('br').close('div'))
>>> print(C.render())

The above outputs:

<html>
    <head>
        <script type = "text/javascript" src = "script.js">
        </script>
        <style type = "text/css" src = "style.css">
        </style>
    </head>
    <body>
        <div class = "message">
            HTML CONSTRUCTOR!!!
            <img src = "img.jpeg" alt = "Hello"/>
        </div>
        <div class = "message floater">
            <div>
                OOHTML
                <br/>
            </div>
        </div>
    </body>
</html>

Explore source code for more info.

Download

Download package from here: https://pypi.python.org/pypi/OOHTML or simply install with pip install OOHTML

Project Info

Github project page: https://github.com/pooya-eghbali/OOHTML PyPi: https://pypi.python.org/pypi/OOHTML Mail me at: persian.writer [at] Gmail.com

Metadata

Release files for OOHTML 0.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 OOHTML 0.1
File Size Uploaded Provenance
OOHTML-0.1.zip 1.9 kB Without provenance Details

Release files / OOHTML-0.1.zip

Download URL OOHTML-0.1.zip
Size 1.9 kB
Tags Source
SHA-256 checksum
How to use checksums
483f0a1c582b467bb42d42361edceb64e4e654124e117f03da8339b537f26ed0
BLAKE2b-256 checksum
How to use checksums
dadeeb45c92eaa49e096139fcbd8b005f5e24ea99f934b6fc0393e8fbf0c65e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for OOHTML 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file No provenance

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