diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 0000000..9134d44 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1,5 @@ +title: python-lucide +description: Lucide icons as Python strings +baseurl: /python-lucide +url: https://mmacpherson.github.io +theme: minima diff --git a/docs/_includes/footer.html b/docs/_includes/footer.html new file mode 100644 index 0000000..4e13a1b --- /dev/null +++ b/docs/_includes/footer.html @@ -0,0 +1,4 @@ + diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..650a5a5 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,116 @@ +--- +layout: default +title: python-lucide — Lucide icons as Python strings +--- + +# python-lucide + +*[Mike Macpherson](https://github.com/mmacpherson)* + +**TL;DR:** All 1600+ [Lucide](https://lucide.dev) icons available as SVG strings +in Python. `pip install python-lucide`, import, embed. No JavaScript, no icon +fonts, no client-side rendering step. Every icon on this page is a real Lucide +SVG, sourced from the package itself. + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ +## the itch + +I like building HTML on the server. Not templates-with-holes, but actual +programmatic markup — [hiccup](https://github.com/weavejester/hiccup) in +Clojure, [cottonmouth](https://github.com/adigitoleo/cottonmouth) in Python, +data structures that *are* the page. [FastHTML](https://fastht.ml/) takes that +ethos and makes it a full framework: pure Python components, web-standards-first, +no transpilation, no virtual DOM, no magic. + +The pattern extends to interactivity. +[Datastar](https://data-star.dev/), [HTMX](https://htmx.org/), and FastHTML's +own HTMX integration all follow the same principle: the server renders HTML, the +browser just shows it. No client-side JavaScript framework sitting between you +and your markup. + +[Lucide](https://lucide.dev) is a beautiful, well-maintained icon set — 1600+ +icons, all SVG, consistent style. But its standard integration assumes a +JavaScript runtime. You include the JS bundle and call `lucide.createIcons()`, +which walks the DOM and replaces placeholder elements with SVG. That works fine +for a traditional SPA. In a server-rendered world, though, you have to call +`lucide.createIcons()` again after every DOM swap — every HTMX response, every +Datastar fragment, every partial update. It's a small thing, but it grates. + +The fix is obvious: just embed the SVG directly. If the icon is already inline +in the HTML, there's nothing to initialize, nothing to re-run, nothing to +coordinate. The server sends the icon, the browser renders it, done. + +## the approach + +python-lucide packs all 1600+ Lucide SVGs into a ~780 KB SQLite database that +ships with the package. One function call gets you an icon: + +```python +from lucide import lucide_icon + +svg = lucide_icon("house") +# → ' + + +

+ +It works with anything that renders HTML on the server. FastHTML, Flask, Django, +FastAPI, plain string concatenation — if you can return an HTML string, you can +use these icons. No framework coupling, no special integration needed. + +If 780 KB of icons is too much for your deployment, the included `lucide-db` CLI +trims the database to just the icons you actually use: + +```bash +lucide-db -i house,settings,heart,search -o slim.db +export LUCIDE_DB_PATH=slim.db +``` + +## links + +- [ repo](https://github.com/mmacpherson/python-lucide) — source, README with full API reference +- [ pypi](https://pypi.org/project/python-lucide/) — `pip install python-lucide` +- [ lucide](https://lucide.dev) — the icon set itself +- [ fasthtml](https://fastht.ml/) — the framework that motivated this