Skip to main content

TorchFont

TorchFont logo

License: MIT Python Version CI Documentation PyPI Downloads PyPI version Rust PyTorch

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 CodepointDataset or GlyphIdDataset at a font directory or a repository checkout that already exists on disk, and TorchFont turns font files into lightweight glyph references. CodepointDataset indexes one sample per face and codepoint, while GlyphIdDataset indexes one sample per face and glyph, reaching ligatures and alternates no codepoint maps to. 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.nn.utils.rnn import pad_sequence
from torch.utils.data import DataLoader

from torchfont import CodepointData, ElementType, Outline
from torchfont.datasets import CodepointDataset
from torchfont.transforms import LoadGlyph


def collate_fn(samples: list[CodepointData[Outline]]):
    outlines = [sample.data for sample in samples]
    return {
        "types": pad_sequence(
            [outline.types for outline in outlines],
            batch_first=True,
            padding_value=ElementType.PAD,
        ),
        "coords": pad_sequence(
            [outline.coords for outline in outlines], batch_first=True
        ),
    }


dataset = CodepointDataset(
    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,
)
batch = next(iter(loader))

print(batch["types"].shape)  # (8, L)
print(batch["coords"].shape)  # (8, L, 6)

What TorchFont Focuses On

  • local font directories and repository checkouts as the input boundary
  • local font indexing by codepoint or by glyph id, plus explicit outline loading through lightweight glyph references
  • torchvision.transforms.v2-style semantic pipelines for adapting glyph samples
  • PyTorch DataLoader integration through an explicit, customizable collate_fn

Manage font repository synchronization with Git or another tool, then point CodepointDataset(root=...) or GlyphIdDataset(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.13.8

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

Source distribution (sdist)

Source distribution for torchfont 0.13.8
File Size Uploaded
torchfont-0.13.8.tar.gz 3.2 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for torchfont 0.13.8
File
torchfont-0.13.8-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
torchfont-0.13.8-cp314-cp314t-manylinux_2_35_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.35+ ARM64 Details
torchfont-0.13.8-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.13.8-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
torchfont-0.13.8-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
torchfont-0.13.8-cp310-abi3-manylinux_2_35_aarch64.whl CPython 3.10 abi3 Linux glibc 2.35+ ARM64 Details
torchfont-0.13.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
torchfont-0.13.8-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details

Total release size: 27.6 MB

Release files / torchfont-0.13.8.tar.gz

Download URL torchfont-0.13.8.tar.gz
Size 3.2 MB
Tags Source
SHA-256 checksum
How to use checksums
34e9d87343ab36308b310bfa397ae518f4c4b7af591880d427b3553b3f60d8de
BLAKE2b-256 checksum
How to use checksums
cd13bdc4d607519cc6b61cd1af156e02f78e58a9fcf96b854c0fcc90d65daa63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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.13.8-cp314-cp314t-win_amd64.whl

Download URL torchfont-0.13.8-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
5742ddb72a562fec79b122facd5ae83f82dad580004d4c3165fb768abdaa5e94
BLAKE2b-256 checksum
How to use checksums
efde607cdca0d5229a574b226f40ff0b0d86e329390bef012c1c1df33ca3dac3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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.13.8-cp314-cp314t-manylinux_2_35_aarch64.whl

Download URL torchfont-0.13.8-cp314-cp314t-manylinux_2_35_aarch64.whl
Size 3.8 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.35+ ARM64
SHA-256 checksum
How to use checksums
94cb4a4ecbcf4cd08eddb93a5d72bd62825c680f7151170e5de3e20fb1a7eae5
BLAKE2b-256 checksum
How to use checksums
1e6d10a3cfd2740407d92eafdb9890911b3ac7e7acff2b377e55b1a94790f0c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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.13.8-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL torchfont-0.13.8-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.9 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
edf03c6af3d4ea8ec5986eba1b84760c831fc728327923e753c446dbfb321eda
BLAKE2b-256 checksum
How to use checksums
62dc9ca1207e1289e7d749d01f5fbf0cd6966de718ebb19f9caddfe0682ef643
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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.13.8-cp314-cp314t-macosx_11_0_arm64.whl

Download URL torchfont-0.13.8-cp314-cp314t-macosx_11_0_arm64.whl
Size 2.5 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
624bfadfa7a8e428d48bc9ff5eda1743ed2c452a0fbf982fed66fbedd325280f
BLAKE2b-256 checksum
How to use checksums
cd09ff11ad076ad9fded1f8734256e838a12d380626786808d3a06e712543ba5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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.13.8-cp310-abi3-win_amd64.whl

Download URL torchfont-0.13.8-cp310-abi3-win_amd64.whl
Size 2.9 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f4137a4568a2e3a75f894a89fce20ea32baa3e32ba5cfd701f281ba34ed4835e
BLAKE2b-256 checksum
How to use checksums
7056fa5d9899509f487a1d6862944e885813c528628ff468c6f433f7ee65397c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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.13.8-cp310-abi3-manylinux_2_35_aarch64.whl

Download URL torchfont-0.13.8-cp310-abi3-manylinux_2_35_aarch64.whl
Size 3.8 MB
Tags CPython 3.10 Linux glibc 2.35+ ARM64 abi3
SHA-256 checksum
How to use checksums
2ae3898a61779c7b7e6465e5958c7e6ff8160d17a57638a54dace6d8325dfa83
BLAKE2b-256 checksum
How to use checksums
e6416f49eb77472ede3d4b96e4fc248b8d9836c3abd4257800c27085763fa389
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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.13.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL torchfont-0.13.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.9 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
3e25c99bcf0c2ac5aad589ea9b75ba8a7af8de2a60ec011a0d0c81360423662c
BLAKE2b-256 checksum
How to use checksums
b94f13bb16409ad438b1da3bede2eb88f6321592db2040d2cd30a782f218c638
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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.13.8-cp310-abi3-macosx_11_0_arm64.whl

Download URL torchfont-0.13.8-cp310-abi3-macosx_11_0_arm64.whl
Size 2.5 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
70016f602a297f3e0dee83487931df441ad3efac6780d1611a4ab1c1d4c7d47e
BLAKE2b-256 checksum
How to use checksums
2acc7c0f87a6db6c3cc538a5613fd1d7640d3ac3243d5c525443475454492d78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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 history Release notifications | RSS feed

0.13.9

9 release files

This release

0.13.8 This release

9 release files

0.13.7

9 release files

0.13.6

9 release files

0.13.5

9 release files

0.13.4

9 release files

0.13.3

9 release files

0.13.2

9 release files

0.13.1

9 release files

0.13.0

9 release files

0.12.5

9 release files

0.9.6

13 release files

0.9.5

13 release files

0.9.4

13 release files

0.9.3

13 release files

0.9.2

31 release files

0.9.1

31 release files

0.9.0

31 release files

0.7.1

17 release files

0.7.0

17 release files

0.6.3

17 release files

0.6.1

17 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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