Skip to main content

color-convert

PyPI version Python License Documentation Status

颜色格式转换工具,支持 HEX、RGB、RGBA、HSL、HSV、CMYK、十进制等多种颜色格式之间的相互转换。


安装

pip install color-convert

支持的颜色格式

格式 示例
HEX(十六进制) #fff000
RGB rgb(255, 240, 0)
RGBA rgba(255, 240, 0, 1)
HSL hsl(56, 100%, 50%)
HSV hsv(56, 100%, 100%)
CMYK cmyk(0%, 6%, 100%, 0%)
Decimal(十进制) 16711680

使用示例

十六进制 → RGB

from color_convert import color

rgb = color.hex_to_rgb('#fff000')
print(rgb)  # rgb(255,240,0)

十六进制 → RGBA

from color_convert import color

rgba = color.hex_to_rgba('#fff000')
print(rgba)  # rgba(255,240,0,1)

rgba = color.hex_to_rgba('#fff000a8')
print(rgba)  # rgba(255,240,0,0.66)

十六进制 → HSL

from color_convert import color

hsl = color.hex_to_hsl('#fff000')
print(hsl)  # hsl(56, 100%, 50%)

十六进制 → HSV

from color_convert import color

hsv = color.hex_to_hsv('#fff000')
print(hsv)  # hsv(56, 100%, 100%)

十进制 → 十六进制

from color_convert import color

hex_val = color.ten_to_hex(16711680)
print(hex_val)  # #ff0000

十进制 → RGBA

from color_convert import color

rgba = color.ten_to_rgb(16711680)
print(rgba)  # rgba(255,0,0,1)

RGB → 十六进制

from color_convert import color

hex_val = color.rgb_to_hex(255, 240, 0)
print(hex_val)  # #fff000

RGBA → 十六进制

from color_convert import color

hex_val = color.rgba_to_hex(255, 240, 0, 0.66)
print(hex_val)  # #fff000a8

RGB → HSL

from color_convert import color

hsl = color.rgb_to_hsl(255, 240, 0)
print(hsl)  # hsl(56, 100%, 50%)

HSL → RGB

from color_convert import color

rgb = color.hsl_to_rgb(56, 100, 50)
print(rgb)  # rgb(255, 238, 0)

RGB → HSV

from color_convert import color

hsv = color.rgb_to_hsv(255, 240, 0)
print(hsv)  # hsv(56, 100%, 100%)

HSV → RGB

from color_convert import color

rgb = color.hsv_to_rgb(56, 100, 100)
print(rgb)  # rgb(255, 238, 0)

RGB → CMYK

from color_convert import color

cmyk = color.rgb_to_cmyk(255, 240, 0)
print(cmyk)  # cmyk(0%, 6%, 100%, 0%)

CMYK → RGB

from color_convert import color

rgb = color.cmyk_to_rgb(0, 6, 100, 0)
print(rgb)  # rgb(255, 240, 0)

API 参考

函数名 说明 参数 返回值示例
hex_to_rgb(hex) 十六进制 → RGB hex: 如 #fff000 rgb(255,240,0)
hex_to_rgba(hex_str) 十六进制 → RGBA(支持带透明度) hex_str: 如 #fff000 或 #fff000a8 rgba(255,240,0,1)
hex_to_hsl(hex_str) 十六进制 → HSL hex_str: 如 #fff000 hsl(56, 100%, 50%)
hex_to_hsv(hex_str) 十六进制 → HSV hex_str: 如 #fff000 hsv(56, 100%, 100%)
ten_to_hex(num) 十进制 → 十六进制 num: 如 16711680 #ff0000
ten_to_rgb(num) 十进制 → RGBA num: 如 16711680 rgba(255,0,0,1)
rgb_to_hex(r, g, b) RGB → 十六进制 r, g, b: 0-255 #fff000
rgba_to_hex(r, g, b, a) RGBA → 十六进制(带透明度) r, g, b: 0-255, a: 0-1 #fff000a8
rgb_to_hsl(r, g, b) RGB → HSL r, g, b: 0-255 hsl(56, 100%, 50%)
hsl_to_rgb(h, s, l) HSL → RGB h: 0-360, s: 0-100, l: 0-100 rgb(255, 238, 0)
rgb_to_hsv(r, g, b) RGB → HSV r, g, b: 0-255 hsv(56, 100%, 100%)
hsv_to_rgb(h, s, v) HSV → RGB h: 0-360, s: 0-100, v: 0-100 rgb(255, 238, 0)
rgb_to_cmyk(r, g, b) RGB → CMYK r, g, b: 0-255 cmyk(0%, 6%, 100%, 0%)
cmyk_to_rgb(c, m, y, k) CMYK → RGB c, m, y, k: 0-100 rgb(255, 240, 0)

License

MIT License

Metadata

Release files for color-convert 1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for color-convert 1.4
File Size Uploaded Provenance
color_convert-1.4.tar.gz 5.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for color-convert 1.4
File Interpreter ABI Platform
color_convert-1.4-py3-none-any.whl Python 3 none any Details

Total release size: 11.0 kB

Release files / color_convert-1.4.tar.gz

Download URL color_convert-1.4.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2358624d13338da59349edd9e5e1c695ea623c07822b9d89fefeb96d2ad0c089
BLAKE2b-256 checksum
How to use checksums
a4930c5d3ef2885f28f102894fcbb22cdbda4915b4e95fffe67c1cd4e84f7c94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / color_convert-1.4-py3-none-any.whl

Download URL color_convert-1.4-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf241c6576f9561d710ac7f3befe9bcf844154beb2dd7e7866ae759730f432dd
BLAKE2b-256 checksum
How to use checksums
fcdd01bbc601a84ce916abaf3d548f05b3e25431b97c84b3dbd2dde95c554f6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Security for color-convert 1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for color_convert-1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.4 This release

2 release files Full provenance

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