Skip to content

micheltlutz/Winged-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Winged-Python

main codecov codebeat badge Reviewed by Hound PyPI version

=============

Winged-Python is an innovative Domain-Specific Language (DSL) library for efficient HTML writing in Python. Mirroring its Swift counterpart, Winged-Python is based on the DSL concept, focusing on simplification and specificity in HTML generation. Using the Composite design pattern, the library enables developers to construct HTML structures in a logical, organized, and reusable manner.

This library is created to be fully independent, not requiring integration with specific server frameworks or front-end libraries. This offers developers the freedom to use Winged-Python across a variety of projects, from simple static pages to complex web applications, keeping the code clean, readable, and efficient.

PyPI Releases Page

https://pypi.org/project/winged-python/

  • Releases Page

Install

pip install winged-python==0.1.0

Simple Usage Example

from winged.HTML.div import Div
from winged.HTML.h import H
from winged.HTML.table import Table
from winged.HTML.string import String

divC = Div(("class", "container"))

h = H("1")
h.add(String("Hello World"))
divC.add(h)

table = Table()
table.add_table_headers(["Name", "Age", "Height", "Location"])  # Define headers

table.add_row()
table.add_in_row(String("John"))
table.add_in_row(String("25"))
table.add_in_row(String("1.80"))
table.add_in_row(String("New York"))

table.add_row()
table.add_in_row(String("Maria"))
table.add_in_row(String("23"))
table.add_in_row(String("1.50"))
table.add_in_row(String("New Jersey"))

divC.add(table)

print(divC.generate())

Output

<div class="container">
  <h1>Hello World</h1>
  <table>
    <thead>
      <th>Name</th>
      <th>Age</th>
      <th>Height</th>
      <th>Location</th>
    </thead>
    <tbody>
      <tr>
        <td>John</td>
        <td>25</td>
        <td>1.80</td>
        <td>New York</td>
      </tr>
      <tr>
        <td>Maria</td>
        <td>23</td>
        <td>1.50</td>
        <td>New Jersey</td>
      </tr>
    </tbody>
  </table>
</div>

Usage with FastAPI Render

from fastapi import FastAPI
from fastapi.responses import HTMLResponse

from winged.HTML.div import Div
from winged.HTML.h import H
from winged.HTML.string import String


@app.get('/', response_class=HTMLResponse)
async def home():
    divC = Div(("class", "container"))
    h = H("1")
    h.add(String("Hello World"))
    divC.add(h)
    return divC.get_string()  # Return HTML String

Contributing

To contribute, it's simple, follow the guidelines below to prepare your development environment

Create environment

User OS terminal or IDE terminal

Linux or macOS

python3 -m venv venv
source venv/bin/activate

Windows

.\venv\Scripts\activate.bat
.\venv\Scripts\activate.ps1`

Install dependencies

python3 -m pip install -r requirements.txt

Run tests

pytest

TODO

  • Make documentation with Sphinx

About

Python HTML Made Simple and Powerful

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages