Skip to main content

Iconify API implementation and tools for Django projects

This re-usable app hepls integrating Iconify into Django projects. Iconify is a unified icons framework, providing access to 40,000+ icons from different icon sets.

Iconify replaces classical icon fonts, claiming that such fonts would get too large for some icon sets out there. Instead, it provides an API to add icons in SVG format from its collections.

django-iconify eases integration into Django. Iconify, to be performant, uses a server-side API to request icons from (in batches, with transformations applied, etc.). Upstream provides a CDN-served central API as well as self-hosted options written in PHP or Node.js, all of which are undesirable for Django projects. django-iconify implements the Iconify API as a re-usable Django app.

Installation

To add django-iconify to a project, first add it as dependency to your project, e.g. using poetry:

$ poetry add django-iconify

Then, add it to your INSTALLED_APPS setting to make its views available later:

INSTALLED_APPS = [
    ...
    "dj_iconify.apps.DjIconifyConfig",
    ...
]

You need to make the JSON collection available by some means. You can download it manually, or use your favourite asset management library. For instance, you could use django-yarnpkg to depend on the @iconify/json Yarn package:

YARN_INSTALLED_APPS = [
  "@iconify/json",
]
NODE_MODULES_ROOT = os.path.join(BASE_DIR, "node_modules")

No matter which way, finally, you have to configure the path to the collections in your settings:

ICONIFY_JSON_ROOT = os.path.join(NODE_MODULES_ROOT, "@iconify", "json")

If you do not use django-yarnpkg, construct the path manually, ot use whatever mechanism your asset manager provides.

You can configure which icon collections are available using two settings:

ICONIFY_COLLECTIONS_ALLOWED = [“foo”, “bar”]

This list controls which collections can be used. If it is set to a non-empty list, only the collections listed are allowed.

ICONIFY_COLLECTIONS_DISALLOWED = [“foo”, “bar”]

This list, on the other hand, controls which collections cannot be used. If this list contains values, while COLLECTIONS_ALLOWED doesn’t, all collections except the listed ones are allowed.

The allow/disallow feature can be used in cases where only a limited set of collections should be available due to design principles or for legal reasons.

Finally, include the URLs in your urlpatterns:

from django.urls import include, path

urlpatterns = [
    path("icons/", include("dj_iconify.urls")),
]

Usage

Iconify SVG Framework

To use the Iconify SVG Framework, get its JavaScript from somewhere (e.g. using django-yarnpkg again, or directly from the CDN, from your ow nstatic files, or wherever).

django-iconify provides a view that returns a small JavaScript snippet that configures the Iconify SVG Framework to use its API endpoints. In the following example, we first load this configuration snippet, then include the Iconify SVG Framework from the CDN (do not do this in production, where data protection matters):

<script type="text/javascript" src="{% url 'config.js' %}"></script>
<script type="text/javascript" src="https://code.iconify.design/1/1.0.6/iconify.min.js"></script>

Loading SVG directly (“How to use Iconify in CSS”)

django-iconify also implements the direct SVG API. For now, you have to use Django’s regular URL reverse resolver to construct an SVG URL, or craft it by hand:

<img src="{% url 'iconify_svg' 'mdi' 'account' %}?rotate=90deg %}" />

Documentation on what query parameters are supported can be found in the documentation on How to use Iconify in CSS.

In the future, a template tag will be available to simplify this.

Including SVG in template directly

Not implemented yet

In the future, a template tag will be available to render SVG icons directly into the template, which can be helpful in situations where retrieving external resources in undesirable, like HTML e-mails.

Example

The source distribution as well as the Git repository contain a full example application that serves the API under /icons/ and a test page under /test.html.

It is reduced to a minimal working example for the reader’s convenience.

Metadata

Release files for django-iconify 0.5.0

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

Source distribution (sdist)

Source distribution for django-iconify 0.5.0
File Size Uploaded
django_iconify-0.5.0.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-iconify 0.5.0
File Interpreter ABI Platform
django_iconify-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.8 kB

Release files / django_iconify-0.5.0.tar.gz

Download URL django_iconify-0.5.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cfd435a2080bba9dbbe487bfa96482ae44c7a658f46ae21b0ecb4e901b317fe8
BLAKE2b-256 checksum
How to use checksums
f5fbf318c872fa0fc4a5e289ec392e5bbc1d13512fdf81766ec0727217e7c9a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.13.12 Linux/6.19.8+deb14-amd64

Release files / django_iconify-0.5.0-py3-none-any.whl

Download URL django_iconify-0.5.0-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c042e6fcb41dd312bc53bf7dda1fc4819a12138fa447c1085bce51e02f348a6a
BLAKE2b-256 checksum
How to use checksums
5f61b6347f1e50a96ce57ccecbd39eac7d86cd127be8901fe7d1e0435a22981d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.13.12 Linux/6.19.8+deb14-amd64

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.1

2 release files

0.4

2 release files

0.3

1 release file

0.2

2 release files

0.1.1

2 release files

0.1.0

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