Skip to main content

A Python tool to generate HTML and CSS with programmable syntax.

Project description

PYFRONTKIT

A Pythonic DSL for Programmatic HTML & CSS Generation

License: GPL v3

PyFrontKit is a Python-based DSL designed to generate HTML and CSS programmatically, providing a clean, elegant, and highly readable syntax inspired by modern component-driven development.

It allows developers to build complete web pages using pure Python, without writing raw HTML manually.
Ideal for:

  • rapid prototyping
  • teaching HTML structure
  • generating static sites
  • automating documentation pages
  • template-driven UI generation

🚀 Features

✔ Pythonic HTML Syntax

Create elements using class constructors or ID-based global functions:

Div(id="container")
container(Section(ctn_p="Hello World"))

✔ Accumulative DOM

Any element with an id="..." automatically generates a global callable:

header(Div(ctn_h1="Welcome"))

✔ Automatic CSS File Generation

All selectors (id, class, and tag names) are scanned and exported into style.css.

✔ Inline Style Support

Every tag accepts a native HTML5 style="..." attribute.

✔ Clean Separation Between Content & Structure

ctn_p, ctn_h1, ctn_div, etc. allow pythonic, newline-based content — internally converted to <p>, <br>, <h1>, etc.

✔ Ready-to-open Output

The library produces:

index.html
style.css

📦 Installation

From PyPI (recommended)

pip install pyfrontkit

From GitHub

pip install git+https://github.com/Edybrown/pyfrontkit.git

💡 Basic Usage Example

from pyfrontkit import HtmlDoc, Div, Section, Header, Nav, Ul, Li, Footer

doc = HtmlDoc(title="My Professional Page")

# Header
Header(id="header", ctn_p="Welcome to My Professional Site",
       style="background-color:#2c3e50; color:white; padding:20px 0;")

# Navigation
Nav(id="nav", style="background-color:#34495e; display:flex; justify-content:center;")
nav(
    Div(ctn_p="Home", style="color:white; padding:15px 25px;"),
    Div(ctn_p="Services", style="color:white; padding:15px 25px;")
)

# Introduction
Section(id="intro", style="padding:40px 20px; max-width:1000px; margin:auto;")
intro(
    Div(ctn_p="This is the introduction section, generated entirely in Python.")
)

# Footer
Footer(id="footer", style="background-color:#2c3e50; color:white; text-align:center; padding:20px 0;")
footer(
    Div(ctn_p="© 2025 My Professional Site. All rights reserved.")
)

# Build files
doc.create_document()

Output generated:

index.html
style.css

🎨 CSS Usage Guide

PyFrontKit automatically generates a style.css file containing all selectors found in the HTML:

Example auto-generated output:

#header {}
#nav {}
#intro {}
#footer {}
div {}
section {}

You can now fill these selectors manually:

#header {
    background:#2c3e50;
    color:white;
    padding:20px 0;
}

Styling methods

1. Inline Styles (fast prototyping)

Div(ctn_p="Hello", style="color:red; margin-top:10px;")

2. External CSS File (recommended)

Edit the generated style.css:

div {
    font-family: Arial, sans-serif;
}

📁 Examples (with screenshots)

A full set of examples is included in the repository:

examples/
│
├── 01-basic/
│   ├── example.py
│   ├── index.html
│   ├── style.css
│   └── screenshot.png
│
├── 02-intermediate/
│   ├── example.py
│   ├── index.html
│   ├── style.css
│   └── screenshot.png
│
└── 03-professional/
    ├── example.py
    ├── index.html
    ├── style.css
    └── screenshot.png

Run any example:

python examples/03-professional/example.py

🛠 Roadmap

Planned features:

  • CSS Template Packs (global themes)
  • Automatic external CSS compilation
  • Reusable Python components
  • Dynamic <script> builder
  • Minified output mode
  • Plugin system for custom tags

📄 License

Released under the GNU GPLv3 license.
You are free to use, modify, and redistribute this project.
Any derivative work must remain open-source under the same license.


👤 Author

Created by Eduardo Antonio Ferrera Rodríguez
A project combining:

  • advanced Python OOP practice
  • DSL design
  • frontend structure understanding
  • static web automation

Contributions, suggestions, and pull requests are welcome!

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfrontkit-1.0.49.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

pyfrontkit-1.0.49-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

Details for the file pyfrontkit-1.0.49.tar.gz.

File metadata

  • Download URL: pyfrontkit-1.0.49.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0rc1

File hashes

Hashes for pyfrontkit-1.0.49.tar.gz
Algorithm Hash digest
SHA256 78de83f8c5484627b37909beda625015bcb22165de3765537708d32caac97465
MD5 f33a6a67528414bab55cc4c3bf8626b2
BLAKE2b-256 5dbb131551dd4e8705616c14a8b4a932fb224a68fa2bda961c7888e71cb265f0

See more details on using hashes here.

File details

Details for the file pyfrontkit-1.0.49-py3-none-any.whl.

File metadata

  • Download URL: pyfrontkit-1.0.49-py3-none-any.whl
  • Upload date:
  • Size: 29.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0rc1

File hashes

Hashes for pyfrontkit-1.0.49-py3-none-any.whl
Algorithm Hash digest
SHA256 e77daa7246d0fc9043f2fd400de43f993fd005f4ad79c175196b35d4d08146d1
MD5 d839d2d46229b09367f2fd1964278b02
BLAKE2b-256 1d15ae739e0d82a9b8a1ee8353d7082ba3e70036edb3dc6e541c00450a211feb

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