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.6.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.6-cp314-cp314t-win_arm64.whl (2.4 MB view details)

Uploaded CPython 3.14tWindows ARM64

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

Uploaded CPython 3.14tWindows x86-64

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

Uploaded CPython 3.14tmanylinux: glibc 2.35+ ARM64

torchfont-0.9.6-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.6-cp314-cp314t-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

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

Uploaded CPython 3.14tmacOS 10.12+ x86-64

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

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+manylinux: glibc 2.35+ ARM64

torchfont-0.9.6-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.6-cp310-abi3-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

torchfont-0.9.6-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.6.tar.gz.

File metadata

  • Download URL: torchfont-0.9.6.tar.gz
  • Upload date:
  • Size: 7.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","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.6.tar.gz
Algorithm Hash digest
SHA256 5771a02928704ce61cde88001b1907ff826a88fd75683a7944698f83a0334ab5
MD5 e586ce54c55f7e753185d151b93f90f8
BLAKE2b-256 4957f6725a09035559dd9fb7d806017aaa870ec8724cf4e8bd440c4f833cd7cd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.6-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.15 {"installer":{"name":"uv","version":"0.11.15","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.6-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 ed9dc76819ee6909d796e42e30152b0e5c47dbe8198ef8863c3f0a0a26703cfc
MD5 14dfff2e1f930c4da0daf09b233caaca
BLAKE2b-256 ad655bc82a1e4062b8e4a23387e77b3df2949ecb1bcfc5ca2011aad0fd86c4de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.6-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.15 {"installer":{"name":"uv","version":"0.11.15","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.6-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 5139307f96b4b593366eafee532c0631f7fd9b27d48a4521f741fc69a59f52e2
MD5 d3f82a7177bbbf4ccb7dab09bcd9b77c
BLAKE2b-256 3b0e57be1e73ac677e2c18bba241ef3a2703dd381825916caa79fd092d8039a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.6-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.15 {"installer":{"name":"uv","version":"0.11.15","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.6-cp314-cp314t-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 6ca555195c3933d04031a8c5f9e8a4c20ea9cf0e15a3b26d09a12df11827dc42
MD5 e150f335a2caed780b75c39bc9517956
BLAKE2b-256 7b1d48ebaa5dfcc622e0d8bbc0d0312bf8f76777fb19dcdebe758eb9e00a489b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.6-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.15 {"installer":{"name":"uv","version":"0.11.15","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.6-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a478956055d21cd12b656319834061e0604691f5646760c9a3a62dcfa917de07
MD5 a19bb9b688cf1f93552bc573d5b4f782
BLAKE2b-256 1bf33f900712c99a5a2ddcce6db69677365b8a2ea4aa390f2159961b3ca95880

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.6-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.15 {"installer":{"name":"uv","version":"0.11.15","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.6-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e25fc5af208244103a3a3658ff1ba074bd37c722216eca4ca6d0b88eb6c38027
MD5 dad65e030de2fcb0b204c5a0eb1a7ce7
BLAKE2b-256 199b6ccd216a15046196d9a5788d66bf7a32767b679cf4a75f3115466b1c8054

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.6-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.15 {"installer":{"name":"uv","version":"0.11.15","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.6-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6dd4b16ae8c93f2e66fa4deed8631d9f4b2fd176b94dd3f84feedafdbed27024
MD5 aa4dd96ccc9c6d636a17786f36eb20de
BLAKE2b-256 85640799bdbea0ec50bf23ad70b04c3bfdf1071215487ab3122f441cf4a2fbda

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.6-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.15 {"installer":{"name":"uv","version":"0.11.15","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.6-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 2f1c563d81d1c28698fc17158f0e300f5be9e3c580cb7ec7c3ecc240fc03897e
MD5 4e9a6f2284e2f0193297b9944679c231
BLAKE2b-256 ce68efc1f47b26ab49aeefc41ac958a3f772d76909066349b8d826abc3ecb0e1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.6-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.15 {"installer":{"name":"uv","version":"0.11.15","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.6-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ef9cf89078fdaa9f760cfc00ea584ba377ac5beb0d580152b930c6ae260d4c1b
MD5 ea4aaf117114e77e3e6f3697dcabe2a2
BLAKE2b-256 7359d18c2d8ab4f0e915113fca18939a66835ace82da524e1d0947986b2089fb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.6-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.15 {"installer":{"name":"uv","version":"0.11.15","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.6-cp310-abi3-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 8633aec276f1c65d7dc06233f0dc95ff8f88fdd17356ae078a306be66403323f
MD5 31d196703a8ae1bd7bd6652db8b97674
BLAKE2b-256 3ae80f7615657627c000d225336c8e4243faf4bda9fae04b7cdff53162eca62d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.6-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.15 {"installer":{"name":"uv","version":"0.11.15","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.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a02bf657f9f53694e085ae513fe3a8b0d80b7f228f22ccafa9de63574e1905fa
MD5 ad1aa026900caebea581dbe1706efd20
BLAKE2b-256 ac9b91d6989e1e70dcf75e9be757ed8117e77ab339b8703acea5cb3cc8e978fe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.6-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.15 {"installer":{"name":"uv","version":"0.11.15","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.6-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 38aa76b4862c5575c2d62e70eded34c33a22a18236f5e271faf1ee2a40381100
MD5 ee17cf97447e6b8e8e04bee29a68bc66
BLAKE2b-256 5717ce01e1be1f8702b792cf366720e90ebf16a816be98a90a7ca925744c480b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.6-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.15 {"installer":{"name":"uv","version":"0.11.15","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.6-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b99990111e6de390d913296f00a0c71855b86ff5cd36954d4bd4bcbc547ffde0
MD5 bd08bd438d1f3e56998030d5a9281664
BLAKE2b-256 4d4326cf8f55575a767b8a07f14e9af0fafd45f319312a2bd430a7e1cf5e3816

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