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

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.13
File Size Uploaded Provenance Actions
torchfont-0.13.13.tar.gz 3.2 MB Without provenance Details for torchfont-0.13.13.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for torchfont 0.13.13
File Actions
torchfont-0.13.13-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details for torchfont-0.13.13-cp314-cp314t-win_amd64.whl
torchfont-0.13.13-cp314-cp314t-manylinux_2_35_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.35+ ARM64 Details for torchfont-0.13.13-cp314-cp314t-manylinux_2_35_aarch64.whl
torchfont-0.13.13-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 Details for torchfont-0.13.13-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
torchfont-0.13.13-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details for torchfont-0.13.13-cp314-cp314t-macosx_11_0_arm64.whl
torchfont-0.13.13-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for torchfont-0.13.13-cp310-abi3-win_amd64.whl
torchfont-0.13.13-cp310-abi3-manylinux_2_35_aarch64.whl CPython 3.10 abi3 Linux glibc 2.35+ ARM64 Details for torchfont-0.13.13-cp310-abi3-manylinux_2_35_aarch64.whl
torchfont-0.13.13-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for torchfont-0.13.13-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
torchfont-0.13.13-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for torchfont-0.13.13-cp310-abi3-macosx_11_0_arm64.whl

Total release size: 27.5 MB

Release files / torchfont-0.13.13.tar.gz

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

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

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

Download URL torchfont-0.13.13-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_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
cce752a7deddb8217633f56e676c331b77306f7bf156e49127591b102b8dca5d
BLAKE2b-256 checksum
How to use checksums
455b5fdf045c3d49061d0fe3888bb3683a6a579d44d5829adb3edcb1a6fddcc7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","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.13-cp314-cp314t-macosx_11_0_arm64.whl

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

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

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

Download URL torchfont-0.13.13-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_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
68ed2bf245018af65be80ed88d69c0c47ce06c4e10b45948c34764b5ed27aeae
BLAKE2b-256 checksum
How to use checksums
e7419c982ad43fa83648f65ba7de7c1eca6bb513239f4e510df29b8a83d0813a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","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.13-cp310-abi3-macosx_11_0_arm64.whl

Download URL torchfont-0.13.13-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
9fb05ae0ac687723b080f40ac56fe0af37908103bb51f544f2365886436466ff
BLAKE2b-256 checksum
How to use checksums
031251e859007876d5adbc6cacfc707896d349d9f44d3e386870e6dca5339dcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","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}

Security for torchfont 0.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.13.13 This release

9 release files No provenance

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