Skip to main content

fastlucide

A convenient FastHTML wrapper for the excellent Lucide icon library.

Installation

Install from pypi

$ pip install fastlucide

How to use

from fastlucide import *

SvgSprites

The most convenient way to use fastlucide is to create an SvgSprites class, passing in a short prefix to ensure IDs are unique:

ss = SvgSprites('l-')

Then add icons whereever you want to show them, by calling the ss object with the desired name. Any additional attrs are added to the SVG.

(NB: we use show here to cause the SVGs to render in the notebook/docs. This isn’t needed in a regular FastHTML app.)

from fasthtml.common import show,Div
show(ss('a-arrow-down'))
show(ss('accessibility'))

Finally, be sure to render ss itself, to add the sprite sheet to the DOM.

show(ss)
<style>.lucide-icon { stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }</style>

fastlucide.icons

If you dynamically add a new icon to the DOM after loading the page (e.g using an HTMX swap), then the SvgSprites element will not contain that icon, so it won’t display. One solution to this is to preinitialize using e.g SvgSprites(nms=['air-vent', 'apple']).

Alternatively, you can import any icon name (sentence-cased, with underscores instead of hyphens) from fastlucide.icons, which will create an icon-generating function and also adds the name to spritesheet, which is an SvgSprite singleton.

from fastlucide.icons import spritesheet, Air_vent, Apple, Circle, X

You can now call Air_vent and Apple as functions – be sure to also include spritesheet in the DOM. If you use the same icon multiple times, you can optionally store it in a variable.

vent = Air_vent(stroke='green')
show(vent, Apple(sz=48, fill='red'), vent,
     spritesheet)

<style>.lucide-icon { stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }</style>

You can create a combination of SVGs:

show(Circle(stroke='steelblue') + X(stroke='crimson'))
show(spritesheet)

<style>.lucide-icon { stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }</style>

Because fastlucide.icons supports the __dir__ protocol, you can use tab-completion in jupyter and similar environments to view a list of matching icons. Or call dir() programmatically.

from fastlucide import icons
[o for o in dir(icons) if o.startswith('Star')]
['Star', 'Star_half', 'Star_off']

How it works

When we render an icon, the actual SVG path information is not included – only an href to an id is there:

ss('a-arrow-down')
<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24" height="24px" width="24px" class="lucide-icon "><use href="#l-a-arrow-down"></use></svg>

The definitions of these ids is provided in the ss object itself, along with style information:

from fastcore.xml import highlight
from IPython.display import Markdown
Markdown(highlight(ss))
<style>.lucide-icon { stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }</style>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none"><defs><symbol id="l-a-arrow-down"><path d="M3.5 13h6"></path><path d="m2 16 4.5-9 4.5 9"></path><path d="M18 7v9"></path><path d="m14 12 4 4 4-4"></path></symbol><symbol id="l-accessibility"><circle cx="16" cy="4" r="1"></circle><path d="m18 19 1-7-6 1"></path><path d="m5 8 3-3 5.5 3-2.36 3.5"></path><path d="M4.24 14.5a5 5 0 0 0 6.88 6"></path><path d="M13.76 17.5a5 5 0 0 0-6.88-6"></path></symbol></defs></svg>

Release files for fastlucide 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastlucide 0.0.7
File Size Uploaded
fastlucide-0.0.7.tar.gz 88.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastlucide 0.0.7
File Interpreter ABI Platform
fastlucide-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size:177.3 kB

Release files / fastlucide-0.0.7.tar.gz

Download URL fastlucide-0.0.7.tar.gz
Size 88.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2bab2d3fe05f0aec144318a174cfcc4ef9622118b1c668dbe27ec56f26d25788
BLAKE2b-256 checksum
How to use checksums
047e8b66c0bbb8e69255ad2ef83229f971b6d98102b0cfffc3b1faed2eb0b68a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release files / fastlucide-0.0.7-py3-none-any.whl

Download URL fastlucide-0.0.7-py3-none-any.whl
Size 89.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4f85008b4ca3735fab83583dcdbeab74cc45165a1018e3a1a5d907be55d9156
BLAKE2b-256 checksum
How to use checksums
72852688101b7130ee53962b7a0ddecd962b506f50c98516fb88a8b34ac4286e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page