How to get a website's favicon in Python

Checked on 2026-11-24.

A website names its icon in its own HTML: a link element with rel="icon", one or several, in different sizes. When a page declares none, browsers may try /favicon.ico at the root of the site, and a site with a web app manifest lists more icons there. A Python script reads all three in two or three requests; the Pipefetch brand endpoint returns the icon addresses it finds on a home page, next to the logo.

Where a site declares its icon

The HTML standard sets the rules:

  • rel="icon" points to "an icon representing the page or site". A page may list several; the browser must "select the most appropriate icon according to the type, media, and sizes attributes", and among equally appropriate ones use "the last one declared".
  • sizes holds values such as 16x16 or 32x32 48x48, in raw pixels. The keyword any means "a scalable icon, e.g. as provided by an SVG image".
  • For historical reasons, rel="shortcut icon" means the same.
  • When a page has no icon link, user agents "may" request /favicon.ico resolved against the page's address and use the answer as its icon. It is a convention browsers are allowed to follow, so a site does not have to have that file.

Google Search reads two more names: its favicon documentation also accepts apple-touch-icon, "an iOS-friendly icon that represents your site, per Apple's developer documentation", and apple-touch-icon-precomposed.

The third place is the web app manifest, a JSON file the page links with rel="manifest". In the Web Application Manifest specification, a W3C Working Draft last published on November 18, 2026, its icons member "specifies images that serve as iconic representations of the web application". Each icon has a src, optional sizes and type, and a purpose: any by default, maskable for an icon designed for a safe zone that may be cropped, monochrome for one used as a mask over a solid fill. The Image Resource draft parses src with the manifest's own address as the base, not the page's.

1. A script that finds every declared icon

Python
# pip install requests beautifulsoup4
from urllib.parse import urljoin

import requests
from bs4 import BeautifulSoup

ICON_RELS = {"icon", "apple-touch-icon", "apple-touch-icon-precomposed"}


def largest_side(sizes):
    """16 for "16x16", 48 for "16x16 48x48", and the most for "any", a scalable icon."""
    best = 0
    if isinstance(sizes, list):
        sizes = " ".join(sizes)
    for size in str(sizes or "").lower().split():
        if size == "any":
            return 100_000
        width, _, height = size.partition("x")
        if width.isdigit() and height.isdigit():
            best = max(best, int(width), int(height))
    return best


def site_icons(url):
    session = requests.Session()
    res = session.get(url, timeout=15)
    res.raise_for_status()
    soup = BeautifulSoup(res.text, "html.parser")
    icons, manifest = [], None
    for link in soup.find_all("link", href=True):
        rel = {token.lower() for token in link.get("rel", [])}   # "shortcut icon" is two tokens
        if rel & ICON_RELS:
            icons.append({"url": urljoin(res.url, link["href"]), "sizes": link.get("sizes"), "from": "link"})
        elif "manifest" in rel and manifest is None:
            manifest = urljoin(res.url, link["href"])

    if manifest:
        try:
            for icon in session.get(manifest, timeout=15).json().get("icons", []):
                purpose = str(icon.get("purpose") or "any").split()
                if icon.get("src") and "any" in purpose:
                    # src is relative to the manifest's own address, not to the page's
                    icons.append({"url": urljoin(manifest, icon["src"]), "sizes": icon.get("sizes"), "from": "manifest"})
        except (requests.exceptions.RequestException, ValueError, AttributeError):
            pass

    if not icons:
        fallback = urljoin(res.url, "/favicon.ico")   # what browsers may try when a page declares no icon
        try:
            if session.get(fallback, timeout=15).ok:
                icons.append({"url": fallback, "sizes": None, "from": "/favicon.ico"})
        except requests.exceptions.RequestException:
            pass

    return sorted(icons, key=lambda icon: largest_side(icon["sizes"]), reverse=True)


for icon in site_icons("https://stripe.com"):
    print(icon["from"], icon["sizes"], icon["url"])

Beautiful Soup stores rel as a list of its values, which is why "shortcut icon" matches without a special case; the tokens are lowered because the standard compares link types case-insensitively. Manifest icons are kept only when their purpose includes any, and /favicon.ico is tried only when nothing is declared, as the standard describes for browsers. The list comes back largest first, by the sizes the site states.

