Basilico: Build HTML Components in Python

What My Project Does

Basilico is a Python package inspired by gomponents. It enables developers to create and maintain reusable HTML components directly in Python, promoting cleaner and more modular codebases for web development projects. Additionally, Basilico includes built-in support for HTMX and AlpineJS, making it easier to create dynamic, interactive frontends without relying on heavy JavaScript frameworks.

Target Audience

Basilico is aimed at Python developers who want to integrate component-based development into their web projects.

Comparison

While gomponents focuses on Go, Basilico brings similar functionality to Python. It offers a Pythonic way to create and manage HTML components, combining simplicity and flexibility.

Check it out: https://github.com/arskode/basilico

10 comments · 90% upvoted · other discussions

comments

Drevicar

Very nice library. You even properly escape injected HTML. I’ll have to give this library a shot in my next side project.

I do have 2 complaints though. 1, html class as a python class feels weird, I feel like it should be an attribute on the html element class. We don’t normally specify the class to use and child elements in the same scope. 2, non-native html should be moved to another package or optional dependencies, such as your htmx and alpine code, and maybe even come with a bundled version of the NPM package for local serving if I didn’t want to use a CDN.

larsga

, html class as a python class feels weird, I feel like it should be an attribute on the html element class.

This stuck out for me, too.

Safe_Duty8392

Very nice project, I think the approach you took was very cool, congratulations for the project, 1+ star.

But have you heard of a project called HTPY ?

InvaderToast348

Currently using Jinja + Jinjax. How does this compare? My current setup is very simple and maintainable: a "components" folder with all the Jinja files, then use jinjax catalog to load the dir. Works a treat; my only issue is with vscode integration - limited syntax highlighting and no go-to-definition and other intellisense features which is pretty annoying. I'd also love a way to get mypy and/or pylint to work with the Jinja templates to improve code quality and ensure the component definitions are kept up to date with the rest of the codebase, especially type hints for args.

It looks somewhat similar to another project I came across recently where they used __getitem__ which imo gives a much cleaner syntax, like:

body[ h1[...], div[ p[...], ], ]

ajmssc

What project is that

Previous-Ad-7181

fasthtml and htpy

Smash-Mothman

I'm genuinely curious, what are you trying to solve with this library? The speed of writing, the ease of use, ect

diabloman8890

How does this differ from things like Plotly Dash?

deadwisdom

Use web component enabled libraries please. So tired of framework after framework that aren’t interoperable.

Drevicar

This python library doesn’t implement any JS, it is entirely python and server rendered. So it is even more interoperable than a web component library.

That said, if you wanted to provide your own web components you can wrap it in a python element class from this library to make it easy to use from within python.