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 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_cubic for adapting glyph samples
  • PyTorch DataLoader integration through ordinary user-defined collate_fn functions

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

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.11.0
File Size Uploaded
torchfont-0.11.0.tar.gz 7.2 MB Details

Built distributions (wheels)

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

Total release size: 34.2 MB

Release files / torchfont-0.11.0.tar.gz

Download URL torchfont-0.11.0.tar.gz
Size 7.2 MB
Tags Source
SHA-256 checksum
How to use checksums
56616376c135b30c824222d027f38c66ceccf145f232cf12cb9c3ca389aecb5b
BLAKE2b-256 checksum
How to use checksums
ddcdb0ba9f212a790614f654af79998cdfa8c8924b8b2833ba1ea59ef0d5ab99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.0-cp314-cp314t-win_arm64.whl

Download URL torchfont-0.11.0-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
6050da43c158b9ed07ccec8cdc67ee783ac4b4ccc92d8d707f5abc532cee65bf
BLAKE2b-256 checksum
How to use checksums
1abfd29c9ef09286ddad1cac11a29005ea95a06bc0df6405090e50755cf8fde8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.0-cp314-cp314t-win_amd64.whl

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

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

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

Download URL torchfont-0.11.0-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
a6b781e6e7692d618e4502a8b454e401303e588028d11f666192d8c6cef726e6
BLAKE2b-256 checksum
How to use checksums
ea8b92eb93678e9def8af8cfdbf676c5a587faf9edc1b4f92343a4f2d938d84c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.0-cp314-cp314t-macosx_10_12_x86_64.whl

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

Download URL torchfont-0.11.0-cp310-abi3-win_arm64.whl
Size 2.7 MB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
df9a67f5fc004c4e90be9a3aa11c0ba5bbb7c8dd71fac6c61afcfc227c2f1965
BLAKE2b-256 checksum
How to use checksums
7058e648d079d0eaf0399ee067ac9543749f340320e4de1eca87c0e3895afe6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.0-cp310-abi3-win_amd64.whl

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

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

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

Download URL torchfont-0.11.0-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
7795587371cd629e5ce57948b097d30e9259cdeeb9c366083531793491f98622
BLAKE2b-256 checksum
How to use checksums
127b03c5991e11578b361ba040e647ce3ce0c866bd361647468c610912314783
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.0-cp310-abi3-macosx_10_12_x86_64.whl

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

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

This release

0.11.0 This release

13 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