Skip to main content

Cleome

Cleome is a Python CLI tool and library that slices Japanese, Korean, and Chinese (JP / KR / SC / TC / HK) variable and static fonts (.ttf / .otf) into unicode-range .woff2 files and @font-face CSS.

Cleome inspects a font's cmap once and writes deterministic static assets instead of scanning page HTML on every site deploy. You can host the generated .woff2 chunks and @font-face stylesheet directly from Next.js, Astro, Fontsource, or any static CDN. Compared to Google Fonts' static slicing templates, Cleome produces smaller stylesheets and transfers fewer .woff2 bytes while keeping OpenType layout features, UVS/IVS variation sequences, and variable font axes intact.


Installation

Requires Python >= 3.15 and uv.

# Install as a standalone CLI tool from GitHub
uv tool install git+https://github.com/myakura/cleome

# Or run directly without installing
uvx --from git+https://github.com/myakura/cleome cleome plan SourceHanSansJP-VF.otf

# Or add to a Python project
uv add git+https://github.com/myakura/cleome

CLI usage

# Preview the dynamic 4-tier slice plan without writing files (read-only)
cleome plan SourceHanSansJP-VF.otf
cleome plan SourceHanSansJP-VF.otf --json

# Slice a Variable Font (auto-detects CJK profile; outputs <out-dir>/<slug>.css and <out-dir>/slices/<slug>-*-<hash8>.woff2)
# Subsequent builds with unchanged inputs/config skip WOFF2 subsetting automatically; pass --force to rebuild
# Pass --dry-run to validate inputs and output paths without creating directories or writing files
# Pass --css-out to write the stylesheet to src/styles/ while keeping .woff2 slices in public/fonts/
# Pass --no-filename-hash when placing slices in a bundler-managed directory that adds its own asset hash
cleome build SourceHanSansJP-VF.otf -o dist/web
cleome build SourceHanSansJP-VF.otf -o dist/web --dry-run
cleome build SourceHanSansJP-VF.otf -o dist/web --force
cleome build SourceHanSansJP-VF.otf -o public/fonts --url-prefix "/fonts/slices" --css-out src/styles/fonts.css
cleome build SourceHanSansJP-VF.otf -o src/assets/fonts --no-filename-hash

# Explicitly select a CJK slicing profile (auto, jp, kr, sc, tc, hk)
cleome build SourceHanSansJP-VF.otf --locale jp -o dist/web-jp
cleome build NotoSansKR-VF.ttf --locale kr -o dist/web-kr

# Slice multiple Static Font weights into a single unified @font-face CSS and slices/ directory
cleome build MyFontJP-Regular.ttf MyFontJP-Bold.ttf -o dist/web-static

# Customize CSS font-family, URL prefix, chunk sizes, or retained OpenType layout features
# Note: --layout-features replaces the entire feature list (default is '*' for all features),
# so include vertical writing (vert,vrt2,vpal,vhal,vkrn) and composition (ccmp,locl) tags if needed.
cleome build MyFont-VF.otf -o dist/web \
  --locale jp \
  --family "My Font JP" \
  --slug "my-font-jp" \
  --url-prefix "/assets/fonts/slices" \
  --rare-chunk-size 250 \
  --layout-features "ccmp,locl,kern,mark,mkmk,liga,palt,halt,vpal,vhal,vkrn,vert,vrt2,ruby"

Python API usage

Call slice_font or slice_fonts from a build script with either file paths or in-memory fontTools.ttLib.TTFont objects. Cleome does not mutate caller-supplied TTFont instances.

When workers > 1 (the default), Cleome runs subsetting in a ProcessPoolExecutor. On platforms that use spawn or forkserver (macOS, Windows, and Linux on Python 3.14+), guard top-level scripts with if __name__ == "__main__": or pass workers=1.

from pathlib import Path
from cleome import SliceConfig, slice_font, slice_fonts

if __name__ == "__main__":
    # 1. Slice a Variable Font (path or in-memory TTFont; locale="auto" by default)
    result = slice_font(
        "SourceHanSansJP-VF.otf",
        out_dir=Path("dist/web"),
        config=SliceConfig(
            locale="auto",  # "auto", "jp", "kr", "sc", "tc", or "hk"
            slices_subdir="slices",
            rare_chunk_size=250,
        ),
    )
    print(f"Generated {result.css_path} and {len(result.built_files)} WOFF2 slices")

    # 2. Slice multiple Static Font weights into a unified stylesheet
    static_result = slice_fonts(
        [
            "MyFontJP-Regular.ttf",
            "MyFontJP-Bold.ttf",
        ],
        out_dir=Path("dist/web-static"),
        family_name="My Font JP",
    )

Development and testing

uv sync
uv run python -m unittest discover -s tests -v -f

Documentation

  • Hosting and usage guide explains how to deploy generated <slug>.css and .woff2 slices on static hosts, bundlers, and CDNs, configure --url-prefix and --slices-dir, and set preload, CORS, and Cache-Control headers.
  • Architecture and rationale explains the 4-tier cascade shadowing design, inverted-pyramid Kanji granularity simulations, OpenType subsetting details, and the issues found in Google Fonts' Japanese delivery.
  • Chinese and Korean (KR / SC / TC / HK) slicing analysis covers Google Fonts' Korean and Chinese (SC, TC, HK) slice templates, ghost unicode-range rules, punctuation, Jamo, and Bopomofo splits, and 4-tier simulation results.

Acknowledgments

  • Google Fonts published the production stylesheets, slice definitions (gfsubsets / nam-files), and corpus frequency data analyzed during this project.
  • Noto Sans Japanese (Noto Sans JP) and Source Han Sans (源ノ角ゴシック) were the primary Japanese typefaces used to test and verify Cleome.
  • fontTools handles OpenType table inspection, cmap, GSUB, and GPOS subsetting (fontTools.subset), and WOFF2 packing.
  • Brotli compresses and decompresses the WOFF2 streams.
  • HarfBuzz and uharfbuzz verify OpenType glyph shaping, cmap Format 14 variation sequences, and combining mark composition (ccmp) in the test suite.
  • Stixis validates and serializes the generated @font-face CSS rules and unicode-range descriptors.

License

MIT License

Metadata

Release files for cleome 0.3.0

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

Source distribution (sdist)

Source distribution for cleome 0.3.0
File Size Uploaded Provenance
cleome-0.3.0.tar.gz 127.8 kB With provenance Details

Built distribution (wheel)

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

Total release size: 204.3 kB

Release files / cleome-0.3.0.tar.gz

Download URL cleome-0.3.0.tar.gz
Size 127.8 kB
Tags Source
SHA-256 checksum
How to use checksums
dc05eade47db04a7d1610b4602e06b76c14362834d743252c2abadca6b930145
BLAKE2b-256 checksum
How to use checksums
ab490731458cc0959b28b198870cbf888a13a182b002d819207f43502dbcede7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 26, 2026.

Transparency log

Release files / cleome-0.3.0-py3-none-any.whl

Download URL cleome-0.3.0-py3-none-any.whl
Size 76.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63dea636609e975810a669c3b941ee5957169bc34f35e1d0264c608b775e6e2d
BLAKE2b-256 checksum
How to use checksums
34a2eacb668c8d560c69c967929459519959446d45bb36f330b2cb9fcde45141
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 26, 2026.

Transparency log

Security for cleome 0.3.0

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 cleome-0.3.0.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 Oct 26, 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

0.3.0 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