Where it stops:

  • The sizes are what the page says. The standard requires them to be true, but only opening the image tells you its real dimensions, and an ICO file can hold several images of different sizes.
  • An icon a script adds after the page loads is not in the HTML requests receives.
  • Some sites answer scripts with 403 or a challenge page, and some icons sit on other hosts with rules of their own.
  • You get addresses. Download and keep the files you need, and remember the icon is the site owner's.

2. The favicon package

The favicon package on PyPI does a similar search. Its README returns Icon objects with url, width, height and format, passes keyword arguments on to Requests, and takes the first icon as the largest.

Python
# pip install favicon
import favicon

icons = favicon.get("https://stripe.com", timeout=15)   # keyword arguments go to requests
for icon in icons:
    print(icon.url, icon.width, icon.height, icon.format)

Where it stops: its last release, 0.7.0, is from August 31, 2019, and there has been none since. Try it on your sites before you depend on it.

Answers online also point to an address on google.com that returns any site's icon. We found no Google documentation for it: Google's favicon page is about how Search shows a site's icon. This guide does not build on it.

3. The brand endpoint

The Pipefetch brand endpoint reads a company's home page when you ask and returns its brand as JSON, the icons included.

Python
import os
import requests

res = requests.get(
    "https://pipefetch.com/v1/web/brand",
    params={"url": "stripe.com"},
    headers={"x-api-key": os.environ["PIPEFETCH_API_KEY"]},
    timeout=90,
)
if res.status_code == 404:
    print(res.json()["error"]["code"])   # website_unreachable or website_blocked: not charged
else:
    res.raise_for_status()
    brand = res.json()["data"]
    print(brand["icon"])     # the first icon found, or None
    print(brand["icons"])    # every icon address found on the home page
    print(brand["logo"])     # url, format and source, or None

The same from Node.js:

JavaScript
const url = new URL('https://pipefetch.com/v1/web/brand');
url.searchParams.set('url', 'stripe.com');

const res = await fetch(url, { headers: { 'x-api-key': process.env.PIPEFETCH_API_KEY } });
if (res.status === 404) {
  const { error } = await res.json();
  console.log(error.code); // website_unreachable or website_blocked: not charged
} else {
  const { data } = await res.json();
  console.log(data.icon, data.icons, data.logo);
}

icons lists the icon addresses found on the home page and icon is the first of them, null when none was found. In our saved answer for stripe.com of November 18, 2026, icons holds two PNG addresses, sized 180 and 96 pixels according to Stripe's own image addresses, and logo is an SVG file the site states in its structured data. The answer also has the sharing image, the brand colors, fonts, name and socials; the reference lists every field.

Where it stops: you get addresses, not files, and no size or type for each icon: if you need the largest, look at the files. Only the home page is read, as plain HTML without JavaScript. Pipefetch does not host the files, so keep your own copies. A request costs 1 credit and most take 2 to 9 seconds. A site that does not answer within 15 seconds answers 404 website_unreachable, one that refuses automated requests 404 website_blocked, and neither costs anything. A new account has 100 free credits and needs no card. It is not an official API of the websites it reads, and Pipefetch is not affiliated with them.

Which one should you use?

SituationUse
Icons of a few sites, with their stated sizes and manifest iconsThe script
A quick try in a notebookThe favicon package, knowing it is unmaintained
Icon, logo, colors and fonts stored with each company record, from a serverThe brand endpoint

Which size to use

For a small mark next to a name, any declared icon of 32 pixels or more will do; for a tile or a card, take the largest, a scalable any icon first. If you want the site's logo rather than its icon, the logo guide covers where sites state one. And if the icon is your own, Google's guidelines for showing it in search results ask for a square of at least 8x8 pixels, recommend one "larger than 48x48px", list BMP, GIF, ICO, PNG, JPEG, PPM and TIFF as the formats they support, and show one icon per host name.

Try it with 100 free credits. No card needed. No scraper to build or maintain. Get an API key or read the docs.

Every source

YouTube

Instagram

TikTok

Facebook

Google

Threads

LinkedIn

App stores

Steam

X

Pinterest

Airbnb

Real estate

Keywords

Job boards

Eventbrite

Shopify stores

Public tenders

All guides