Skip to main content

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

Project description

Perfecto. Te preparo un README completo en inglés actualizado para pyfrontkit, con todos los puntos que discutimos y el ejemplo usando import pyfrontkit. Aquí va:

# PYFRONTKIT: Python DSL for Programmatic Web Generation

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)

**PYFRONTKIT** is a Python library designed to **programmatically generate HTML and CSS web structures**.  
It acts as a **Domain-Specific Language (DSL)**, allowing developers to build web pages entirely in Python.

Unlike frontend frameworks like React or Vue, PYFRONTKIT focuses on **rapid prototyping**, styling templates, and automatic CSS generation, rather than dynamic reactivity.

---

## Key Features

- **Pythonic HTML Syntax:** Use classes or functions (`Div`, `div`, `Section`, etc.) to build page elements without writing raw HTML.
- **Accumulative DOM:** Global functions for IDs allow you to add children to any element without deep nesting:
  ```python
  Div(id="container")
  container(Section(ctn_p="Hello World"))
  • Automatic CSS Generation: All id, class, and tag selectors are collected to generate a ready-to-use style.css.
  • Native JS Support (basic): Inline <script> in <head> is supported.
  • Template Styles (future-ready): Ability to apply preset style templates (e.g., simple_blue) for a cohesive look.
  • Final Output: Generates index.html and style.css ready to open in any browser.

Installation

Install directly from PyPI:

pip install pyfrontkit

Or from GitHub:

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

💡 Usage Example

The following Python code generates a semantic page structure with styles:

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

# Create the document
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
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.")
)

# Services Section
Section(id="services", style="padding:40px 20px; max-width:1000px; margin:auto;")
services(
    Ul(id="service_list")
)
service_list(
    Li(ctn_p="Custom web development"),
    Li(ctn_p="Technology consulting")
)

# 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.")
)

# Generate files
doc.create_document()

This produces index.html and style.css ready to open in a browser.


Styling Possibilities

PYFRONTKIT provides three layers of control for styles:

  1. Inline Styles: Directly on any block using style="...".
  2. Generated CSS: Automatic style.css is created with all selectors.
  3. Template Styles (future): Apply pre-defined style templates such as simple_blue, controlling colors, fonts, and layout patterns globally.

License

This project is released under the GNU General Public License version 3 (GPLv3).

  • Free to use, modify, and redistribute.
  • Any derivative work must also be free software (copyleft).

See the LICENSE file for full details.


About the Author

Created by Eduardo Antonio Ferrera Rodríguez as part of an advanced Python learning journey, exploring OOP, library design, and DSL creation.

Contributions and feedback 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-0.9.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

pyfrontkit-0.9.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyfrontkit-0.9.0.tar.gz
Algorithm Hash digest
SHA256 bbc507db76e2ec0243611620374424b784ba456dc447f489e47a34538271d94b
MD5 4821900e8b30167fb2b7abdb14481374
BLAKE2b-256 4a390f38885d03faffcc47ebfc9e1f86cebe768df4c1ed4782d397aa85f8157c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfrontkit-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 14.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-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5b2f31c8a586bca23d8da27356e86b3ac580a4b224654f0b9568d450a4e0723
MD5 a8fd34099f5a312711696986d78282e2
BLAKE2b-256 1c4abb4061fa5e8e0db6fddce8776a2ceebc574faee04745da1449ad7170ad37

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