Skip to Content
✨ v3.0.4 Released - See the release notes
DocumentationGetting Started

Getting Started

Once Fubam is installed, you can render your first template in just a few steps. This section shows the correct workflow: creating a Fubam instance, writing a .pmx file (pure Python), and generating clean HTML output.


1. Create an Instance

Fubam assumes a default template directory, but you can explicitly define your own:

from fubam import Fubam compiler = Fubam(templates_dir="Templates")

This tells Fubam where to search for your .pmx template files.


2. Create Your First Template

Inside the directory you specified (Templates), create:

Templates/home.pmx

How .pmx Templates Work

A .pmx file is pure Python, executed inside a special environment where HTML tags are available as Python functions (div(), h1(), p(), etc).

Each template must define an Export variable — this becomes the final HTML output.

Example template:

# Templates/home.pmx Export = HTML( h1("Hello, World!"), p("This page was generated with Fubam.") )

You can use any real Python here — variables, loops, functions, conditions.


3. Render the Template

Use the compiler instance to render the file. The resources argument is optional and allows you to pass variables into the template.

html = compiler.renderTemplate("home.pmx", resources={ "name": "Aman" })

Note on Output

Fubam().renderTemplate() always returns a plain string containing the final HTML. You can use this string with any Python server or framework — Flask, FastAPI, Django responses, custom servers, or static file generation.

Example:

html = compiler.renderTemplate("home.pmx")

You can now:

  • return it in a Flask route
  • send it in a FastAPI response
  • write it to a file
  • embed it in any backend system
  • use it inside CI pipelines or static-site generators

4. Save or Use the HTML Output

To save the generated HTML as a static file:

with open("home.html", "w") as f: f.write(html)

Your home.html is now ready to open in any browser.


5. What’s Next?

Now that you’ve rendered your first page, explore the core features of Fubam:

  • Layouts — define a shared base structure for all pages
  • Components — write reusable UI blocks as Python functions
  • SEO Injection — automatically insert <meta> tags
  • Asset Injection — optionally inline CSS/JS for faster loads

Continue with Core Concepts to understand how Fubam processes templates and builds pages.

Last updated on