TorchFont
TorchFont is an unofficial library based on PyTorch for deep learning with vector fonts. It is not affiliated with or endorsed by the PyTorch project.
TorchFont is local-first: point GlyphDataset at a font directory or a
repository checkout that already exists on disk, and TorchFont turns font files
into lightweight glyph references. Load outlines explicitly with load_glyph
inside your transform when tensors are needed.
Installation
The package requires Python 3.10+ and PyTorch 2.3+.
Install TorchFont with uv:
uv add torchfont
Or with pip:
pip install torchfont
Quickstart
from torch.utils.data import DataLoader
from torch.nn.utils.rnn import pad_sequence
from torchfont.datasets import GlyphDataset, GlyphSample
from torchfont.transforms import load_glyph
def transform(sample: GlyphSample):
return load_glyph(sample.ref)
def collate_fn(batch):
types = pad_sequence([types for types, _ in batch], batch_first=True)
coords = pad_sequence([coords for _, coords in batch], batch_first=True)
return types, coords
dataset = GlyphDataset(
root="~/fonts", # or "tests/fonts" in this repository
patterns=("*.ttf",),
codepoints=range(0x20, 0x7F), # printable ASCII
transform=transform,
)
loader = DataLoader(dataset, batch_size=8, shuffle=True, collate_fn=collate_fn)
types_t, coords_t = next(iter(loader))
print(types_t.shape) # (8, L)
print(coords_t.shape) # (8, L, 6)
What TorchFont Focuses On
- local font directories and repository checkouts as the input boundary
- Rust-backed indexing plus explicit outline loading through lightweight glyph references
- transform utilities such as
quad_to_cubicfor adapting glyph samples - PyTorch
DataLoaderintegration through ordinary user-definedcollate_fnfunctions
TorchFont does not need to own Git clone / fetch / checkout in the main
workflow. Sync repositories with Git or another tool, then point
GlyphDataset(root=...) at the resulting directory.
Citation
If you find TorchFont useful in your work, please consider citing the following BibTeX entry:
@software{fujioka2025torchfont,
author = {Fujioka, Takumu},
title = {{TorchFont: A Machine Learning library for Vector Fonts}},
year = {2025},
url = {https://github.com/torchfont/torchfont}
}
Metadata
Release files for torchfont 0.11.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| torchfont-0.11.1.tar.gz | 7.2 MB | Details |
Built distributions (wheels)
Total release size: 34.4 MB
Release files / torchfont-0.11.1.tar.gz
| Download URL | torchfont-0.11.1.tar.gz |
|---|---|
| Size | 7.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f8009aa604c5ec82b8beb6b086525291b1ac20b6e2cb8372530729218f969f18
|
|
BLAKE2b-256 checksum How to use checksums |
0728b5a48f956550550c28cceaaf94283650d3339eed18abc1001bb655fcf8c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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 / torchfont-0.11.1-cp314-cp314t-win_arm64.whl
| Download URL | torchfont-0.11.1-cp314-cp314t-win_arm64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Windows ARM64 |
|
SHA-256 checksum How to use checksums |
addf2cb7b39c1acc6bdb0ff7e85e43d35ed24ecec4bcf4b74c9df5eb0d686716
|
|
BLAKE2b-256 checksum How to use checksums |
e41be3658eddee46c2fe442860d0eca6efea5de8a2823504c5f0604f5478c2c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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 / torchfont-0.11.1-cp314-cp314t-win_amd64.whl
| Download URL | torchfont-0.11.1-cp314-cp314t-win_amd64.whl |
|---|---|
| Size | 2.9 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Windows x86-64 |
|
SHA-256 checksum How to use checksums |
b7a6b82eeea6e4e495f154100ad0b079bdc6a1b6430d27470c6b8fb7b18e603c
|
|
BLAKE2b-256 checksum How to use checksums |
30f56a6fe0520148d641699fd8fec584e9635e5a1339406b408a69688c0ca2c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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 / torchfont-0.11.1-cp314-cp314t-manylinux_2_35_aarch64.whl
| Download URL | torchfont-0.11.1-cp314-cp314t-manylinux_2_35_aarch64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.35+ ARM64 |
|
SHA-256 checksum How to use checksums |
55e5144b2c72eef58539609138aa72d3246d263c3ef75de61b7b7a365c9cdb1e
|
|
BLAKE2b-256 checksum How to use checksums |
d49a7eaed66d0cea4bd2a0c1c586ead7ea2018503bf91e32a44e1bf7b797ae46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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 / torchfont-0.11.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | torchfont-0.11.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
7728961448c47009e7f72635d94ffdeb7099bf2583c7b0613fd77652a4915ae1
|
|
BLAKE2b-256 checksum How to use checksums |
4b2588652c6e30067c102a491f6306fca197c1e00922760f2397477cfc13a211
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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 / torchfont-0.11.1-cp314-cp314t-macosx_11_0_arm64.whl
| Download URL | torchfont-0.11.1-cp314-cp314t-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
01e0eb3600a72c55fa4999af2fb9a941fa55da03bb3ef8306c52b48d95be81d0
|
|
BLAKE2b-256 checksum How to use checksums |
7f90dc35e64d1053b019c5fb7b5c20681cc0212f6e53750b4f33f4043bba5ffd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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 / torchfont-0.11.1-cp314-cp314t-macosx_10_12_x86_64.whl
| Download URL | torchfont-0.11.1-cp314-cp314t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
3e2ebda335b9bdc0ab7c0c852b2cbffd1d623bbfd29c888ab41111f58a8d7ba7
|
|
BLAKE2b-256 checksum How to use checksums |
b3508b93280e1e543371716ab1416db428db278323adce34515758cbd716aa39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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 / torchfont-0.11.1-cp310-abi3-win_arm64.whl
| Download URL | torchfont-0.11.1-cp310-abi3-win_arm64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.10 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
93da7951f0936e54c80002fcc30f205e2bd983eac2ecdce83768ab954a1135af
|
|
BLAKE2b-256 checksum How to use checksums |
fc533e8bf0112d1eae647967e6a0180dbe03fc5692aadcaefe07ad0523c08fc9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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 / torchfont-0.11.1-cp310-abi3-win_amd64.whl
| Download URL | torchfont-0.11.1-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 2.9 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
87eadf9dc80e72c46abe81d65b366622a299d51ee8d52fe6a6dcc0a4aefb9066
|
|
BLAKE2b-256 checksum How to use checksums |
212e2353fef6f1d98660fbdcb300cdf83fd0ee45d1ca24e20f537d0a59d3a80c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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 / torchfont-0.11.1-cp310-abi3-manylinux_2_35_aarch64.whl
| Download URL | torchfont-0.11.1-cp310-abi3-manylinux_2_35_aarch64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.10 Linux glibc 2.35+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
9919ca4602f873b03c9028dcc259373079dcc6c9b6fe01fbfce4d0051829d253
|
|
BLAKE2b-256 checksum How to use checksums |
8f2d3517be724915485fa6cfc3d98442f0be2b15c9989f2477491363cbed952d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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 / torchfont-0.11.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | torchfont-0.11.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f272db582f085daf21f7b4c617cce8426e4f32f2be2656114cf1e247cf2115a0
|
|
BLAKE2b-256 checksum How to use checksums |
7477e947b634d00146f3022493520a44eac0383d696438eaa534be50feeba2c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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 / torchfont-0.11.1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | torchfont-0.11.1-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0c7244496f839a614527dfa16fb12ed7d0aa2a2eac5423bbf2b18f77949532dc
|
|
BLAKE2b-256 checksum How to use checksums |
e1650a79a5d1bf3858c19a11c48b18090e0c7d33ce927deef92b62a5f4006636
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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 / torchfont-0.11.1-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | torchfont-0.11.1-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
99f8d4fbe8f58fef584b8efd2bacbe521d054267aeba44dd16fae276c8f30609
|
|
BLAKE2b-256 checksum How to use checksums |
e155552d5bc789fe08e333cc92f7c3d740e44d9edff09be17d39ddb499054b88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"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}
|