openbrand 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.
- openbrand-0.1.0/.gitignore +218 -0
- openbrand-0.1.0/LICENSE +21 -0
- openbrand-0.1.0/PKG-INFO +123 -0
- openbrand-0.1.0/README.md +91 -0
- openbrand-0.1.0/pyproject.toml +77 -0
- openbrand-0.1.0/src/openbrand/__init__.py +114 -0
- openbrand-0.1.0/src/openbrand/__main__.py +4 -0
- openbrand-0.1.0/src/openbrand/_async.py +146 -0
- openbrand-0.1.0/src/openbrand/backdrops.py +103 -0
- openbrand-0.1.0/src/openbrand/brand_name.py +79 -0
- openbrand-0.1.0/src/openbrand/cli.py +38 -0
- openbrand-0.1.0/src/openbrand/colors.py +202 -0
- openbrand-0.1.0/src/openbrand/fetch.py +84 -0
- openbrand-0.1.0/src/openbrand/html_parse.py +289 -0
- openbrand-0.1.0/src/openbrand/images.py +97 -0
- openbrand-0.1.0/src/openbrand/logos.py +379 -0
- openbrand-0.1.0/src/openbrand/py.typed +0 -0
- openbrand-0.1.0/src/openbrand/types.py +106 -0
- openbrand-0.1.0/src/openbrand/util.py +44 -0
- openbrand-0.1.0/tests/test_async.py +246 -0
- openbrand-0.1.0/tests/test_backdrops.py +137 -0
- openbrand-0.1.0/tests/test_brand_name.py +168 -0
- openbrand-0.1.0/tests/test_colors.py +184 -0
- openbrand-0.1.0/tests/test_logos.py +466 -0
- openbrand-0.1.0/tests/test_pipeline.py +297 -0
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
# Temporary file for partial code execution
|
|
204
|
+
tempCodeRunnerFile.py
|
|
205
|
+
|
|
206
|
+
# Ruff stuff:
|
|
207
|
+
.ruff_cache/
|
|
208
|
+
|
|
209
|
+
# PyPI configuration file
|
|
210
|
+
.pypirc
|
|
211
|
+
|
|
212
|
+
# Marimo
|
|
213
|
+
marimo/_static/
|
|
214
|
+
marimo/_lsp/
|
|
215
|
+
__marimo__/
|
|
216
|
+
|
|
217
|
+
# Streamlit
|
|
218
|
+
.streamlit/secrets.toml
|
openbrand-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cass
|
|
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.
|
openbrand-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: openbrand
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Extract brand assets (logos, colors, backdrops) from any website. A dependency-light Python alternative to the openbrand npm package.
|
|
5
|
+
Project-URL: Homepage, https://github.com/cassidyhhaas/openbrand-py
|
|
6
|
+
Project-URL: Repository, https://github.com/cassidyhhaas/openbrand-py
|
|
7
|
+
Project-URL: Issues, https://github.com/cassidyhhaas/openbrand-py/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/cassidyhhaas/openbrand-py/releases
|
|
9
|
+
Author-email: Cass <cassidyhhaas@gmail.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: brand,color-extraction,favicon,logo,metadata,scraping,web
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
20
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.12
|
|
24
|
+
Requires-Dist: pillow>=10.0.0
|
|
25
|
+
Provides-Extra: async
|
|
26
|
+
Requires-Dist: httpx>=0.27.0; extra == 'async'
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: httpx>=0.27.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# openbrand
|
|
34
|
+
|
|
35
|
+
Extract brand assets — **logos, colors, backdrops, and brand name** — from any
|
|
36
|
+
website URL. A dependency-light Python port of the open-source
|
|
37
|
+
[`openbrand`](https://github.com/ethanjyx/OpenBrand) npm package, built to
|
|
38
|
+
remove any coupling to the npm registry.
|
|
39
|
+
|
|
40
|
+
**One required dependency:** [Pillow](https://python-pillow.org/) (image
|
|
41
|
+
decoding for color quantization). Everything else is the Python standard
|
|
42
|
+
library. `httpx` is an optional extra for the native-async backend.
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install openbrand
|
|
48
|
+
# or, with the native-async backend (httpx):
|
|
49
|
+
pip install "openbrand[async]"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Requires Python 3.12+.
|
|
53
|
+
|
|
54
|
+
## Library use
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from openbrand import extract_brand_assets
|
|
58
|
+
|
|
59
|
+
result = extract_brand_assets("https://stripe.com")
|
|
60
|
+
if result.ok:
|
|
61
|
+
assets = result.data
|
|
62
|
+
print(assets.brand_name) # "Stripe"
|
|
63
|
+
for logo in assets.logos:
|
|
64
|
+
print(logo.type, logo.url)
|
|
65
|
+
for color in assets.colors:
|
|
66
|
+
print(color.usage, color.hex) # primary / secondary / accent
|
|
67
|
+
for backdrop in assets.backdrops:
|
|
68
|
+
print(backdrop.url)
|
|
69
|
+
else:
|
|
70
|
+
print(result.error.code, result.error.message)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`extract_brand_assets` never raises on network/HTTP failures — they come back
|
|
74
|
+
via `result.ok == False` with a classified `result.error.code` (one of
|
|
75
|
+
`ACCESS_BLOCKED`, `NOT_FOUND`, `SERVER_ERROR`, `NETWORK_ERROR`,
|
|
76
|
+
`EMPTY_CONTENT`).
|
|
77
|
+
|
|
78
|
+
## Async use (FastAPI, asyncio, …)
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from openbrand import aextract_brand_assets
|
|
82
|
+
|
|
83
|
+
result = await aextract_brand_assets("https://stripe.com")
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Drops cleanly into any event loop. Two backends, same return value:
|
|
87
|
+
|
|
88
|
+
- **Default** (no extras): runs the sync pipeline on a worker thread via
|
|
89
|
+
`asyncio.to_thread`. Zero extra deps, never blocks the event loop, no
|
|
90
|
+
in-extraction concurrency.
|
|
91
|
+
- **`pip install "openbrand[async]"`**: switches to a native async backend
|
|
92
|
+
powered by `httpx` that fetches the page and pre-warms all candidate-image
|
|
93
|
+
bytes **concurrently**, then runs the heuristics against cache. Measurably
|
|
94
|
+
faster on sites with many logo candidates.
|
|
95
|
+
|
|
96
|
+
## CLI
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
openbrand https://stripe.com # pretty JSON
|
|
100
|
+
openbrand https://stripe.com --indent 0 # compact, single line
|
|
101
|
+
python -m openbrand https://stripe.com # module form
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Exits non-zero when extraction fails.
|
|
105
|
+
|
|
106
|
+
## What it extracts
|
|
107
|
+
|
|
108
|
+
| Asset | Sources |
|
|
109
|
+
|-------|---------|
|
|
110
|
+
| **brand_name** | `og:site_name` → `application-name` → header/nav logo alt → `<title>` segment → domain |
|
|
111
|
+
| **logos** | favicons, apple-touch-icons, `<img>`, inline `<svg>` (serialized to a `data:` URI), ranked by a two-pass header/nav heuristic; dimensions probed per image |
|
|
112
|
+
| **colors** | declared (`theme-color`, `msapplication-TileColor`, `manifest.json`) + saturation-weighted quantization of the logo imagery; capped at 3 with `primary`/`secondary`/`accent` roles |
|
|
113
|
+
| **backdrops** | `og:image`, CSS `background-image`, hero `<img>` (excludes `data:` and `.svg`) |
|
|
114
|
+
|
|
115
|
+
## Links
|
|
116
|
+
|
|
117
|
+
- Source: [github.com/cassidyhhaas/openbrand-py](https://github.com/cassidyhhaas/openbrand-py)
|
|
118
|
+
- Issues: [github.com/cassidyhhaas/openbrand-py/issues](https://github.com/cassidyhhaas/openbrand-py/issues)
|
|
119
|
+
- Contributing & release process: [CONTRIBUTING.md](https://github.com/cassidyhhaas/openbrand-py/blob/main/CONTRIBUTING.md)
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT (matching the upstream `openbrand` package).
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# openbrand
|
|
2
|
+
|
|
3
|
+
Extract brand assets — **logos, colors, backdrops, and brand name** — from any
|
|
4
|
+
website URL. A dependency-light Python port of the open-source
|
|
5
|
+
[`openbrand`](https://github.com/ethanjyx/OpenBrand) npm package, built to
|
|
6
|
+
remove any coupling to the npm registry.
|
|
7
|
+
|
|
8
|
+
**One required dependency:** [Pillow](https://python-pillow.org/) (image
|
|
9
|
+
decoding for color quantization). Everything else is the Python standard
|
|
10
|
+
library. `httpx` is an optional extra for the native-async backend.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install openbrand
|
|
16
|
+
# or, with the native-async backend (httpx):
|
|
17
|
+
pip install "openbrand[async]"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Requires Python 3.12+.
|
|
21
|
+
|
|
22
|
+
## Library use
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from openbrand import extract_brand_assets
|
|
26
|
+
|
|
27
|
+
result = extract_brand_assets("https://stripe.com")
|
|
28
|
+
if result.ok:
|
|
29
|
+
assets = result.data
|
|
30
|
+
print(assets.brand_name) # "Stripe"
|
|
31
|
+
for logo in assets.logos:
|
|
32
|
+
print(logo.type, logo.url)
|
|
33
|
+
for color in assets.colors:
|
|
34
|
+
print(color.usage, color.hex) # primary / secondary / accent
|
|
35
|
+
for backdrop in assets.backdrops:
|
|
36
|
+
print(backdrop.url)
|
|
37
|
+
else:
|
|
38
|
+
print(result.error.code, result.error.message)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`extract_brand_assets` never raises on network/HTTP failures — they come back
|
|
42
|
+
via `result.ok == False` with a classified `result.error.code` (one of
|
|
43
|
+
`ACCESS_BLOCKED`, `NOT_FOUND`, `SERVER_ERROR`, `NETWORK_ERROR`,
|
|
44
|
+
`EMPTY_CONTENT`).
|
|
45
|
+
|
|
46
|
+
## Async use (FastAPI, asyncio, …)
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from openbrand import aextract_brand_assets
|
|
50
|
+
|
|
51
|
+
result = await aextract_brand_assets("https://stripe.com")
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Drops cleanly into any event loop. Two backends, same return value:
|
|
55
|
+
|
|
56
|
+
- **Default** (no extras): runs the sync pipeline on a worker thread via
|
|
57
|
+
`asyncio.to_thread`. Zero extra deps, never blocks the event loop, no
|
|
58
|
+
in-extraction concurrency.
|
|
59
|
+
- **`pip install "openbrand[async]"`**: switches to a native async backend
|
|
60
|
+
powered by `httpx` that fetches the page and pre-warms all candidate-image
|
|
61
|
+
bytes **concurrently**, then runs the heuristics against cache. Measurably
|
|
62
|
+
faster on sites with many logo candidates.
|
|
63
|
+
|
|
64
|
+
## CLI
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
openbrand https://stripe.com # pretty JSON
|
|
68
|
+
openbrand https://stripe.com --indent 0 # compact, single line
|
|
69
|
+
python -m openbrand https://stripe.com # module form
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Exits non-zero when extraction fails.
|
|
73
|
+
|
|
74
|
+
## What it extracts
|
|
75
|
+
|
|
76
|
+
| Asset | Sources |
|
|
77
|
+
|-------|---------|
|
|
78
|
+
| **brand_name** | `og:site_name` → `application-name` → header/nav logo alt → `<title>` segment → domain |
|
|
79
|
+
| **logos** | favicons, apple-touch-icons, `<img>`, inline `<svg>` (serialized to a `data:` URI), ranked by a two-pass header/nav heuristic; dimensions probed per image |
|
|
80
|
+
| **colors** | declared (`theme-color`, `msapplication-TileColor`, `manifest.json`) + saturation-weighted quantization of the logo imagery; capped at 3 with `primary`/`secondary`/`accent` roles |
|
|
81
|
+
| **backdrops** | `og:image`, CSS `background-image`, hero `<img>` (excludes `data:` and `.svg`) |
|
|
82
|
+
|
|
83
|
+
## Links
|
|
84
|
+
|
|
85
|
+
- Source: [github.com/cassidyhhaas/openbrand-py](https://github.com/cassidyhhaas/openbrand-py)
|
|
86
|
+
- Issues: [github.com/cassidyhhaas/openbrand-py/issues](https://github.com/cassidyhhaas/openbrand-py/issues)
|
|
87
|
+
- Contributing & release process: [CONTRIBUTING.md](https://github.com/cassidyhhaas/openbrand-py/blob/main/CONTRIBUTING.md)
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT (matching the upstream `openbrand` package).
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "openbrand"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Extract brand assets (logos, colors, backdrops) from any website. A dependency-light Python alternative to the openbrand npm package."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Cass", email = "cassidyhhaas@gmail.com" },
|
|
11
|
+
]
|
|
12
|
+
keywords = [
|
|
13
|
+
"brand",
|
|
14
|
+
"logo",
|
|
15
|
+
"favicon",
|
|
16
|
+
"color-extraction",
|
|
17
|
+
"scraping",
|
|
18
|
+
"web",
|
|
19
|
+
"metadata",
|
|
20
|
+
]
|
|
21
|
+
classifiers = [
|
|
22
|
+
"Development Status :: 4 - Beta",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"Operating System :: OS Independent",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
29
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
30
|
+
"Topic :: Multimedia :: Graphics",
|
|
31
|
+
"Typing :: Typed",
|
|
32
|
+
]
|
|
33
|
+
dependencies = [
|
|
34
|
+
"Pillow>=10.0.0",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://github.com/cassidyhhaas/openbrand-py"
|
|
39
|
+
Repository = "https://github.com/cassidyhhaas/openbrand-py"
|
|
40
|
+
Issues = "https://github.com/cassidyhhaas/openbrand-py/issues"
|
|
41
|
+
Changelog = "https://github.com/cassidyhhaas/openbrand-py/releases"
|
|
42
|
+
|
|
43
|
+
[project.scripts]
|
|
44
|
+
openbrand = "openbrand.cli:main"
|
|
45
|
+
|
|
46
|
+
[project.optional-dependencies]
|
|
47
|
+
async = [
|
|
48
|
+
"httpx>=0.27.0",
|
|
49
|
+
]
|
|
50
|
+
dev = [
|
|
51
|
+
"pytest>=8.0.0",
|
|
52
|
+
"pytest-asyncio>=0.23.0",
|
|
53
|
+
"httpx>=0.27.0",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[build-system]
|
|
57
|
+
requires = ["hatchling"]
|
|
58
|
+
build-backend = "hatchling.build"
|
|
59
|
+
|
|
60
|
+
[tool.hatch.build.targets.wheel]
|
|
61
|
+
packages = ["src/openbrand"]
|
|
62
|
+
|
|
63
|
+
[tool.hatch.build.targets.sdist]
|
|
64
|
+
# Ship source for reproducible builds, but skip the 1MB fixture tarball worth
|
|
65
|
+
# of captured HTML snapshots — they're regression-test inputs, not library code.
|
|
66
|
+
include = [
|
|
67
|
+
"src/openbrand",
|
|
68
|
+
"tests/test_*.py",
|
|
69
|
+
"README.md",
|
|
70
|
+
"LICENSE",
|
|
71
|
+
"pyproject.toml",
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
[tool.pytest.ini_options]
|
|
75
|
+
pythonpath = ["src"]
|
|
76
|
+
testpaths = ["tests"]
|
|
77
|
+
asyncio_mode = "auto"
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""openbrand — extract brand assets (logos, colors, backdrops) from any website.
|
|
2
|
+
|
|
3
|
+
A dependency-light Python port of the npm ``openbrand`` package. The only
|
|
4
|
+
*required* third-party dependency is Pillow (image decoding for color
|
|
5
|
+
quantization); everything else is pure standard library.
|
|
6
|
+
|
|
7
|
+
Sync use::
|
|
8
|
+
|
|
9
|
+
from openbrand import extract_brand_assets
|
|
10
|
+
|
|
11
|
+
result = extract_brand_assets("https://stripe.com")
|
|
12
|
+
if result.ok:
|
|
13
|
+
print(result.data.brand_name)
|
|
14
|
+
|
|
15
|
+
Async use (drops cleanly into FastAPI handlers)::
|
|
16
|
+
|
|
17
|
+
from openbrand import aextract_brand_assets
|
|
18
|
+
|
|
19
|
+
result = await aextract_brand_assets("https://stripe.com")
|
|
20
|
+
|
|
21
|
+
Without extras, ``aextract_brand_assets`` runs the sync pipeline on a worker
|
|
22
|
+
thread (no extra deps, never blocks the event loop). With
|
|
23
|
+
``pip install openbrand[async]`` it switches to a native ``httpx`` backend that
|
|
24
|
+
fetches candidate images concurrently — a measurable speedup on sites with many
|
|
25
|
+
logo candidates.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
from .backdrops import extract_backdrops
|
|
31
|
+
from .brand_name import extract_brand_name
|
|
32
|
+
from .colors import extract_colors
|
|
33
|
+
from .fetch import FetchError, fetch_html
|
|
34
|
+
from .html_parse import parse
|
|
35
|
+
from .logos import extract_logos
|
|
36
|
+
from .types import (
|
|
37
|
+
BackdropAsset,
|
|
38
|
+
BrandAssets,
|
|
39
|
+
ColorAsset,
|
|
40
|
+
ExtractionError,
|
|
41
|
+
ExtractionResult,
|
|
42
|
+
LogoAsset,
|
|
43
|
+
Resolution,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
__all__ = [
|
|
47
|
+
"extract_brand_assets",
|
|
48
|
+
"aextract_brand_assets",
|
|
49
|
+
"extract_from_html",
|
|
50
|
+
"BrandAssets",
|
|
51
|
+
"LogoAsset",
|
|
52
|
+
"ColorAsset",
|
|
53
|
+
"BackdropAsset",
|
|
54
|
+
"Resolution",
|
|
55
|
+
"ExtractionError",
|
|
56
|
+
"ExtractionResult",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
__version__ = "0.1.0"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def extract_from_html(html: str, base_url: str) -> BrandAssets:
|
|
63
|
+
"""Run the extraction pipeline on already-fetched HTML.
|
|
64
|
+
|
|
65
|
+
Pure (modulo the network access each extractor performs internally —
|
|
66
|
+
dimension probes for logos, manifest + image fetches for colors). The
|
|
67
|
+
sync and async front-doors both funnel through this so the heuristics
|
|
68
|
+
only live in one place.
|
|
69
|
+
"""
|
|
70
|
+
doc = parse(html)
|
|
71
|
+
# Logos first: color quantization samples the discovered logo imagery.
|
|
72
|
+
logos = extract_logos(doc, base_url)
|
|
73
|
+
return BrandAssets(
|
|
74
|
+
brand_name=extract_brand_name(doc, base_url),
|
|
75
|
+
logos=logos,
|
|
76
|
+
colors=extract_colors(doc, base_url, logos),
|
|
77
|
+
backdrops=extract_backdrops(doc, base_url),
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def extract_brand_assets(url: str) -> ExtractionResult:
|
|
82
|
+
"""Fetch ``url`` and extract its brand assets.
|
|
83
|
+
|
|
84
|
+
Returns an :class:`ExtractionResult`: on success ``result.ok`` is ``True`` and
|
|
85
|
+
``result.data`` is a :class:`BrandAssets`; on failure ``result.ok`` is
|
|
86
|
+
``False`` and ``result.error`` is a classified :class:`ExtractionError`.
|
|
87
|
+
Network/HTTP failures are reported via the error path rather than raised.
|
|
88
|
+
"""
|
|
89
|
+
try:
|
|
90
|
+
html, final_url = fetch_html(url)
|
|
91
|
+
except FetchError as exc:
|
|
92
|
+
return ExtractionResult.failure(exc.error)
|
|
93
|
+
return ExtractionResult.success(extract_from_html(html, final_url))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
async def aextract_brand_assets(url: str) -> ExtractionResult:
|
|
97
|
+
"""Async front-door, safe to call from FastAPI handlers / any event loop.
|
|
98
|
+
|
|
99
|
+
Picks a backend at call time:
|
|
100
|
+
|
|
101
|
+
* ``openbrand[async]`` installed → native ``httpx`` backend that fetches
|
|
102
|
+
the page and pre-warms candidate-image bytes **concurrently**, then runs
|
|
103
|
+
the synchronous heuristics with everything already in cache.
|
|
104
|
+
* ``httpx`` not importable → :func:`asyncio.to_thread` wraps the sync
|
|
105
|
+
pipeline so the event loop never blocks, at the cost of no in-extraction
|
|
106
|
+
concurrency. Identical return value either way.
|
|
107
|
+
"""
|
|
108
|
+
try:
|
|
109
|
+
import httpx # noqa: F401
|
|
110
|
+
except ImportError:
|
|
111
|
+
import asyncio
|
|
112
|
+
return await asyncio.to_thread(extract_brand_assets, url)
|
|
113
|
+
from ._async import aextract_with_httpx
|
|
114
|
+
return await aextract_with_httpx(url)
|