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, IconStyle.SHARP or IconStyle.TWOTONE.

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
  • TWOTONE (IconStyle.TWOTONE): Two toned icons
# 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.3.2.tar.gz (1.5 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.3.2-py3-none-any.whl (4.3 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_material_icons-0.3.2.tar.gz
  • Upload date:
  • Size: 1.5 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.3.2.tar.gz
Algorithm Hash digest
SHA256 eeab036bd2fef04baf435b97a61660c44e96e64488ac8c6997aa0e3cd0c1aac9
MD5 244a97d5f6efe3ed24330bc0ca75a345
BLAKE2b-256 68eb9eb6bb6be24e7d0492efba47873b005672be26d913e33852a9ccb518a29f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_material_icons-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dc0b6a776c3b1e36e33458ba0d6e7a726de7c2e947b7792781e8186094f7fae0
MD5 6742ac13dedae6158825f519601921f0
BLAKE2b-256 9453dd22653f9ba3251601b03834f71de5cd330b24e771be5ef0009a26d3b330

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