spyrite
Python library to create MapLibre/Mapbox compatible sprite file.
Features
- Few dependencies (only Pillow)
- Input: Image files of icons (no SVG support)
- Parameters:
- max_width: Maximum width of the sprite image, default is 1024
- icon_height: Height of each icon, default is 32
- padding: Gap between icons, default is 2
- Parameters:
- Output: MapLibre/Mapbox compatible sprite files (sprite.png and sprite.json)
Sprite Specification
- Icon name is derived from the filename without extension (e.g., bank-JP.png -> bank-JP)
- Height of each icon is uniform (icon_height)
- Width of each icon is proportional to the original aspect ratio
- Total width of the sprite image does not exceed max_width in almost all cases
- If an icon is too wide to fit in the remaining space of the current row, it is moved to the next row
- If an icon with fixed height of icon_height is wider than max_width, the icon won't be resized and set to a row as is. Then, width of the sprite image may exceed max_width.
CLI Usage
pip install spyrite
spyrite --help
usage: spyrite [-h] [--output-dir OUTPUT_DIR] [--padding PADDING] [--icon-height ICON_HEIGHT]
[--max-width MAX_WIDTH] [--retina]
icons_dir
Generate a MapLibre/Mapbox compatible sprite sheet from PNG icons.
positional arguments:
icons_dir Directory that contains source icons
options:
-h, --help show this help message and exit
--output-dir OUTPUT_DIR
Directory to write output files to (default: current directory)
--padding PADDING XY gap (in px) inserted between icons (default: 2)
--icon-height ICON_HEIGHT
Height (in px) each icon is resized to (default: 32)
--max-width MAX_WIDTH
Maximum width (in px) of the generated sprite sheet (default: 1024)
--retina Flag indicating that the output should be treated as retina assets.
spyrite icons_dir
# This will generate sprite.png and sprite.json in the current directory
spyrite icons_dir --output-dir output_dir --max-width 2048 --icon-height 128 --padding 4 --retina
# This will generate sprite.png and sprite.json in output_dir with specified parameters
Example
# convert maki-icons https://github.com/mapbox/maki
spyrite sample/maki-icons --output-dir sample # sprite.json/png
spyrite sample/maki-icons --output-dir sample --retina # sprite@2x.json/png
sample/sprite@2x.png
Development
uv sync
uv run python -m spyrite
uv run pytest
uv run ruff check .
uv run ty check spyrite
Metadata
Release files for spyrite 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spyrite-0.2.0.tar.gz | 4.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spyrite-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.4 kB
Release files / spyrite-0.2.0.tar.gz
| Download URL | spyrite-0.2.0.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c96086d307444f1bc9ea6bda8e4518c154d3f1bdf2f2a68c633a71d6fcc88817
|
|
BLAKE2b-256 checksum How to use checksums |
aa1ad930c655d2ff538d7b88505fc56209a1f1c0a9adbd83458cf06952a24e4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / spyrite-0.2.0-py3-none-any.whl
| Download URL | spyrite-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8a80dfa929177d9fe770831c8ca2f6e91196c988a9b423ff76c3d0656e60905a
|
|
BLAKE2b-256 checksum How to use checksums |
c0aab0b46270aeb728fbc202b339ce27b4487a937cd75333f7620ce34fe7d327
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|