Skip to main content

djc-phosphor-icons

Phosphor Icons as django-components.

Browse all icons →

Installation

pip install djc-phosphor-icons

Add to INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    "django_components",
    "djc_phosphor_icons",
]

Usage

{% component "Icon" name="house" / %}
{% component "Icon" name="house" weight="bold" / %}
{% component "Icon" name="house" style="stroke" size=24 color="#ff0000" / %}
Kwarg Type Default Description
name str Icon name, e.g. "house"
weight str "regular" bold, duotone, fill, light, regular, thin
style str "flat" flat or stroke
size str or int None Sets width and height; any CSS length ("1.5rem"), an int is read as px
color str None Sets CSS color
mirrored bool False Flips the icon horizontally
attrs dict None Extra attributes passed to the <svg> element

class and style from attrs are combined with the component's own, not replaced by them - so passing attrs={"class": "me-2"} keeps whatever the component already sets, and size still wins over a conflicting width in your style.

Subclassing

Kwargs and Defaults are inherited, so a subclass only declares what it changes. get_attrs() returns what the component sets on the <svg> itself, get_default_attrs() what the caller's attrs may override - extend either to add your own class, aria-label or data- attribute:

from django_components import merge_attributes
from djc_phosphor_icons import Icon


class MyIcon(Icon):
    def get_attrs(self, kwargs):
        return merge_attributes({"class": "icon"}, super().get_attrs(kwargs))

Search and metadata

Every icon ships with the tags, categories and aliases that power search on phosphoricons.com, so you can build an icon picker without calling out to an API. search_icons() mirrors that site's ranking: names weigh four times heavier than tags and categories, and near-misses still match.

from djc_phosphor_icons.search import search_icons

search_icons("arrow left")               # ranked, best match first
search_icons("roledex")                  # matches on tags: address-book
search_icons("cart", categories="Commerce")
search_icons()                           # every icon, alphabetically
from djc_phosphor_icons.search import all_icons, categories, get_icon

get_icon("house").tags                   # ('homes', 'buildings', 'places', 'locations')
get_icon("caduceus").name                # 'asclepius' - aliases resolve
categories()                             # ('Arrows', 'Brand', ... ) - for filter dropdowns
len(all_icons())

The same search answers a wrong name, so the error suggests by tag as well as by spelling - {% component "Icon" name="cart" / %} raises Did you mean: shopping-cart, shopping-cart-simple, car?, narrowed to icons that exist in the requested weight and style.

To retune the ranking, subclass Ranking and point PHOSPHOR_ICONS["ranking"] at it. Override the weights and thresholds, or score() for a different algorithm entirely:

from djc_phosphor_icons.search import Ranking


class MyRanking(Ranking):
    name_weight = 8.0
    fuzzy_cutoff = 0.9

A one-off ranking can also be passed straight in: search_icons("cart", ranking=MyRanking()).

The raw SVGs are reachable too, for when you need the markup outside a template:

from djc_phosphor_icons.svgs import get_svg, get_svg_inner, icon_names

get_svg("house", weight="bold", style="flat")
get_svg_inner("house")                   # without the wrapping <svg> tag
icon_names()

Settings

Configure via PHOSPHOR_ICONS in your Django settings:

PHOSPHOR_ICONS = {
    "auto_register": True,        # Auto-register the component on startup (default: True)
    "component_name": "Icon",     # Template tag name (default: "Icon")
    "default_style": "flat",      # Default style (default: "flat")
    "default_weight": "regular",   # Default weight (default: "regular")
    "cache": True,                # Cache rendered output per unique set of kwargs (default: True)
    "ranking": "myapp.MyRanking", # Dotted path to a Ranking subclass (default: the bundled one)
}

Development

uv sync
uv run pytest
uv run ruff check .
uv run ruff format .

To update the icon set to a specific Phosphor release (for local inspection only — the update-icons GitHub Action handles this automatically when committing):

uv run python scripts/download_icons.py v2.1.0

To refresh the metadata (tags, categories, aliases) from the Phosphor API:

uv run python scripts/download_metadata.py

To generate a visual preview of all icons:

uv run python scripts/preview_icons.py

Known Icon Issues

The following icons are incomplete in the upstream Phosphor release and will fail to render in certain combinations:

  • book-user: missing from stroke/light, stroke/bold, stroke/fill, stroke/duotone

Download files

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

Source Distribution

djc_phosphor_icons-0.2.0.tar.gz (3.8 MB view details)

Uploaded Source

Built Distribution

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

djc_phosphor_icons-0.2.0-py3-none-any.whl (9.2 MB view details)

Uploaded Python 3

File details

Details for the file djc_phosphor_icons-0.2.0.tar.gz.

File metadata

  • Download URL: djc_phosphor_icons-0.2.0.tar.gz
  • Upload date:
  • Size: 3.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for djc_phosphor_icons-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9d6147dbab348ccdf04378aa46daa123b78ca3a9f294d0eb841b8c72a476ed5f
MD5 498e151cc8798f5fc5d5c2a8b61c767f
BLAKE2b-256 e79e451ab405e6e254ff34d787d4fedbe37951737ba47f0b99fb2ac9e94ae632

See more details on using hashes here.

Provenance

The following attestation bundles were made for djc_phosphor_icons-0.2.0.tar.gz:

Publisher: publish.yml on joeyjurjens/djc-phosphor-icons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djc_phosphor_icons-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for djc_phosphor_icons-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e1d143fb327ddce436832c41e116ff1ca6f509559810654836c0c9d8b501fe80
MD5 4179e668ba76324d81d40b51a2b6128a
BLAKE2b-256 87ed7ddc6a31e8dcf391675923747b839660b237d1d6cba9b644fa69db3c8dad

See more details on using hashes here.

Provenance

The following attestation bundles were made for djc_phosphor_icons-0.2.0-py3-none-any.whl:

Publisher: publish.yml on joeyjurjens/djc-phosphor-icons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

0.0.2

2 files

0.0.1

2 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