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 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 DataLoader integration through an explicit, customizable collate_fn

Manage font repository synchronization 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.12.4

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

Built distributions (wheels)

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

Total release size: 30.2 MB

Release files / torchfont-0.12.4.tar.gz

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

Download URL torchfont-0.12.4-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
1eaba27d5bd77f08367f70f2eb122871fc5be26ccb512ac5e035301b541a2ffc
BLAKE2b-256 checksum
How to use checksums
100bdd84bb3cca7eb904161b0faab78601fcc14e5c34cce555977a3c31744105
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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.4-cp314-cp314t-win_amd64.whl

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

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

Download URL torchfont-0.12.4-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
2908c796bd1227b15b8154a61699b2fad15457df10fd61be246f804eb351283a
BLAKE2b-256 checksum
How to use checksums
337a8866e06e5ea1e71ad8f7b125481b59cc202f9b6e107e55bf415b7f660913
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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.4-cp314-cp314t-macosx_11_0_arm64.whl

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

Download URL torchfont-0.12.4-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
ff48556fa4b866a5269284438a78657d1f9a2e9aa798cd48e87aa48e1dc4ead9
BLAKE2b-256 checksum
How to use checksums
013a731142eb2b830e93e0bee9ee73f90816f8540cc4876de304bc59ba2cb633
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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.4-cp310-abi3-win_arm64.whl

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

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

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

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

Download URL torchfont-0.12.4-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
645d46a489826b17b186bda177d1e042b79ea61a1c43b69c7e8dbc445d9a474d
BLAKE2b-256 checksum
How to use checksums
49d1b10906d8c882d130546be3e0a85b88feff7077244fe5e59dc6f343d0c270
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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.4-cp310-abi3-macosx_10_12_x86_64.whl

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