djc-phosphor-icons
Phosphor Icons as django-components.
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
Metadata
Release files for djc-phosphor-icons 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| djc_phosphor_icons-0.2.0.tar.gz | 3.8 MB | With provenance | Details for djc_phosphor_icons-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| djc_phosphor_icons-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for djc_phosphor_icons-0.2.0-py3-none-any.whl |
Total release size: 13.0 MB
Release files / djc_phosphor_icons-0.2.0.tar.gz
| Download URL | djc_phosphor_icons-0.2.0.tar.gz |
|---|---|
| Size | 3.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9d6147dbab348ccdf04378aa46daa123b78ca3a9f294d0eb841b8c72a476ed5f
|
|
BLAKE2b-256 checksum How to use checksums |
e79e451ab405e6e254ff34d787d4fedbe37951737ba47f0b99fb2ac9e94ae632
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.
Transparency logRelease files / djc_phosphor_icons-0.2.0-py3-none-any.whl
| Download URL | djc_phosphor_icons-0.2.0-py3-none-any.whl |
|---|---|
| Size | 9.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e1d143fb327ddce436832c41e116ff1ca6f509559810654836c0c9d8b501fe80
|
|
BLAKE2b-256 checksum How to use checksums |
87ed7ddc6a31e8dcf391675923747b839660b237d1d6cba9b644fa69db3c8dad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.
Transparency logSecurity for djc-phosphor-icons 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for djc_phosphor_icons-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.