Material You Color

3.0.2 · active · verified Fri Apr 17

materialyoucolor is a pure Python library that implements the Material You color generation algorithms. It allows developers to extract dominant colors from images, generate custom color palettes, and apply Material You dynamic theming principles to their applications. As of version 3.0.2, it is actively developed with periodic updates, offering a robust solution for creating adaptive and personalized user interfaces.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate a Material You color scheme using a seed color. It shows how to convert a hex string to the `Hct` format and then use a `SchemeFidelity` to create both light and dark themes, printing some of the key generated colors.

from materialyoucolor.hct.hct import Hct
from materialyoucolor.scheme.scheme_fidelity import SchemeFidelity

# Define a seed color (e.g., from an image or a brand color)
seed_hex = "#FF00A3" # A vibrant magenta

# Convert hex string to integer for Hct
seed_argb_int = int(seed_hex[1:], 16)
seed_color_hct = Hct.from_int(seed_argb_int)

# Generate a Material You color scheme
# You can choose different schemes like SchemeVibrant, SchemeContent, etc.
# Set is_dark=True for a dark theme
scheme_light = SchemeFidelity(seed_color_hct, is_dark=False, contrast_level=0.0)
scheme_dark = SchemeFidelity(seed_color_hct, is_dark=True, contrast_level=0.0)

print("--- Light Scheme ---")
print(f"Primary color: {scheme_light.primary.hex}")
print(f"On Primary color: {scheme_light.on_primary.hex}")
print(f"Background color: {scheme_light.background.hex}")
print(f"Surface color: {scheme_light.surface.hex}")
print(f"Error color: {scheme_light.error.hex}")

print("\n--- Dark Scheme ---")
print(f"Primary color: {scheme_dark.primary.hex}")
print(f"Background color: {scheme_dark.background.hex}")

view raw JSON →