Skip to main content

Use Google's Material Icons in your Python applications

Project description

Python Material Icons

Use Google's Material Icons in your Python applications.

This library provides access to the full set of Material Icons in three distinct styles: outlined, round, and sharp. Icons are converted from SVG to PNG at runtime using CairoSVG, with automatic caching based on icon name, size, color, and style.

When loading an icon, it will return a PNG byte stream that you can use in any way you see fit.

Installation

pip install python-material-icons

Usage

With Pillow:

from material_icons import MaterialIcons, IconStyle
from PIL import Image
import io

# Load an icon as PNG bytes
icons = MaterialIcons()
png_bytes = icons.get("cancel", size=48, color="#ff0000", style=IconStyle.ROUND)

# Use with Pillow
image = Image.open(io.BytesIO(png_bytes))
image.show()

With pygame:

import pygame
from material_icons import MaterialIcons, IconStyle

icons = MaterialIcons()

# Load an icon as PNG bytes
png_bytes = icons.get("cancel", size=48, color="#ff0000", style=IconStyle.SHARP)

# Use with pygame
surface = pygame.image.load(io.BytesIO(png_bytes))

Parameters

  • name (str): The Material icon name, e.g. "cancel", "check_box", "signal_cellular_4_bar".
  • size (int, default=24): The output icon size in pixels (square).
  • color (str, default="#000000"): The icon color as a hex string.
  • style (IconStyle, default=IconStyle.OUTLINED): The icon style - IconStyle.OUTLINED, IconStyle.ROUND, or IconStyle.SHARP.

Icon Styles

Material Icons come in three distinct styles:

  • Outlined (IconStyle.OUTLINED): Clean, minimal outlined icons (default)
  • Round (IconStyle.ROUND): Rounded corners and edges for a softer look
  • Sharp (IconStyle.SHARP): Angular, sharp-edged icons for a more geometric feel
# Get the same icon in different styles
outlined = icons.get("home", style=IconStyle.OUTLINED)
round_icon = icons.get("home", style=IconStyle.ROUND)
sharp = icons.get("home", style=IconStyle.SHARP)

Caching

Icons are cached automatically based on (name, size, color, style). Subsequent calls with the same parameters return instantly without re-rendering.

Examples

A pygame icon gallery example is available in the examples directory, install pygame and run it like so:

python examples/pygame-gallery.py

Contribution

We welcome contributions!

  • Open issues for bugs or feature requests
  • Submit pull requests to improve the code, documentation, or packaging.
  • The icon set is fetched automatically in the build pipeline, so you don't need to commit icons to the repository.

Distribution

To build and upload to pypi, first update version pyproject.toml then run run:

python -m build
python -m twine upload --repository testpypi dist/*
python -m twine upload dist/*

Project details


Download files

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

Source Distribution

python_material_icons-0.2.0.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

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

python_material_icons-0.2.0-py3-none-any.whl (3.2 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_material_icons-0.2.0.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python_material_icons-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e8feb1b46182b375843933fcb061ca6f30534e2d58800b0e4aa26eb383cc2e5f
MD5 93e93462e14019a7a2f0149219d3d018
BLAKE2b-256 60b0f201332062a66a4fac491a7ac1f6a7493eb663b181b36aed3f7d33a998fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_material_icons-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c31be7c5dff54dd77b9b339c5de4c260faf567ad8346dfcaaef031cb080ef14b
MD5 3a269d1c10cffa6daad517a77e7c8614
BLAKE2b-256 5050d6e8bb70fc637a967f874c97a6593017b28a2c6887de30f73c5d8ba0a23d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page