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.0.75.tar.gz (29.3 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.75-py3-none-any.whl (37.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyfrontkit-1.0.75.tar.gz
  • Upload date:
  • Size: 29.3 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.75.tar.gz
Algorithm Hash digest
SHA256 33d251af91e59e698bcd4a07e83a834765b3e9207f010631b4e5b4565f84797a
MD5 2eeb9519f7f76b61cc23d3922f04a801
BLAKE2b-256 90faccdb8e00bac02a46fcf7a947550edb427fbe2eda6ed2ef58290fac29a55f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfrontkit-1.0.75-py3-none-any.whl
  • Upload date:
  • Size: 37.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.75-py3-none-any.whl
Algorithm Hash digest
SHA256 5a48075b33f966f104994d3e39249ef85b8b500117fb870c3a6d60b2c0f43a0a
MD5 65a03bdc6e4b5139e96d0809c24d6049
BLAKE2b-256 d2a16e7d52f0deffdf5608755212112bc38383c65573f9cbf8dfb3e3d8d90cb6

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