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.7

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.7
File Size Uploaded
torchfont-0.13.7.tar.gz 3.2 MB Details

Built distributions (wheels)

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

Total release size: 27.4 MB

Release files / torchfont-0.13.7.tar.gz

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

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

Download URL torchfont-0.13.7-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
e916416443792648d10b15d33a3babb4cdd9a28c3409b31378d0c017f3a34217
BLAKE2b-256 checksum
How to use checksums
a97f6b57de632cc0f776e3dbd119926bf1e8a2afb52856383b8e5e5de60f0732
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","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.7-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL torchfont-0.13.7-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
59878984ee3f102335da1bf3ebb1a77605ec3435dbd03ce484a15f3078fb763b
BLAKE2b-256 checksum
How to use checksums
134c28d1d15985ae59b44a375b7504795b152cdfcc96afdc068aea07b01a8677
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","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.7-cp314-cp314t-macosx_11_0_arm64.whl

Download URL torchfont-0.13.7-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
d3cf555f2e616b6fea8dfe6d2e064926453bd1dc3680aa6474205ac98199f624
BLAKE2b-256 checksum
How to use checksums
c7b96fe216006f38faa92175e50773ea96f816e071955c0bd249542b4dcc27fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","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.7-cp310-abi3-win_amd64.whl

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

Download URL torchfont-0.13.7-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
d556af91a2ebb580ebbe406fac01ea967d473f6aa165d258b324c52f5c9d603b
BLAKE2b-256 checksum
How to use checksums
fc14105eae49564e0ba7f7dee1548d30a742774902a9a4d93e227f594d92c7fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","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.7-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL torchfont-0.13.7-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
ddca3e6b3ddc55450389797f4d5912020ae84f49119546846231afd3e1e9c1e7
BLAKE2b-256 checksum
How to use checksums
0b5792c2c7025a997a746c3d6746cf21526e39fdc8ad1875dcd39939bf55a435
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","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.7-cp310-abi3-macosx_11_0_arm64.whl

Download URL torchfont-0.13.7-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
7e55c9b46b1a6ea2ac00ecfb90a6c9a32514c3d9bf2baa408c391550b096296a
BLAKE2b-256 checksum
How to use checksums
fe6f2a6b4c252e671bf35ed79e2a9b7633ded3a3eed1b5242ec28dc633d1ae6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","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.7 This release

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