Skip to main content

Easy and quick html builder with natural syntax correspondence (python->html). No templates needed. Serves pure pythonic library with no dependencies.

Project description

Airium

Bidirectional HTML-python translator.

PyPI download total PyPI version fury.io PyPI license PyPI pyversions PyPI status pipeline status coverage report

Key features:

  • simple, straight-forward
  • template-less (just the python, say goodbye to all the templates)
  • DOM structure is strictly represented by python indentation (with context-managers)
  • gives much cleaner html than regular templates
  • equipped with reverse translator: html to python

Basic html page (hello world)

from airium import Airium
a = Airium()

a('<!DOCTYPE html>')
with a.html(lang="pl"):
    with a.head():
        a.meta(charset="utf-8")
        a.title(_t="Airium example")

    with a.body():
        with a.h3(id="id23409231", klass='main_header'):
            a("Hello World.")

html = str(a) # casting to string extracts the value

print(html)

Prints such a string:

<!DOCTYPE html>
<html lang="pl">
  <head>
    <meta charset="utf-8" />
    <title>Airium example</title>
  </head>
  <body>
    <h3 id="id23409231" class="main_header">
      Hello World.
    </h3>
  </body>
</html>

Simple image in a div

from airium import Airium
a = Airium()

with a.div():
    a.img(src='source.png', alt='alt text')
    a('the text')

html_str = str(a)
print(html_str)
<div>
    <img src="source.png" alt="alt text" />
    the text
</div>

Table

from airium import Airium
a = Airium()

with a.table(id='table_372'):
    with a.tr(klass='header_row'):
        a.th(_t='no.')
        a.th(_t='Firstname')
        a.th(_t='Lastname')

    with a.tr():
        a.td(_t='1.')
        a.td(id='jbl', _t='Jill')
        a.td(_t='Smith')  # can use _t or text

    with a.tr():
        a.td(_t='2.')
        a.td(_t='Roland', id='rmd')
        a.td(_t='Mendel')

table_str = str(a)
print(table_str)
<table id="table_372">
  <tr class="header_row">
    <th>no.</th>
    <th>Firstname</th>
    <th>Lastname</th>
  </tr>
  <tr>
    <td>1.</td>
    <td id="jbl">Jill</td>
    <td>Smith</td>
  </tr>
  <tr>
    <td>2.</td>
    <td id="rmd">Roland</td>
    <td>Mendel</td>
  </tr>
</table>

Reverse translation

from airium import from_html_to_airium

html_str = """\
<!DOCTYPE html>
<html lang="pl">
  <head>
    <meta charset="utf-8" />
    <title>Airium example</title>
  </head>
  <body>
    <h3 id="id23409231" class="main_header">
      Hello World.
    </h3>
  </body>
</html>
"""

py_str = from_html_to_airium(html_str)

assert py_str == """\
#!/usr/bin/env python
# File generated by reverse AIRIUM translator.
# Any change will be overridden on next run.
# flake8: noqa E501 (line too long)

from airium import Airium

a = Airium()

a('<!DOCTYPE html>')
with a.html(lang='pl'):
    with a.head():
        a.meta(charset='utf-8')
        a.title(_t='Airium example')
    with a.body():
        a.h3(klass='main_header', id='id23409231', _t='Hello World.')
"""

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

airium-0.0.6.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

airium-0.0.6-py2.py3-none-any.whl (14.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file airium-0.0.6.tar.gz.

File metadata

  • Download URL: airium-0.0.6.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for airium-0.0.6.tar.gz
Algorithm Hash digest
SHA256 8c04a5541b01ddbe267699306a93ed0ab41b0e43f3dc7cd0b7ad665b4c9ccc36
MD5 3aaa95cb1fd7a42f6a4b0d14298ef41d
BLAKE2b-256 73aa1f3fefb65e6dced33af7bcf6a1b746f56b62d3301164436f18fa99c6896e

See more details on using hashes here.

File details

Details for the file airium-0.0.6-py2.py3-none-any.whl.

File metadata

  • Download URL: airium-0.0.6-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for airium-0.0.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 980eead6f1ed5bb79a1692ced5aad4dad233d65d5106d93fb1a46d9bd6a1828a
MD5 bc06384eba6c7b414fab6901c33e2140
BLAKE2b-256 01ed24c0776205098bf1a48a65011b22683f7f51fa20e470965fe87029bd94c3

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