api
Class info¶
🛈 DocStrings¶
Wrapper for the Iconify API and the Iconify icon set packages.
Per-icon calls (svg, css, icon_data, search, ...) go to the Iconify API.
Collection-level calls (collections, collection, icon_set) load the
@iconify/collections and @iconify-json/<prefix> npm packages from a CDN,
as the public API is rate-limited for bulk usage.
Environment variables:
| Variable | Default |
|---|---|
PYCONS_ICONIFY_API |
https://api.iconify.design |
PYCONS_ICONIFY_CDN |
https://cdn.jsdelivr.net/npm,https://unpkg.com |
CDN roots are tried in order. jsDelivr refuses files above 50 MB (e.g. fluent-emoji),
unpkg serves those.
api_root
¶
cdn_roots
¶
Return the root URLs of the npm CDNs serving the Iconify packages, in order.
Source code in src/pycons/iconify/api.py
collection
¶
collection(prefix: str, info: bool = False, chars: bool = False) -> APIv2CollectionResponse
Return a list of icons in an icon set.
https://iconify.design/docs/api/collection.html
Built from the @iconify-json/<prefix> package in the same shape as the API
response.
Parameters¶
prefix : str Icon set prefix. info : bool, optional If enabled, the response will include icon set information. chars : bool, optional If enabled, the response will include the character map. The character map exists only in icon sets that were imported from icon fonts.
Source code in src/pycons/iconify/api.py
collections
¶
collections(*prefixes: str) -> dict[str, IconifyInfo]
Return collections where key is icon set prefix, value is IconifyInfo object.
https://iconify.design/docs/api/collections.html
Loaded from the @iconify/collections package instead of the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefixes
|
str
|
Icon set prefixes to filter by. Partial prefixes ending with "-" match all sets starting with them (e.g. "mdi-" matches "mdi-light"). If none are given, all collections are returned. |
()
|
Source code in src/pycons/iconify/api.py
css
¶
css(
*keys: str,
selector: str | None = None,
common: str | None = None,
override: str | None = None,
pseudo: bool | None = None,
var: str | None = None,
square: bool | None = None,
color: str | None = None,
mode: Literal["mask", "background"] | None = None,
format: StylesheetFormat | None = None,
) -> str
Return CSS for icons in prefix.
https://iconify.design/docs/api/css.html
Iconify API can dynamically generate CSS for icons, where icons are used as background or mask image.
Example: https://api.iconify.design/mdi.css?icons=account-box,account-cash,account,home
Parameters¶
keys : str
Icon set prefix and name(s). May be passed as a single string in the format
"prefix:name" or as multiple strings: 'prefix', 'name1', 'name2'.
To generate CSS for icons from multiple icon sets, send separate queries for
each icon set.
selector : str, optional
CSS selector for icons. If not set, defaults to ".icon--{prefix}--{name}"
Variable "{prefix}" is replaced with icon set prefix, "{name}" with icon name.
common : str, optional
Common selector for icons, defaults to ".icon--{prefix}". Set it to empty to
disable common code. Variable "{prefix}" is replaced with icon set prefix.
override : str, optional
Selector that mixes selector and common to generate icon specific
style that overrides common style. Default value is
".icon--{prefix}.icon--{prefix}--{name}".
pseudo : bool, optional
Set it to True if selector for icon is a pseudo-selector, such as
".icon--{prefix}--{name}::after".
var : str, optional
Name for variable to use for icon, defaults to "svg" for monotone icons,
None for icons with palette. Set to null to disable.
square : bool, optional
Forces icons to have width of 1em.
color : str, optional
Sets color for monotone icons. Also renders icons as background images.
mode : Literal["mask", "background"], optional
Forces icon to render as mask image or background image. If not set, mode will
be detected from icon content: icons that contain currentColor will be rendered
as mask image, other icons as background image.
format : Literal["expanded", "compact", "compressed"], optional
Stylesheet formatting option. Matches options used in Sass. Supported values
are "expanded", "compact" and "compressed".
Source code in src/pycons/iconify/api.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
icon_data
¶
icon_data(*keys: str) -> IconifyJSON
Return icon data for the given icons of one icon set.
https://iconify.design/docs/api/icon-data.html
Example: https://api.iconify.design/mdi.json?icons=acount-box,account-cash,account,home
Missing icons are added to not_found property of response.
Parameters¶
keys : str
Icon set prefix and name(s). May be passed as a single string in the format
"prefix:icon" or as multiple strings: 'prefix', 'icon1', 'icon2'.
Source code in src/pycons/iconify/api.py
icon_set
¶
icon_set(prefix: str) -> IconifyJSON
Return the complete data of an icon set, including all icons and aliases.
Loaded from the @iconify-json/<prefix> package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Icon set prefix. |
required |
Source code in src/pycons/iconify/api.py
iconify_version
¶
Return version of iconify API.
https://iconify.design/docs/api/version.html
The purpose of this query is to be able to tell which server you are connected to, but without exposing actual location of server, which can help debug error. This is used in networks when many servers are running.
Examples¶
iconify_version() 'Iconify API version 3.0.0-beta.1'
Source code in src/pycons/iconify/api.py
keywords
¶
keywords(prefix: str | None = None, keyword: str | None = None) -> APIv3KeywordsResponse
Intended for use in suggesting search queries.
https://iconify.design/docs/api/keywords.html
One of prefix or keyword MUST be specified.
Keyword can only contain letters numbers and dash. If it contains "-", only the last part after "-" is used. Must be at least 2 characters long.
Parameters¶
prefix : str, optional
Keyword Prefix. API returns all keywords that start with prefix.
keyword : str, optional
Partial keyword. API returns all keywords that start or
end with keyword. (Ignored if prefix is specified).
Source code in src/pycons/iconify/api.py
last_modified
¶
Return last modified date for icon sets.
https://iconify.design/docs/api/last-modified.html
Example: https://api.iconify.design/last-modified?prefixes=mdi,mdi-light,tabler
Parameters¶
prefixes : Sequence[str], optional Comma separated list of icon set prefixes. You can use partial prefixes that end with "-", such as "mdi-" matches "mdi-light". If None, return all collections.
Returns¶
dict[str, int] Dictionary where key is icon set prefix, value is last modified date as UTC integer timestamp.
Source code in src/pycons/iconify/api.py
search
¶
search(
query: str,
limit: int | None = None,
start: int | None = None,
prefixes: Iterable[str] | None = None,
category: str | None = None,
) -> APIv2SearchResponse
Search icons.
https://iconify.design/docs/api/search.html
Example: https://api.iconify.design/search?query=arrows-horizontal&limit=999
The Search query can include special keywords.
For most keywords, the keyword and value can be separated by ":" or "=". It is recommended to use "=" because the colon can also be treated as icon set prefix.
Keywords with boolean values can have the following values:
"true" or "1" = true. "false" or "0" = false. Supported keywords:
palette(bool). Filter icon sets by palette. Example queries: "home palette=false", "cat palette=true".style("fill" | "stroke"). Filter icons by code. Example queries: "home style=fill", "cat style=stroke".fillandstroke(bool). Same as above, but as boolean. Only one of keywords can be set: "home fill=true".prefix(str). Same as prefix property from search query parameters, but in keyword. Overrides parameter.prefixes(string). Same as prefixes property from search query parameters, but in keyword. Overrides parameter.
Parameters¶
query : str Search string. Case insensitive. limit : int, optional Maximum number of items in response, default is 64. Min 32, max 999. If numer of icons in result matches limit, it means there are more icons to show. start : int, optional Start index for results, default is 0. prefixes : str | Iterable[str], optional List of icon set prefixes. You can use partial prefixes that end with "-", such as "mdi-" matches "mdi-light". category : str, optional Filter icon sets by category.
Source code in src/pycons/iconify/api.py
svg
¶
svg(
*key: str,
color: str | None = None,
height: str | int | None = None,
width: str | int | None = None,
flip: Flip | None = None,
rotate: Rotation | None = None,
box: bool | None = None,
) -> bytes
Generate SVG for icon.
https://iconify.design/docs/api/svg.html
Returns a bytes object containing the SVG data: b'<svg>...</svg>'
Example: https://api.iconify.design/fluent-emoji-flat/alarm-clock.svg?height=48&width=48
Parameters¶
key: str
Icon set prefix and name. May be passed as a single string in the format
"prefix:name" or as two separate strings: 'prefix', 'name'.
color : str, optional
Icon color. Replaces currentColor with specific color, resulting in icon with
hardcoded palette.
height : str | int, optional
Icon height. If only one dimension is specified, such as height, other
dimension will be automatically set to match it.
width : str | int, optional
Icon width. If only one dimension is specified, such as height, other
dimension will be automatically set to match it.
flip : str, optional
Flip icon.
rotate : str | int, optional
Rotate icon. If an integer is provided, it is assumed to be in degrees.
box : bool, optional
Adds an empty rectangle to SVG that matches the icon's viewBox. It is needed
when importing SVG to various UI design tools that ignore viewBox. Those tools,
such as Sketch, create layer groups that automatically resize to fit content.
Icons usually have empty pixels around icon, so such software crops those empty
pixels and icon's group ends up being smaller than actual icon, making it harder
to align it in design.