A Python-based HTML builder with built-in SEO, accessibility, layout injection, and optional minification.
Project description
Fubam
The Lightweight Python Frontend Generator
- Version: 1.0 Stable Release
- Release Date: 29 January 2026
- Author: Aman Ali
- Documentation: https://fubam.mdadsolutions.com/docs/
FUBAM (Functions-Based Markup for Python) is a lightweight Python library for generating HTML using pure Python. It enables complex UI designs with components, loops, conditional rendering, and automated SEO/performance enhancements.
Table of Contents
- Fubam
Installation
Using Git
git clone https://github.com/amanalimon/fubam.git
Importing Fubam
from fubam import Fubam
Fubam functions return plain HTML strings compatible with frameworks like Flask (return string) or Django (HttpResponse(string)).
Basic Usage
Using Templates
templates/page.pmx:
Export = html(
head(
title("My Fubam Project"),
link({"rel":"stylesheet","href":"bootstrap.css"})
),
body(
div({"class":"container"}, h1(message))
)
)
Server-side:
from fubam import Fubam
compiler = Fubam(templates_dir="templates")
context = {"message": "Hello, world!"}
return compiler.renderTemplate("page", resources=context)
How Fubam Works
- HTML representation: Each function corresponds to an HTML tag.
- Children & Attributes:
div({"class":"mydiv"}, "Text")→<div class="mydiv">Text</div>. - Text Content: Strings represent text nodes.
Export = p("Fubam is a lightweight Python templating engine")
Templates & Components
Components
Define reusable HTML blocks in a separate file (components.pmx):
Footer = footer(
div("Links"),
div("Copyright © 2023")
)
Use in template:
HTML = wrapper(body("This is a body") , useComponent("Footer")) # `wrapper` is use for combining tags/modules
Layouts
Layouts provide a reusable page structure across multiple templates. They define common elements like headers, footers, and main containers, while letting templates inject content into placeholders.
layout.pmx:
Export = HTML(
head(
title(page_title if "page_title" in globals() else "My Fubam Site"),
meta(charset="UTF-8")
),
body(
header(
h1("Site Header"),
nav(
a("Home", href="/"),
a("About", href="/about")
)
),
main(__content__), # Placeholder for page-specific content
footer(
p("© 2025 Fubam")
)
)
)
template.pmx:
page_title = "Home Page"
Export = useLayout("layout.pmx", content=wrapper(
h2("Welcome to Fubam!"),
p("This page uses a layout for consistent structure.")
))
Notes:
__content__is where page template content is injected.- You can define multiple placeholders for flexibility (e.g.,
content.var1,content.var2). - Layouts can use Python logic to dynamically adjust content.
Loops
Dynamic rendering with Python loops:
dbResult = [{"name": "Aman", "age": 17}, {"name": "Lorem", "age": 27}]
return render_pythonMarkup("page", resources={"persons": dbResult})
Template:
def card(name, age):
return div(
h1(f"Username: {name}"),
p(f"Age: {age}")
)
Export = body(
div([card(p["name"], p["age"]) for p in persons])
)
Conditionals
Render content based on a condition:
return render_pythonMarkup("page", resources={"loggedin": loggedIn})
Template:
HTML = "<homepage content>" if loggedin else render_pythonMarkup("../templates/login")
SEO, Performance, and Accessibility
SEO
If SEO=True:
- Automatic
<title>tag. - Meta tags for
viewport,description,keywords,Content-Type,X-UA-Compatible.
Performance
- Images automatically receive
loading="lazy". - Optional CSS/JS inlining (
InjectCSS/InjectJS). - Minifies
<style>and<script>tags.
Accessibility
- Images receive default
alt="There was an image". - Automatic
<!DOCTYPE html>andlang="en"on<html>.
Configuration
Default settings:
Performance = True
SEO = True
Accessibility = True
InjectCSS = False
InjectJS = False
MinifyStyleTags = True
MinifyScriptTags = True
Pre-serving Compression
compressCSSFile("style.css") # outputs style.min.css
compressJSFile("script.js") # outputs script.min.js
compressCSSFile("style.css", "dist/main.css") # custom path
CLI Entry Point
Fubam provides a command-line interface for compiling .pmx templates without writing Python code.
Usage
python3 -m fubam <files_or_directories> [options]
Options
| Flag | Description |
|---|---|
-r, --recursive |
Process directories recursively |
--ext |
Set output file extension (e.g., html) |
--ref |
Load a JSON file with template resources |
-o, --out |
Set the output directory (default: ./) |
Examples
Compile a single template
python3 -m fubam templates/page.pmx --ext=html
Compile a directory recursively
python3 -m fubam templates/ -r --ext=html
Compile to a custom output directory
python3 -m fubam templates/ -r --ext=html --out=build
Compile with template resources from JSON
python3 -m fubam templates/ -r --ext=html --ref=ref.json
Pros & Highlights
- Full Python integration within HTML.
- Lightweight and fast.
- Supports reusable components.
- SEO, accessibility, and performance optimizations included.
- Minimal boilerplate.
- Ideal for rapid prototyping, teaching, and lightweight production.
Advanced Tips
- Use Python string methods (
replace,join, etc.) directly in templates. useComponent()allows rendering reusable blocks dynamically.
Official Documentation: https://fubam.mdadsolutions.com/docs/
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fubam-1.0.0.tar.gz.
File metadata
- Download URL: fubam-1.0.0.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77e38761bfe3b68ec59bf90a1dd469b6057d8d2971e771dc99841cd84259e968
|
|
| MD5 |
75ca86795abfc8b28ec7cf566133fc33
|
|
| BLAKE2b-256 |
e3f5a26521f0c0f5d3e42ff27a7190c1f569aff9cedfde40c422338c9d9eb39f
|
File details
Details for the file fubam-1.0.0-py3-none-any.whl.
File metadata
- Download URL: fubam-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46f4233effdf4632e5b42dac15a660703002492a1980377cc26ff201708b73ba
|
|
| MD5 |
3a904bfaea936576624e17b7fb164733
|
|
| BLAKE2b-256 |
36256aaddeb7fc20a290265ed46df25d4ab0beebed00c41a1a81bdf2aa005920
|