Skip to main content

Favicons

Favicon generator for Python 3 with strongly typed sync & async APIs, CLI, & HTML generation.


Installation

pip3 install favicons

Documentation

More docs are coming. Remember, this is a work in progress.

Supported Formats

  • SVG
  • PNG
  • JPEG
  • TIFF

CLI

$ favicons --help

Usage: favicons [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  generate  Generate Favicons
  html      Get favicons as HTML.
  json      Get favicons as JSON.
  names     Get favicon file names.

generate

Generate Favicons from the command line:

Usage: favicons generate [OPTIONS]

  Generate Favicons

Options:
  --source PATH                    Source Image  [required]
  --output-directory PATH          Output Directory  [required]
  --background-color TEXT          Background Color  [default: #000000]
  --transparent / --no-transparent Transparent Background  [default: True]
  --base-url TEXT                  Base URL for HTML output  [default: /]
  --help                           Show this message and exit.

html

Generate HTML elements (same options as generate).

json

Generate JSON array of favicon objects (same options as generate).

names

Generate list of favicon file names (same options as generate).

Python Sync API

from favicons import Favicons

YOUR_ICON = "/home/user/icon.jpg"
WEB_SERVER_ROOT = "/var/www/html"

with Favicons(YOUR_ICON, WEB_SERVER_ROOT) as favicons:
    favicons.generate()
    for icon in favicons.filenames():
        print(icon)

# favicon.ico
# favicon-16x16.png
# favicon-32x32.png
# favicon-64x64.png
# favicon-96x96.png
# favicon-180x180.png
# apple-touch-icon-57x57.png
# apple-touch-icon-60x60.png
# apple-touch-icon-72x72.png
# apple-touch-icon-76x76.png
# apple-touch-icon-114x114.png
# apple-touch-icon-120x120.png
# apple-touch-icon-144x144.png
# apple-touch-icon-152x152.png
# apple-touch-icon-167x167.png
# apple-touch-icon-180x180.png
# mstile-70x70.png
# mstile-270x270.png
# mstile-310x310.png
# mstile-310x150.png
# favicon-196x196.png

Python Async API

from favicons import Favicons

YOUR_ICON = "/home/user/icon.jpg"
WEB_SERVER_ROOT = "/var/www/html"

async with Favicons(YOUR_ICON, WEB_SERVER_ROOT) as favicons:
    await favicons.generate()
    for icon in favicons.filenames():
        print(icon)

# favicon.ico
# favicon-16x16.png
# favicon-32x32.png
# favicon-64x64.png
# favicon-96x96.png
# favicon-180x180.png
# apple-touch-icon-57x57.png
# apple-touch-icon-60x60.png
# apple-touch-icon-72x72.png
# apple-touch-icon-76x76.png
# apple-touch-icon-114x114.png
# apple-touch-icon-120x120.png
# apple-touch-icon-144x144.png
# apple-touch-icon-152x152.png
# apple-touch-icon-167x167.png
# apple-touch-icon-180x180.png
# mstile-70x70.png
# mstile-270x270.png
# mstile-310x310.png
# mstile-310x150.png
# favicon-196x196.png

HTML

Get HTML elements for each generated favicon:

from favicons import Favicons

YOUR_ICON = "/home/user/icon.jpg"
WEB_SERVER_ROOT = "/var/www/html"

async with Favicons(YOUR_ICON, WEB_SERVER_ROOT) as favicons:
    await favicons.generate()
    # As generator
    html = favicons.html_gen()
    # As tuple
    html = favicons.html()

print(html)
# (
#   '<link rel="None" type="image/ico" href="/favicon.ico" />',
#   '<link rel="icon" type="image/png" href="/favicon-16x16.png" />',
#   '<link rel="icon" type="image/png" href="/favicon-32x32.png" />',
#   '<link rel="icon" type="image/png" href="/favicon-64x64.png" />',
#   '<link rel="icon" type="image/png" href="/favicon-96x96.png" />',
#   '<link rel="icon" type="image/png" href="/favicon-180x180.png" />',
#   '<link rel="apple-touch-icon" type="image/png" '
#   'href="/apple-touch-icon-57x57.png" />',
#   '<link rel="apple-touch-icon" type="image/png" '
#   'href="/apple-touch-icon-60x60.png" />',
#   '<link rel="apple-touch-icon" type="image/png" '
#   'href="/apple-touch-icon-72x72.png" />',
#   '<link rel="apple-touch-icon" type="image/png" '
#   'href="/apple-touch-icon-76x76.png" />',
#   '<link rel="apple-touch-icon" type="image/png" '
#   'href="/apple-touch-icon-114x114.png" />',
#   '<link rel="apple-touch-icon" type="image/png" '
#   'href="/apple-touch-icon-120x120.png" />',
#   '<link rel="apple-touch-icon" type="image/png" '
#   'href="/apple-touch-icon-144x144.png" />',
#   '<link rel="apple-touch-icon" type="image/png" '
#   'href="/apple-touch-icon-152x152.png" />',
#   '<link rel="apple-touch-icon" type="image/png" '
#   'href="/apple-touch-icon-167x167.png" />',
#   '<link rel="apple-touch-icon" type="image/png" '
#   'href="/apple-touch-icon-180x180.png" />',
#   '<link rel="None" type="image/png" href="/mstile-70x70.png" />',
#   '<link rel="None" type="image/png" href="/mstile-270x270.png" />',
#   '<link rel="None" type="image/png" href="/mstile-310x310.png" />',
#   '<link rel="None" type="image/png" href="/mstile-310x150.png" />',
#   '<link rel="shortcut icon" type="image/png" href="/favicon-196x196.png" />'
# )

Tuple

Get a Python tuple containing each generated favicon's properties:

from favicons import Favicons

YOUR_ICON = "/home/user/icon.jpg"
WEB_SERVER_ROOT = "/var/www/html"

async with Favicons(YOUR_ICON, WEB_SERVER_ROOT) as favicons:
    await favicons.generate()
    as_tuple = favicons.formats()
    print(as_tuple)
# (
#   {
#     'dimensions': (64, 64),
#     'image_format': 'ico',
#     'prefix': 'favicon',
#     'rel': None
#   },
#   {
#     'dimensions': (16, 16),
#     'image_format': 'png',
#     'prefix': 'favicon',
#     'rel': 'icon'
#   },
#   {
#     'dimensions': (32, 32),
#     'image_format': 'png',
#     'prefix': 'favicon',
#     'rel': 'icon'
#   },
#   {
#     'dimensions': (64, 64),
#     'image_format': 'png',
#     'prefix': 'favicon',
#     'rel': 'icon'
#   },
#   {
#     'dimensions': (96, 96),
#     'image_format': 'png',
#     'prefix': 'favicon',
#     'rel': 'icon'
#   },
#   {
#     'dimensions': (180, 180),
#     'image_format': 'png',
#     'prefix': 'favicon',
#     'rel': 'icon'
#   },
#   {
#     'dimensions': (57, 57),
#     'image_format': 'png',
#     'prefix': 'apple-touch-icon',
#     'rel': 'apple-touch-icon'
#   },
#   {
#     'dimensions': (60, 60),
#     'image_format': 'png',
#     'prefix': 'apple-touch-icon',
#     'rel': 'apple-touch-icon'
#   },
#   {
#     'dimensions': (72, 72),
#     'image_format': 'png',
#     'prefix': 'apple-touch-icon',
#     'rel': 'apple-touch-icon'
#   },
#   {
#     'dimensions': (76, 76),
#     'image_format': 'png',
#     'prefix': 'apple-touch-icon',
#     'rel': 'apple-touch-icon'
#   },
#   {
#     'dimensions': (114, 114),
#     'image_format': 'png',
#     'prefix': 'apple-touch-icon',
#     'rel': 'apple-touch-icon'
#   },
#   {
#     'dimensions': (120, 120),
#     'image_format': 'png',
#     'prefix': 'apple-touch-icon',
#     'rel': 'apple-touch-icon'
#   },
#   {
#     'dimensions': (144, 144),
#     'image_format': 'png',
#     'prefix': 'apple-touch-icon',
#     'rel': 'apple-touch-icon'
#   },
#   {
#     'dimensions': (152, 152),
#     'image_format': 'png',
#     'prefix': 'apple-touch-icon',
#     'rel': 'apple-touch-icon'
#   },
#   {
#     'dimensions': (167, 167),
#     'image_format': 'png',
#     'prefix': 'apple-touch-icon',
#     'rel': 'apple-touch-icon'
#   },
#   {
#     'dimensions': (180, 180),
#     'image_format': 'png',
#     'prefix': 'apple-touch-icon',
#     'rel': 'apple-touch-icon'
#   },
#   {
#     'dimensions': (70, 70),
#     'image_format': 'png',
#     'prefix': 'mstile',
#     'rel': None
#   },
#   {
#     'dimensions': (270, 270),
#     'image_format': 'png',
#     'prefix': 'mstile',
#     'rel': None
#   },
#   {
#     'dimensions': (310, 310),
#     'image_format': 'png',
#     'prefix': 'mstile',
#     'rel': None
#   },
#   {
#     'dimensions': (310, 150),
#     'image_format': 'png',
#     'prefix': 'mstile',
#     'rel': None
#   },
#   {
#     'dimensions': (196, 196),
#     'image_format': 'png',
#     'prefix': 'favicon',
#     'rel': 'shortcut icon'
#   }
# )

JSON

Get a JSON array containing each generated favicon's properties:

from favicons import Favicons

YOUR_ICON = "/home/user/icon.jpg"
WEB_SERVER_ROOT = "/var/www/html"

async with Favicons(YOUR_ICON, WEB_SERVER_ROOT) as favicons:
    await favicons.generate()
    as_json = favicons.json(indent=2)
    print(as_json)

# [
#   {
#     "image_format": "ico",
#     "dimensions": [
#       64,
#       64
#     ],
#     "prefix": "favicon",
#     "rel": null
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       16,
#       16
#     ],
#     "prefix": "favicon",
#     "rel": "icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       32,
#       32
#     ],
#     "prefix": "favicon",
#     "rel": "icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       64,
#       64
#     ],
#     "prefix": "favicon",
#     "rel": "icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       96,
#       96
#     ],
#     "prefix": "favicon",
#     "rel": "icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       180,
#       180
#     ],
#     "prefix": "favicon",
#     "rel": "icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       57,
#       57
#     ],
#     "prefix": "apple-touch-icon",
#     "rel": "apple-touch-icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       60,
#       60
#     ],
#     "prefix": "apple-touch-icon",
#     "rel": "apple-touch-icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       72,
#       72
#     ],
#     "prefix": "apple-touch-icon",
#     "rel": "apple-touch-icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       76,
#       76
#     ],
#     "prefix": "apple-touch-icon",
#     "rel": "apple-touch-icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       114,
#       114
#     ],
#     "prefix": "apple-touch-icon",
#     "rel": "apple-touch-icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       120,
#       120
#     ],
#     "prefix": "apple-touch-icon",
#     "rel": "apple-touch-icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       144,
#       144
#     ],
#     "prefix": "apple-touch-icon",
#     "rel": "apple-touch-icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       152,
#       152
#     ],
#     "prefix": "apple-touch-icon",
#     "rel": "apple-touch-icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       167,
#       167
#     ],
#     "prefix": "apple-touch-icon",
#     "rel": "apple-touch-icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       180,
#       180
#     ],
#     "prefix": "apple-touch-icon",
#     "rel": "apple-touch-icon"
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       70,
#       70
#     ],
#     "prefix": "mstile",
#     "rel": null
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       270,
#       270
#     ],
#     "prefix": "mstile",
#     "rel": null
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       310,
#       310
#     ],
#     "prefix": "mstile",
#     "rel": null
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       310,
#       150
#     ],
#     "prefix": "mstile",
#     "rel": null
#   },
#   {
#     "image_format": "png",
#     "dimensions": [
#       196,
#       196
#     ],
#     "prefix": "favicon",
#     "rel": "shortcut icon"
#   }
# ]

License

Clear BSD License

Metadata

Release files for favicons 0.2.2

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

Source distribution (sdist)

Source distribution for favicons 0.2.2
File Size Uploaded
favicons-0.2.2.tar.gz 12.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for favicons 0.2.2
File Interpreter ABI Platform
favicons-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 25.9 kB

Release files / favicons-0.2.2.tar.gz

Download URL favicons-0.2.2.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
57749e6b3145b485d9ea9b6239dc679fbc00d092a873545c018c03597abce1c9
BLAKE2b-256 checksum
How to use checksums
8b676f701e807ca31d76b63fd2ff90d6c1a0f2ead70b59dd031d34a47ae6a071
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.2 Linux/6.2.0-1019-azure

Release files / favicons-0.2.2-py3-none-any.whl

Download URL favicons-0.2.2-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b94fb2312ed33afb65873d04a0354d70a45f99207e78fa59d68ba64c37e368d4
BLAKE2b-256 checksum
How to use checksums
071fb1e89aee2260f9dfd31a60b78ee048a098af05fed83a0d2161a17897e74c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.2 Linux/6.2.0-1019-azure

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

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