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 LoadGlyph
in your transform pipeline when tensors are needed.
Installation
The package requires Python 3.10+ and PyTorch 2.5+.
Install TorchFont with uv:
uv add torchfont
Or with pip:
pip install torchfont
Quickstart
from torch.utils.data import DataLoader
from torchfont import GlyphData, Outline, pad_outlines
from torchfont.datasets import GlyphDataset
from torchfont.transforms import LoadGlyph
def collate_fn(samples: list[GlyphData[Outline]]) -> Outline:
return pad_outlines([sample.data for sample in samples])
dataset = GlyphDataset(
root="~/fonts", # or "tests/fonts" in this repository
patterns=("*.ttf",),
codepoints=range(0x20, 0x7F), # printable ASCII
transform=LoadGlyph(),
)
loader = DataLoader(
dataset,
batch_size=8,
shuffle=True,
collate_fn=collate_fn,
)
outlines = next(iter(loader))
print(outlines.types.shape) # (8, L)
print(outlines.coords.shape) # (8, L, 6)
Use pad_outlines to pad variable-length outlines. A model that also needs
targets can add them to the batch in its local collate_fn.
What TorchFont Focuses On
- local font directories and repository checkouts as the input boundary
- local font indexing plus explicit outline loading through lightweight glyph references
torchvision.transforms.v2-style semantic pipelines for adapting glyph samples- PyTorch
DataLoaderintegration through an explicit, customizablecollate_fn
Manage font repository synchronization with Git or another tool, then point
GlyphDataset(root=...) at the resulting directory.
Citing TorchFont
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.12.5
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.12.5.tar.gz | 3.2 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| torchfont-0.12.5-cp314-cp314t-win_amd64.whl | CPython 3.14 | CPython 3.14 free-threading | Windows x86-64 | Details |
| torchfont-0.12.5-cp314-cp314t-manylinux_2_35_aarch64.whl | CPython 3.14 | CPython 3.14 free-threading | Linux glibc 2.35+ ARM64 | Details |
| torchfont-0.12.5-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.14 | CPython 3.14 free-threading | Linux glibc 2.17+ x86-64 | Details |
| torchfont-0.12.5-cp314-cp314t-macosx_11_0_arm64.whl | CPython 3.14 | CPython 3.14 free-threading | macOS 11.0+ ARM64 | Details |
| torchfont-0.12.5-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| torchfont-0.12.5-cp310-abi3-manylinux_2_35_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.35+ ARM64 | Details |
| torchfont-0.12.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| torchfont-0.12.5-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 21.4 MB
Release files / torchfont-0.12.5.tar.gz
| Download URL | torchfont-0.12.5.tar.gz |
|---|---|
| Size | 3.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f176735aae42a65407ff345baa98e3e504f9c1d4589ac8cc83977c28883f7326
|
|
BLAKE2b-256 checksum How to use checksums |
1f71051623e0c2ddc937745d0e815623a20cd87bf1cf77554ea2633c739c9a07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","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.12.5-cp314-cp314t-win_amd64.whl
| Download URL | torchfont-0.12.5-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 |
9aa04004d9defa189bcc2fcbdfe94fb88ad51ab892c8739c1bd4e7e6c16f51bb
|
|
BLAKE2b-256 checksum How to use checksums |
57f461e1bbf7fba08efa6a96a5cc0c27d29319876198de7c3a7af478aff3b557
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","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.12.5-cp314-cp314t-manylinux_2_35_aarch64.whl
| Download URL | torchfont-0.12.5-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 |
e4e0cc998dc8d69eeed19cf58f9954cd0648da01f3de4ee527cc96e89ab96ee3
|
|
BLAKE2b-256 checksum How to use checksums |
3460af07215bfbfa2c002e3980b96f6d0d9670788ee1f4c8109929f0b8b2afce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","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.12.5-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | torchfont-0.12.5-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 |
7a09877336e34a16c51da555e6a2fa8903484832159fbbc1de379312103f18cc
|
|
BLAKE2b-256 checksum How to use checksums |
eefc972b38d76f2f0fe35578d43044ba2ae07eb8ff955992551d9f8e6ad25042
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","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.12.5-cp314-cp314t-macosx_11_0_arm64.whl
| Download URL | torchfont-0.12.5-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 |
bc887986f77943596239a36d7ad4dabc7c50048561d5d91400e81981982c6716
|
|
BLAKE2b-256 checksum How to use checksums |
88775779e9c7a64779f27657351113836235098fdecbde3ba344ac739a4c4644
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","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.12.5-cp310-abi3-win_amd64.whl
| Download URL | torchfont-0.12.5-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 2.9 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
fbc0a6648b16934bd37492b33b4af4c468ecb6ef3ea648c66f6c04509d6c2ebc
|
|
BLAKE2b-256 checksum How to use checksums |
f097e8dc8d3293f1be083bfbee391fdb6d6a1514699db63ad34c994a8fb8dae3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","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.12.5-cp310-abi3-manylinux_2_35_aarch64.whl
| Download URL | torchfont-0.12.5-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 |
3ba6233e327829bbaf8a343e83235dbf3866f7bb24fc19c64466fa32835a232c
|
|
BLAKE2b-256 checksum How to use checksums |
db24744bb6d4c520becbead1a2674e05eba5511d5f57171c62a0741c070d4df5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","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.12.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | torchfont-0.12.5-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 |
fa7b8780ea15c4aad800c9bf0827bf90255f1099ec8227ca161ee930926e84cc
|
|
BLAKE2b-256 checksum How to use checksums |
5fec36df324c1d49eb3e7cbc97e2c8a45ec84df15031df9ab3643c7b1aadd1b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","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.12.5-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | torchfont-0.12.5-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8ab0dbd54460cd311691b6f08a30f015f1ece6825a25c71c2631a8592e185b72
|
|
BLAKE2b-256 checksum How to use checksums |
ea1be4abf60ee890603efcf9e0b3a81302102b0f264bd9ebe02da63efb6a9b02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","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}
|