Quick Start¶
This guide walks you through creating your first PyJinHx component.
Project Structure¶
A typical PyJinHx components folder looks like this:
my_project/
└── components/
└── ui/
├── button.py # Component class
└── button.html # Component template
Step 1: Create a Component Class¶
Create components/ui/button.py:
from pyjinhx import BaseComponent
class Button(BaseComponent):
id: str
text: str
variant: str = "default"
Every component:
- Inherits from
BaseComponent - Has an
idfield — auto-generated (pjx-<n>) if omitted; redeclareid: strto require one - Can have additional fields with optional defaults
Step 2: Create the Template¶
Create components/ui/button.html (same directory as the class):
Template Discovery
PyJinHx automatically finds templates by converting the class name to snake_case.
Button → button.html, ActionButton → action_button.html — kebab-case
(action-button.html) and .jinja candidates are also tried; see
PascalCase tags for the full list.
Step 3: Render the Component¶
Create main.py:
from pyjinhx import Renderer
# Set the template search path
Renderer.set_default_environment("./components")
# Import components after setting the default environment so template
# discovery is rooted at the path above.
from components.ui.button import Button
# Create and render
button = Button(
id="submit-btn",
text="Submit",
variant="primary"
)
html = button.render()
print(html)
Output:
What's Next?¶
- Build an App — full step-by-step tutorial with Why? panels (start here for a real app)
- Creating Components - Fields, validation, and templates
- Nesting Components - Compose components together
- Reactivity - Dependency-aware HTMX updates