Skip to content

jpsca/jx

Repository files navigation

Jx

python: 3.12, 3.13, 3.14 license: MIT

Python server-side components

From chaos to clarity: The power of components in your server-side-rendered Python web app.

How It Works

Jx is a Python library for creating reusable template components with Jinja2. It works by pre-parsing the template source and replacing TitleCased HTML tags with Jinja calls that render the component.

Component Definition

Components are defined as regular Jinja2 templates (.jinja files) with special metadata comments:

  • {# def parameter1 parameter2=default_value #} - Defines required and optional parameters
  • {# import "path/to/component.jinja" as ComponentName #} - Imports other components
  • {# css "/path/to/style.css" #} - Includes CSS files
  • {# js "/path/to/script.js" #} - Includes JavaScript files

Example component:

{# def message #}
{# import "button.jinja" as Button #}

<div class="greeting">{{ message }}</div>
<Button text="OK" />

Usage Example

from jx import Catalog

# Create a catalog and add a components folder
catalog = Catalog("templates/components")

# Render a component with parameters
html = catalog.render("card.jinja", title="Hello", content="This is a card")

About

The next generation of Python server-side components

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages