colorbrew 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ lint:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: astral-sh/setup-uv@v5
15
+ - run: uv sync
16
+ - run: uv run ruff check src/
17
+
18
+ test:
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ python-version: ["3.12", "3.13"]
23
+ steps:
24
+ - uses: actions/checkout@v4
25
+ - uses: astral-sh/setup-uv@v5
26
+ with:
27
+ python-version: ${{ matrix.python-version }}
28
+ - run: uv sync
29
+ - run: uv run pytest
@@ -0,0 +1,18 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags: ["[0-9]+.[0-9]+.[0-9]+"]
6
+
7
+ permissions:
8
+ id-token: write
9
+
10
+ jobs:
11
+ publish:
12
+ runs-on: ubuntu-latest
13
+ environment: pypi
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: astral-sh/setup-uv@v5
17
+ - run: uv build
18
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,216 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+
204
+ # Ruff stuff:
205
+ .ruff_cache/
206
+
207
+ # PyPI configuration file
208
+ .pypirc
209
+
210
+ # Marimo
211
+ marimo/_static/
212
+ marimo/_lsp/
213
+ __marimo__/
214
+
215
+ # Streamlit
216
+ .streamlit/secrets.toml
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dawid Prus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.4
2
+ Name: colorbrew
3
+ Version: 0.1.0
4
+ Summary: A lightweight, zero-dependency Python library for color manipulation.
5
+ Project-URL: Homepage, https://github.com/zfoq/colorbrew
6
+ Project-URL: Repository, https://github.com/zfoq/colorbrew
7
+ Author: Dawid Prus
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: accessibility,color,css,hex,hsl,palette,rgb,wcag
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.12
20
+ Description-Content-Type: text/markdown
21
+
22
+ # ColorBrew
23
+
24
+ A lightweight, zero-dependency Python library for working with colors.
25
+
26
+ ## Features
27
+
28
+ - Parse colors from hex strings (`#3498db`, `#fff`, `3498db`)
29
+ - Parse CSS function strings (`rgb(52, 152, 219)`, `hsl(204, 70%, 53%)`)
30
+ - Parse CSS named colors (`cornflowerblue`, `red`, etc.)
31
+ - Convert between hex, RGB, HSL, and CMYK formats
32
+ - Input validation with clear error messages
33
+ - 148 built-in CSS named colors
34
+ - Immutable `Color` class with format properties and dunder methods
35
+ - CSS/HTML-ready output (`rgb()`, `rgba()`, `hsl()`, `hsla()`, hex)
36
+ - Format string support (`f"{color:rgb}"`, `f"{color:hsl}"`)
37
+ - Reverse name lookup — find the closest CSS named color with distance score
38
+ - Color manipulation — lighten, darken, saturate, desaturate, rotate hue, invert, grayscale, mix
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ pip install colorbrew
44
+ ```
45
+
46
+ Requires Python 3.12+. Zero runtime dependencies.
47
+
48
+ ## Quick Start
49
+
50
+ ```python
51
+ from colorbrew import Color
52
+
53
+ # Create from any format
54
+ c = Color("#3498db")
55
+ c = Color(52, 152, 219)
56
+ c = Color("rgb(52, 152, 219)")
57
+ c = Color("cornflowerblue")
58
+
59
+ # Alternate constructors
60
+ c = Color.from_hsl(204, 70, 53)
61
+ c = Color.from_cmyk(76, 31, 0, 14)
62
+ c = Color.from_name("cornflowerblue")
63
+
64
+ # Access format properties
65
+ c.rgb # (52, 152, 219)
66
+ c.hex # "#3498db"
67
+ c.hsl # (204, 70, 53)
68
+ c.cmyk # (76, 31, 0, 14)
69
+
70
+ # CSS output
71
+ c.css_rgb # "rgb(52, 152, 219)"
72
+ c.css_hsl # "hsl(204, 70%, 53%)"
73
+ c.css_hex # "#3498db"
74
+ c.css_rgba(0.5) # "rgba(52, 152, 219, 0.5)"
75
+ c.css_hsla(0.8) # "hsla(204, 70%, 53%, 0.8)"
76
+
77
+ # Format strings
78
+ f"{c:rgb}" # "rgb(52, 152, 219)"
79
+ f"{c:hsl}" # "hsl(204, 70%, 53%)"
80
+ f"{c:hex}" # "#3498db"
81
+
82
+ # Reverse name lookup
83
+ match = c.closest_name
84
+ match.name # "steelblue"
85
+ match.distance # 10.7703
86
+ match.exact # False
87
+
88
+ # Manipulation (all return new Color instances)
89
+ c.lighten(20) # lighter color
90
+ c.darken(10) # darker color
91
+ c.saturate(15) # more vivid
92
+ c.desaturate(15) # more muted
93
+ c.rotate(180) # shift hue
94
+ c.invert() # RGB inverse
95
+ c.grayscale() # remove saturation
96
+ c.mix(Color("red"), 0.5) # blend two colors
97
+
98
+ # Iteration and comparison
99
+ r, g, b = c # unpack RGB
100
+ Color("#ff0000") == Color("red") # True
101
+ ```
102
+
103
+ ## Development
104
+
105
+ ```bash
106
+ uv sync
107
+ uv run pytest
108
+ uv run ruff check src/
109
+ ```
110
+
111
+ ## License
112
+
113
+ MIT
@@ -0,0 +1,92 @@
1
+ # ColorBrew
2
+
3
+ A lightweight, zero-dependency Python library for working with colors.
4
+
5
+ ## Features
6
+
7
+ - Parse colors from hex strings (`#3498db`, `#fff`, `3498db`)
8
+ - Parse CSS function strings (`rgb(52, 152, 219)`, `hsl(204, 70%, 53%)`)
9
+ - Parse CSS named colors (`cornflowerblue`, `red`, etc.)
10
+ - Convert between hex, RGB, HSL, and CMYK formats
11
+ - Input validation with clear error messages
12
+ - 148 built-in CSS named colors
13
+ - Immutable `Color` class with format properties and dunder methods
14
+ - CSS/HTML-ready output (`rgb()`, `rgba()`, `hsl()`, `hsla()`, hex)
15
+ - Format string support (`f"{color:rgb}"`, `f"{color:hsl}"`)
16
+ - Reverse name lookup — find the closest CSS named color with distance score
17
+ - Color manipulation — lighten, darken, saturate, desaturate, rotate hue, invert, grayscale, mix
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install colorbrew
23
+ ```
24
+
25
+ Requires Python 3.12+. Zero runtime dependencies.
26
+
27
+ ## Quick Start
28
+
29
+ ```python
30
+ from colorbrew import Color
31
+
32
+ # Create from any format
33
+ c = Color("#3498db")
34
+ c = Color(52, 152, 219)
35
+ c = Color("rgb(52, 152, 219)")
36
+ c = Color("cornflowerblue")
37
+
38
+ # Alternate constructors
39
+ c = Color.from_hsl(204, 70, 53)
40
+ c = Color.from_cmyk(76, 31, 0, 14)
41
+ c = Color.from_name("cornflowerblue")
42
+
43
+ # Access format properties
44
+ c.rgb # (52, 152, 219)
45
+ c.hex # "#3498db"
46
+ c.hsl # (204, 70, 53)
47
+ c.cmyk # (76, 31, 0, 14)
48
+
49
+ # CSS output
50
+ c.css_rgb # "rgb(52, 152, 219)"
51
+ c.css_hsl # "hsl(204, 70%, 53%)"
52
+ c.css_hex # "#3498db"
53
+ c.css_rgba(0.5) # "rgba(52, 152, 219, 0.5)"
54
+ c.css_hsla(0.8) # "hsla(204, 70%, 53%, 0.8)"
55
+
56
+ # Format strings
57
+ f"{c:rgb}" # "rgb(52, 152, 219)"
58
+ f"{c:hsl}" # "hsl(204, 70%, 53%)"
59
+ f"{c:hex}" # "#3498db"
60
+
61
+ # Reverse name lookup
62
+ match = c.closest_name
63
+ match.name # "steelblue"
64
+ match.distance # 10.7703
65
+ match.exact # False
66
+
67
+ # Manipulation (all return new Color instances)
68
+ c.lighten(20) # lighter color
69
+ c.darken(10) # darker color
70
+ c.saturate(15) # more vivid
71
+ c.desaturate(15) # more muted
72
+ c.rotate(180) # shift hue
73
+ c.invert() # RGB inverse
74
+ c.grayscale() # remove saturation
75
+ c.mix(Color("red"), 0.5) # blend two colors
76
+
77
+ # Iteration and comparison
78
+ r, g, b = c # unpack RGB
79
+ Color("#ff0000") == Color("red") # True
80
+ ```
81
+
82
+ ## Development
83
+
84
+ ```bash
85
+ uv sync
86
+ uv run pytest
87
+ uv run ruff check src/
88
+ ```
89
+
90
+ ## License
91
+
92
+ MIT
@@ -0,0 +1,59 @@
1
+ [project]
2
+ name = "colorbrew"
3
+ version = "0.1.0"
4
+ description = "A lightweight, zero-dependency Python library for color manipulation."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ requires-python = ">=3.12"
8
+ authors = [{ name = "Dawid Prus" }]
9
+ keywords = ["color", "hex", "rgb", "hsl", "css", "palette", "accessibility", "wcag"]
10
+ classifiers = [
11
+ "Development Status :: 3 - Alpha",
12
+ "Intended Audience :: Developers",
13
+ "License :: OSI Approved :: MIT License",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.12",
16
+ "Programming Language :: Python :: 3.13",
17
+ "Topic :: Software Development :: Libraries :: Python Modules",
18
+ "Typing :: Typed",
19
+ ]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/zfoq/colorbrew"
23
+ Repository = "https://github.com/zfoq/colorbrew"
24
+
25
+ [build-system]
26
+ requires = ["hatchling"]
27
+ build-backend = "hatchling.build"
28
+
29
+ [tool.hatch.build.targets.wheel]
30
+ packages = ["src/colorbrew"]
31
+
32
+ [dependency-groups]
33
+ dev = [
34
+ "pytest>=8.0",
35
+ "ruff>=0.9",
36
+ ]
37
+
38
+ [tool.ruff]
39
+ target-version = "py312"
40
+ line-length = 88
41
+ src = ["src"]
42
+
43
+ [tool.ruff.lint]
44
+ select = [
45
+ "E", # pycodestyle errors
46
+ "W", # pycodestyle warnings
47
+ "F", # pyflakes
48
+ "I", # isort
49
+ "UP", # pyupgrade
50
+ "D", # pydocstyle
51
+ "RUF", # ruff-specific rules
52
+ ]
53
+ ignore = []
54
+
55
+ [tool.ruff.lint.pydocstyle]
56
+ convention = "google"
57
+
58
+ [tool.pytest.ini_options]
59
+ testpaths = ["tests"]
@@ -0,0 +1,24 @@
1
+ """ColorBrew — a lightweight, zero-dependency Python library for colors.
2
+
3
+ Provides color parsing, format conversion, CSS/HTML output, reverse name
4
+ lookup, and color manipulation through a single ``Color`` class.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from colorbrew.color import Color
10
+ from colorbrew.converters import hex_to_rgb, hsl_to_rgb, rgb_to_hex, rgb_to_hsl
11
+ from colorbrew.exceptions import ColorBrewError, ColorParseError, ColorValueError
12
+ from colorbrew.types import NameMatch
13
+
14
+ __all__ = [
15
+ "Color",
16
+ "ColorBrewError",
17
+ "ColorParseError",
18
+ "ColorValueError",
19
+ "NameMatch",
20
+ "hex_to_rgb",
21
+ "hsl_to_rgb",
22
+ "rgb_to_hex",
23
+ "rgb_to_hsl",
24
+ ]