Skip to main content

A Python tool to generate HTML and CSS with programmale 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.1.0.tar.gz (29.6 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.1.0-py3-none-any.whl (36.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyfrontkit-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d6c1a91aeee3a746529b000f6bf6b11180181f97b46a6c0c82bda4377e5a5fa5
MD5 771ce69c1f55ba90740fdf2971d356b0
BLAKE2b-256 fdfe67702984fa64670ff3f8b2a88d1042ac494cbd9a59dd35ca95056c35fa04

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfrontkit-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 36.9 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 473049ac4ab629dbc3c98e01cdcc867fe20b333ddebf8bd2f157e73984e64eb2
MD5 f35175832310554d5f631a822f0ab70b
BLAKE2b-256 5a7b034b36922e052f46bdc7b6347842033a079760b46d016153ffb85e273247

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