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

Uploaded CPython 3.14tWindows ARM64

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

Uploaded CPython 3.14tWindows x86-64

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

Uploaded CPython 3.14tmanylinux: glibc 2.35+ ARM64

torchfont-0.10.0-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.10.0-cp314-cp314t-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

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

Uploaded CPython 3.14tmacOS 10.12+ x86-64

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

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+manylinux: glibc 2.35+ ARM64

torchfont-0.10.0-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.10.0-cp310-abi3-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

torchfont-0.10.0-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.10.0.tar.gz.

File metadata

  • Download URL: torchfont-0.10.0.tar.gz
  • Upload date:
  • Size: 7.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0.tar.gz
Algorithm Hash digest
SHA256 55e1be8ebfdbe2c7c756459b513138cd95ce6c7afa20a300df5b774591080764
MD5 b137067d2dbaedc5beca8ddd3495493e
BLAKE2b-256 e5a7fd43d5ab67045a49ed93ea2266b125607a2389154da695d5c2dfb60b3d7a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.0-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.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 99879dbb186f7cc9740aca881d67fdcd73c498dd6baa3cee11cbda68e82db3a4
MD5 2c2d339d5e7243a55907b95c1516bce4
BLAKE2b-256 86a0df1759919884f26cd181e419d59f0d549f26362001fb5a35483885321da0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.0-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.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 8c655bf34bf18c28df192fb0653eeefc9456b671d1ac71b76eac2cd03c36761c
MD5 a7c8874b1defaa4d6c771008206537b1
BLAKE2b-256 5addbf04bb6a5b3449f7a9e28cce6c1cc792677eec64b1690d71f87d84313dee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.0-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.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0-cp314-cp314t-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 22427927d1eb00c6bdda0a58895f3ef2d2142bd236453bfb11b14ce89eb1dbcf
MD5 bb16e420bb7c744653d41ddeb2cc24ff
BLAKE2b-256 b2148646c102125ad716ce2f55ef5722755d41e660d624a64813ef0b0d6fee40

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.0-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.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d721e03ad724b15d64803be0d81debf4a7e997ca40cd2e18d98667ea6e16a5b2
MD5 83fc19845c795ebdb75d8d3076990238
BLAKE2b-256 cd66bd15b38651821b171ca6f19ad364d127bb4b322a4ea80a8639146f69a24d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.0-cp314-cp314t-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.14t, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 67db844c2a93bfc35ecc5c92c9ad35a809fd0cd89192924cf95a052ec0008233
MD5 1e79ce1145c31f1df5fdf93bc5d2916a
BLAKE2b-256 0726ad807ab6652954b1798b73b3d2b799e16be0184047bd6b925b51b940cab7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.0-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.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 45575a386372c69e2aea47f4ec4f33d3e853b19811e57e31f9dcff6066fe13c2
MD5 e0d5999ad237a366a1cbe3c89fd2fc24
BLAKE2b-256 af685b40559098647bd37fb15058488dfa9402e293b3818c5e47e4b2f23993e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.0-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.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 f18dbde11166f4ca34ffbd2e4908d716e7367ca2f9a280db3273e125c8398e47
MD5 624ad73799c86b4ad5afe206201254db
BLAKE2b-256 cbcc4e72303bd580fbaf5bebce8ff25c7d57fd355a310c9a76e6b52838580871

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.0-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.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c16a305c0a6bc9d9a27337f231477f0e26f731b5e66521988e624b6c781a672a
MD5 a173d147f1ceaefe6a72a1b0c08c8fc0
BLAKE2b-256 e2d15ee17792e670c3fceb66eefe2f31746f6449b0c206b3249d2bd73de52497

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.0-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.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0-cp310-abi3-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 f1bb2c069f2734041804cdffa609a83083f0e6355082d71dbdec2fd2523395c3
MD5 c7c97810f6de570375267b587635527f
BLAKE2b-256 f932ade11783f255e19d7698e2899386567d09cf896df07819200b86e5c6b5a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.0-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.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 45210991d490b9d0371c2c65359d0d21994b7db50b3d0ba107d8943343172679
MD5 895cf0e113c36921f5d45f630ec2d4ae
BLAKE2b-256 ef7516d14d706436c09df4bd93bb172942b611e497b20eecfc95b2dc3b93b225

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.0-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 697997bd489ba2b3b8c7f2b836e6557721536ad171986f6d852e6cd424a3cd81
MD5 3799c9af7c02183ab82eacddcd1eb2c7
BLAKE2b-256 8e51e56ac67e5fe21c7119fabcb5217dc90d23954045c036209ff485975149f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.0-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.16 {"installer":{"name":"uv","version":"0.11.16","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.10.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 79543366dbdb5725bc051ef5d5e6a935b2709546363b883bb4d6e1797fa62c1c
MD5 7269f02f42f748f53d69b7ed7beea046
BLAKE2b-256 4474dd453489f1a72a2eef754d291fff9acdbefd36d66b344b7fe3d41c2dbf24

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