Skip to main content

TorchFont logo

TorchFont: A Machine Learning Library for Vector Fonts

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

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

Built distributions (wheels)

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

Total release size: 27.5 MB

Release files / torchfont-0.13.9.tar.gz

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

Download URL torchfont-0.13.9-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
89e49ab22f12d600f6f492414fb9d4c43b5d12e38ad148d30e0a46e4ac2c5cf7
BLAKE2b-256 checksum
How to use checksums
66297106efb9cdcce0e86caec343de5ef63717a1df1741835408b5621ef1b511
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","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.9-cp314-cp314t-manylinux_2_35_aarch64.whl

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

Download URL torchfont-0.13.9-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
11a5443d95f1bffd63e7182de8f8ef97242826931cf88ae59a3d8956f4355e34
BLAKE2b-256 checksum
How to use checksums
018f680e6a15b4f7fcb882db327cd138cf29fcd8fdcad4ffc8356c97f5ea4321
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","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.9-cp314-cp314t-macosx_11_0_arm64.whl

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

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

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

Download URL torchfont-0.13.9-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
36b2ff15a99e9d94afb0fde205d9bf8f5b6538b7db176872129f0dbe0dabaa88
BLAKE2b-256 checksum
How to use checksums
6a40521f6d9a281410fe95e6849349f57e1305eca8b07e7d47a45dd819a78775
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","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.9-cp310-abi3-macosx_11_0_arm64.whl

Download URL torchfont-0.13.9-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
b2cd2a8e59dec4c535abe604cdddbbd7a63ee57c04912247ccfb4db58a8aa1f7
BLAKE2b-256 checksum
How to use checksums
f109755cfd6f59c1711864eb1cc6173d39e46f5baed9f8e427626cd45ba6acb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","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

This release

0.13.9 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