Skip to main content

Datasets, Transforms and Models specific to Vector Fonts

Project description

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 glyph outlines into GlyphSample objects for PyTorch pipelines.

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


def transform(sample: GlyphSample):
    return sample.types, sample.coords


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 outline decoding into GlyphSample with outline tensors, metrics, and glyph name
  • 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,
    title        = {TorchFont: A Machine Learning library for Vector Fonts},
    author       = {Takumu Fujioka},
    year         = 2025,
    journal      = {GitHub repository},
    publisher    = {GitHub},
    howpublished = {\url{https://github.com/torchfont/torchfont}}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchfont-0.9.5.tar.gz (7.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

torchfont-0.9.5-cp314-cp314t-win_arm64.whl (2.4 MB view details)

Uploaded CPython 3.14tWindows ARM64

torchfont-0.9.5-cp314-cp314t-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.14tWindows x86-64

torchfont-0.9.5-cp314-cp314t-manylinux_2_35_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.35+ ARM64

torchfont-0.9.5-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

torchfont-0.9.5-cp314-cp314t-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

torchfont-0.9.5-cp314-cp314t-macosx_10_12_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.14tmacOS 10.12+ x86-64

torchfont-0.9.5-cp310-abi3-win_arm64.whl (2.4 MB view details)

Uploaded CPython 3.10+Windows ARM64

torchfont-0.9.5-cp310-abi3-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.10+Windows x86-64

torchfont-0.9.5-cp310-abi3-manylinux_2_35_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.35+ ARM64

torchfont-0.9.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

torchfont-0.9.5-cp310-abi3-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

torchfont-0.9.5-cp310-abi3-macosx_10_12_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file torchfont-0.9.5.tar.gz.

File metadata

  • Download URL: torchfont-0.9.5.tar.gz
  • Upload date:
  • Size: 7.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5.tar.gz
Algorithm Hash digest
SHA256 4d27bb77c22fcc1f2dd8bcaec1898ffce6e79cf28a0c1c7c7b82312a30e64ec4
MD5 fb0311fa86ee818242e7d4e48af44642
BLAKE2b-256 e27b7c0fb32fe3e56db2fc4a79870849a48245268fb40f9815d283925cf74f19

See more details on using hashes here.

File details

Details for the file torchfont-0.9.5-cp314-cp314t-win_arm64.whl.

File metadata

  • Download URL: torchfont-0.9.5-cp314-cp314t-win_arm64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.14t, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 0783a107860e896a5894151689704ec65fa1cdab043a491de96f7150fbf9502f
MD5 62b9bff92b11beef0e40aae87c57ecd2
BLAKE2b-256 80a0fa3e5a2eb724059531744b14412a9711dd3ac627102feb4c0ca9cffb62b0

See more details on using hashes here.

File details

Details for the file torchfont-0.9.5-cp314-cp314t-win_amd64.whl.

File metadata

  • Download URL: torchfont-0.9.5-cp314-cp314t-win_amd64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.14t, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 3e274d97ab24dd425c86c10c0fd9a8d2a1d759dec02ea2821ded251d7c702ff3
MD5 960a9fb982ff1df4addf5e983e96edb6
BLAKE2b-256 5e3cfd57cbd6941e4079e0d4c8ca6ec683061eba57c378d2f136da4c7d499881

See more details on using hashes here.

File details

Details for the file torchfont-0.9.5-cp314-cp314t-manylinux_2_35_aarch64.whl.

File metadata

  • Download URL: torchfont-0.9.5-cp314-cp314t-manylinux_2_35_aarch64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.14t, manylinux: glibc 2.35+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5-cp314-cp314t-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 730095b1d99dac78ddd410626074a60fdfddc3c518305deb5fb0248504f65d68
MD5 2a89361f6bf99cd9dbb341d72b46f892
BLAKE2b-256 7988ee243d9eec307cf1366dee8a76a6f7f3e5901e289349f2678f99213eb2e9

See more details on using hashes here.

File details

Details for the file torchfont-0.9.5-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: torchfont-0.9.5-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.14t, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fa41fd0d38deaa5ba0088d1d29c8e2957c923249ac6174d3bcac95751e830834
MD5 0896509d7438d571870506e919ec7712
BLAKE2b-256 971294f6325bf6dfd69a620c345086df424ca9b8e44eb46c86e4f7b14158e7b3

See more details on using hashes here.

File details

Details for the file torchfont-0.9.5-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

  • Download URL: torchfont-0.9.5-cp314-cp314t-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.14t, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ce330cb4f77368a9d8d125aa345cc19505a75dc8a055ff38ec2ed962be545054
MD5 b022814653646a3c611ff7688363745d
BLAKE2b-256 d6b25c3c29a81661a5d4516df04af7d4930c9bc8890f4efb4b1abecd0a76bebc

See more details on using hashes here.

File details

Details for the file torchfont-0.9.5-cp314-cp314t-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: torchfont-0.9.5-cp314-cp314t-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.14t, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 41a1a476b2435a47352c578d05dbabaacbe91186357250a3ac49fce94c280632
MD5 57e21fa87505004f4c94dbdfe7a8189f
BLAKE2b-256 f35a8a5f63ec16f27c4e451e83b52f24aed09f3d775950c835a2426c480a88d6

See more details on using hashes here.

File details

Details for the file torchfont-0.9.5-cp310-abi3-win_arm64.whl.

File metadata

  • Download URL: torchfont-0.9.5-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.10+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 3f6a4ef48f5ff95c543dd882ae363599b2ccc037f973a2859200b57770d75b20
MD5 7f75818a7d8e4e20586a102ac27b3644
BLAKE2b-256 a3052e19190b140a205d119f845edac1ff0ce80c28d8bd1a4aba020b388c9d2c

See more details on using hashes here.

File details

Details for the file torchfont-0.9.5-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: torchfont-0.9.5-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 306fa1a14696a12fddc908fefe758f48cfa7deb8ddfc3c5cb85797b5b4257d42
MD5 be452027987425925b42ce3e974f6bd3
BLAKE2b-256 7744326c335f879680090fb6738752ffd93090df9fa8e11044444ff521afc6a7

See more details on using hashes here.

File details

Details for the file torchfont-0.9.5-cp310-abi3-manylinux_2_35_aarch64.whl.

File metadata

  • Download URL: torchfont-0.9.5-cp310-abi3-manylinux_2_35_aarch64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.35+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5-cp310-abi3-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 6a92e792c1d0fe588c3e08fabcdb137a7cf828f803a2318df37510ec99636239
MD5 62912c37f624074a8a037ea7dd8f75d9
BLAKE2b-256 49e4b5cf8cfa5bb7ec28bbf8306bb51edd7e10b47e98baf580fca7b3a02edb3d

See more details on using hashes here.

File details

Details for the file torchfont-0.9.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: torchfont-0.9.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 94a80a12dc0a0bf5ba22812de229f6c9bdb2e8f71c27ae63c96edec83ef0df26
MD5 801e7ee59989d06de96e74483be383e1
BLAKE2b-256 f858e6d9cdd85dda6db7ab360f4c7b4859fd8e92ba3ab165dd367f82e0a53b15

See more details on using hashes here.

File details

Details for the file torchfont-0.9.5-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: torchfont-0.9.5-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 94d6f7c8f41a4e7bd96a7fa454c1f6bc567c91d3466d90a7b31f306fd2428920
MD5 887530ba5e71c927e89c1e7f8075047c
BLAKE2b-256 76fe5366b409a40f929825d135e96d065af8345ec7608aa3964674e43015055a

See more details on using hashes here.

File details

Details for the file torchfont-0.9.5-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: torchfont-0.9.5-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}

File hashes

Hashes for torchfont-0.9.5-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 72a434f82a9c20a416dece172de20a4af4b786f03b8b25dd1fb66c382628e4c6
MD5 7c79743762c10654bdccd98f948de31f
BLAKE2b-256 c2b4d76fd83263c6240f18eccf9d3726405868936431fd2b159f0b0f683ca5d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page