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

Uploaded CPython 3.14tWindows ARM64

torchfont-0.9.4-cp314-cp314t-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.14tWindows x86-64

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

Uploaded CPython 3.14tmanylinux: glibc 2.35+ ARM64

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

Uploaded CPython 3.14tmacOS 11.0+ ARM64

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

Uploaded CPython 3.14tmacOS 10.12+ x86-64

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

Uploaded CPython 3.10+Windows ARM64

torchfont-0.9.4-cp310-abi3-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+manylinux: glibc 2.35+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

torchfont-0.9.4-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.4.tar.gz.

File metadata

  • Download URL: torchfont-0.9.4.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.4.tar.gz
Algorithm Hash digest
SHA256 5347602f74c102b9cf15c193ebb86c1e63a71e92bdda3447f3cc1d8c21dce554
MD5 e4f083f48ed79e4af894a44c586fbcc2
BLAKE2b-256 0ed9260c7d464c4228046dde4ea4524cd2a90f5261ebb7ee7b7f40781f869adb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.4-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.4-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 c5b37e9f18768a20df4e92958495baa3aff6cbbc7a7c45ea21fefa7cecbbe3ea
MD5 d2f3f0d3b5a4e5d5a6e7ed64f1195ec0
BLAKE2b-256 27fbf5670a9d19b0a7faa32effefae1e0fdff43c8cabc34994b9ad7faec8c349

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.4-cp314-cp314t-win_amd64.whl
  • Upload date:
  • Size: 2.6 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.4-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 5d09c02455c4ca71e4e42802a8b426d040a6827f92dfae4db316999ed3a997ad
MD5 be51d1eb4822ee39a1329895fc57eb39
BLAKE2b-256 1f1da21f84a5930fdabaa80bca5a9737d2ece6088274984ed43f140c1dbe47f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.4-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.4-cp314-cp314t-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 5e1d7a213df82782fb98197cdef7f9055458651d86510945a5093812e4ba9017
MD5 d9c0a0d181cf6a0ffd10fc13b75c21fd
BLAKE2b-256 22c38c6779b7e69c9f633dc84fbb5be4f22f2527e6fd095ac99063b5bfd1fb1c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.4-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.4-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3d6e0c7f1042e4706a4c54a46e96b29f2bfca545d5e32d704c8812a968629e06
MD5 10ece42528d16bee762f57321a2c1ebc
BLAKE2b-256 df19d481dd3669dac509eacfd98bfae89f1fbac06c98d37e3e90e1438cb8202a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.4-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.4-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 16b1ad8146b2c3552844dffaabf2f693b2cd01b44f3d3c662630bc45eaef5290
MD5 950390f8610228ba9e5e339e446c5d6b
BLAKE2b-256 f211873229ec81030de601db21f1f1fc0ed821bb370fe8041421a99715b355c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.4-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.4-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4082b473d37c411bed4e597de1d138149bdaf0aa48bba16ebfa69d7ca1026872
MD5 6ddeca75ff0d1314e176c61de5bb4bd5
BLAKE2b-256 1e6eb0f8ad831570b4b1271442dd88f80c1264b7d0919950aaf0f63af93cd2ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.4-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.4-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 6a0e99448953a51c1a4c64191f0bee3f2f64eeb1fae8779834f499d13889e50c
MD5 5e0782587335e66cab85761cbc3ea45d
BLAKE2b-256 907199800ef21b0df0705ae23d83fd091ba8bf984c9e49c0c0d7f705d51ccf46

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.4-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.6 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.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ccf6b62300775b4d585d4a288f4fda594919b837f28a6e79a57521a3a36e5a15
MD5 62d22838a5f9e21e6c2dcb44102f1a67
BLAKE2b-256 4d35f9ad4efb9cc9737a1a1064c7aa3e94cf9300721bea26572796e02a4d7983

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.4-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.4-cp310-abi3-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 462e70adf80be72c790374f3210633bb8b3a18c0e7637b20770975cdf31bfe4e
MD5 c03755126b90a25d5bdd63b5651a1b5e
BLAKE2b-256 9d6c19ed990bc5eeb94371e136b5f3dfc3ac4bfe015cd09ddb28665c6e4862f0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.4-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.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2513920390db79994ceb13cd0e21d9c7cb0986fa1c3774c3a70aeba4b1bb2898
MD5 99c30092dd4d1c2ff1d4ce6d437a0ba6
BLAKE2b-256 3b68289cdc4a5c4b4077d133b002d92440eee053b0980ee7b8c676d1350e1c6e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.4-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.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c9b75a34850853f24de64247fd36ee2d928f6c50417bbc5b6013b2d6b4ab4aa9
MD5 970c73f1456ddeb7b8ef34dc3594b2cc
BLAKE2b-256 be4ce7aeb61d080dbd82572fd449ef4916e01ee415302f771ccb15d5b26ff283

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.4-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.4-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f52da052d58ab9164eb10f549a9ece3be90d8471bc2e87a0aa96a08da517e74d
MD5 ee1275e64492cabfbddf96c1a638e1dd
BLAKE2b-256 33e0b1889e1cdd28e252338dd22890237c5c7d25e9a9327eae25ae658f26b43f

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