Skip to main content

pinkie

pypi python python

All-in-one solution for color management.

Features

  • Simple and pythonic way to manage colors
  • Multiple models (RGB, HSL, CMYK, HEX) and conversions
  • Palettes, schemes and color generators
  • Color blending with many modes
  • Supports alpha (transparency) channel

Installation

To install this package, run the following command:

pip install pinkie

Usage

Get started

You can define colors like below. Color equals RGBA color.

from pinkie import Color

color = Color('c0ffee') 

Initialize colors

You can create colors in different ways:

Color((244, 11, 58)) # rgb tuple, alpha is set to 255
Color((244, 11, 58, 215)) # rgba tuple
Color('#ff53a7') # hex value ('#' is automatically stripped)
Color('ff53a7f6') # hex value with alpha
Color(43252667) # int value
HSLA((259, 94, 47)).to_rgba() # hsl value
...

and define colors with another bit count per channel:

Color((34832, 632, 65103), bits=16) # rgb tuple
Color('ff53a7cc671a', bits=16) # hex value
Color('ff53a7cc671a12e3', bits=16) # hex value with alpha
...

Color conversions

Color models can be converted to RGBA and back:

Color('ff00ff').to_hsla() 
Color('157cc3').to_cmyk()
HSLA('44c26b').to_rgba()
...

Color blending

You can blend colors like in Photoshop:

import pinkie.blend as blend
from pinkie import Color

bg = Color('ffd015ff')
fg = Color('ff15bd80')

bg.blend(fg, blend.Normal()) # FF7269FF

and create your own blending mode:

class MyBlend(BlendMode):
    def blend(
        self, 
        bg: tuple[float, float, float, float], 
        fg: tuple[float, float, float, float]
    ) -> tuple[float, float, float, float]:
        a = self._alpha(bg, fg)

        def _ch(num: int) -> float:
            return bg[num] * fg[num]

        return _ch(0), _ch(1), _ch(2), a

bg.blend(fg, MyBlend())

Harmonic colors

There are various methods to get harmonic colors:

color.complementary() # complementary color
color.triadic() # list of triadic colors
color.closest(Color('ffffff'), Color('000000')) # closest color from the list
...

Color palettes

Palettes are just sequences of colors. You can manage them like this:

from pinkie import Color, Palette

palette = Palette(Color('ffffff'), Color('4c66a1'))
palette.add(Color('16c235'))
palette.remove(Color('ffffff'))

Palette.web() # palette of web-safe colors
Palette.gradient(Color('ff0000'), Color('0000ff'), 5) # palette of colors that create gradient from red to blue
...

Metadata

Release files for pinkie 0.0.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 pinkie 0.0.2
File Size Uploaded
pinkie-0.0.2.tar.gz 12.5 kB Details

Built distribution (wheel)

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

Total release size: 32.2 kB

Release files / pinkie-0.0.2.tar.gz

Download URL pinkie-0.0.2.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e32fd49a9da2f121e765e2d0aeae3b5de46d66a0635ee1d2630492c0c7f31843
BLAKE2b-256 checksum
How to use checksums
fbeedeb79bbc3f3004bf70feeb6482cb99219ef0b1b55632e14196d045a64b5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Windows/10

Release files / pinkie-0.0.2-py3-none-any.whl

Download URL pinkie-0.0.2-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd8b46a6c7b17f35f298524c4c70c809f07e5d66a0020241a54e02b704c9ba8b
BLAKE2b-256 checksum
How to use checksums
5f074170f45784a336bf6481555ae7c32b033b29aa01f021cdc8fa73869d9971
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Windows/10

Release history Release notifications | RSS feed

This release

0.0.2 This release

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