Skip to main content

A simple Tag to implement Lucide Icons in Flask

Project description

Flask Lucide

A simple Tag ({% icon "name" %}) to implement Lucide Icons in Flask. This is completely copied of the library Flask Feather by TheTomcat This is largely based of the library django_feather by Jonas Drotleff.

Install

Install flask-lucide using pip.

pip install flask-lucide

Quick Start

Firstly, initialize the extension within your Flask context

from flask_lucide import Lucide
lucide = Lucide(app)

This extension also supports the Flask application factory pattern by allowing you to create a Lucide object and then initialized it separately for an app:

lucide = Lucide()


def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)

    lucide.init_app(app)

Advanced setup

In addition to the wonderful icons provided in the lucide set, you can supply your own svg icons, to attempt to parse them and use them in the same format. Simply initialize the extension with a directory containing .svg files that are similar in style to the lucide ones. They should resemble the lucide icon style as near as possible - any significant differences in formatting/structure may result in unexpected errors.

lucide = Lucide(import_dir='app\\static\\customsvg')


def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)

    lucide.init_app(app)

Usage

It's pretty simple to use this package. From within a jinja template:

<p>{{ lucide.icon('icon-name', width=32, height=32) }}</p>

If the property you're modifying has a hyphen, use an underscore instead. You can refer to icon names with either hyphens or underscores.

<p>{{ lucide.icon('icon-name', stroke_width=2) }}</p>

The icon function takes the SVG source from the Lucide project, applies additional attributes and return the SVG tag.

Performance

flask-lucide borrows the application structure from django-feather and does not read the .svg files each time an icon is rendered. Instead, on installation, all the icons are written to a .py file. All icons are rendered on the server side, avoiding the need to call feather.replace() after the page has loaded.

Any custom icons are parsed each time the server is restarted, and not every time they're loaded.

License

Lucide is licensed under the ISC License.

flask-lucide is a derivative work of flask-feather and django-feather, are licensed under the Apache License, Version 2.0:

    Modifications Copyright 2020 Tom Vos <tjvos1@gmail.com>
    
    Original Django-feather Copyright 2020 Jonas Drotleff <j.drotleff@desk-lab.de>
    
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    
       http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask-lucide-0.2.0.tar.gz (62.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_lucide-0.2.0-py2.py3-none-any.whl (29.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file flask-lucide-0.2.0.tar.gz.

File metadata

  • Download URL: flask-lucide-0.2.0.tar.gz
  • Upload date:
  • Size: 62.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.5

File hashes

Hashes for flask-lucide-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a9954656ab60149b4e34a65e7cde9fdd73e0f7fc1d260f01b99c820055f31043
MD5 cc2e5e9eae4559ef5ec46ca652944fd8
BLAKE2b-256 fd932a8aa6abe6f88c4eceedba38808b1a475066c39aef47e3b2f761c53153e6

See more details on using hashes here.

File details

Details for the file flask_lucide-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: flask_lucide-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.5

File hashes

Hashes for flask_lucide-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1065e85066e65de75d05032d68930a9c77d4d48cc54e3beb7b0f0f0cc74e52ce
MD5 6d3cd36293f4750518b5bc87330093d1
BLAKE2b-256 78f00336099b6c87a74ce5e5a7e133e3cc84108d722a3befefda9d04b2939fe0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page