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

Uploaded CPython 3.14tWindows ARM64

torchfont-0.10.1-cp314-cp314t-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.14tWindows x86-64

torchfont-0.10.1-cp314-cp314t-manylinux_2_35_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.35+ ARM64

torchfont-0.10.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

torchfont-0.10.1-cp314-cp314t-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

torchfont-0.10.1-cp314-cp314t-macosx_10_12_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.14tmacOS 10.12+ x86-64

torchfont-0.10.1-cp310-abi3-win_arm64.whl (2.5 MB view details)

Uploaded CPython 3.10+Windows ARM64

torchfont-0.10.1-cp310-abi3-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.10+Windows x86-64

torchfont-0.10.1-cp310-abi3-manylinux_2_35_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.35+ ARM64

torchfont-0.10.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

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

torchfont-0.10.1-cp310-abi3-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

torchfont-0.10.1-cp310-abi3-macosx_10_12_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: torchfont-0.10.1.tar.gz
  • Upload date:
  • Size: 7.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1.tar.gz
Algorithm Hash digest
SHA256 3db8ce585b8f5fc7b03d5ef92a9175100f88465490c4092c00021945761b915c
MD5 826a90b06480951763717a7d15376079
BLAKE2b-256 8571264b1c24e5957696345e26b8c4170475f08e957b1f04ac2ce6d072749138

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.1-cp314-cp314t-win_arm64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.14t, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 f6a40335284bbddcdced2722926312c11eb39e5867724c55eb5c5e6821d31c1b
MD5 62bce9cb29e66666b38352e7871fabe0
BLAKE2b-256 82caf62f174a137d590685588682101194a4b75ed7c656dd2f2957e5fc9e83d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.1-cp314-cp314t-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.14t, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 f2a76f47a209c0dfcec775717d80e9c7550c3427601646cb6ac1614408f11083
MD5 639cb40835fee6870fa632ec8dcf67b0
BLAKE2b-256 797c698e4da84e869042c8eabb58bc1ecc523b648cdd70cdc92fd06b4cf60fac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.1-cp314-cp314t-manylinux_2_35_aarch64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.14t, manylinux: glibc 2.35+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1-cp314-cp314t-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 a97b19383cf88b7be56a764d385605880107b5b8c7e43c8cb2fd9b6f0421691a
MD5 e52dea96af78f741b9241a8a32e201f6
BLAKE2b-256 39d70202060088e344be243fef1eafed109a8a6965fffc47754cc0591a60f1ca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.14t, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9625c989eff971a1564edaeedd5bfee25764809c6de905c15cd1875e375949ad
MD5 98de979bf677d9d51b3def8849f3fdb8
BLAKE2b-256 04ea4bf4d0da52a78e7c475b9802a9beae4586ff0cd6d2c6743c6d28ef87efb5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.1-cp314-cp314t-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.14t, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2ab504da5a937c7543868f3a9bd7b39cb54b715959709d2748de1396602c221f
MD5 121230ba28b838d1cf51425bc634dfd2
BLAKE2b-256 fd5d5003a2e6b95ee382da3a5bcf7dd41e4eed4eadea908f18204717d0e0e511

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.1-cp314-cp314t-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.14t, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7c8d9999f35a7e5779775644716d978f6d3868d139f7f26804ea57f8eb6fcb76
MD5 82db67405d0e7c2118559f6fc358b3bf
BLAKE2b-256 18325aaeb0732f493b2a919309bc77dcc12605c43f7d8a405cb042ee7e8d84f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.1-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.10+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 c34977e07105de3f8da664ca1e7585a724786d7168eb33f54efb867f94c6aac2
MD5 fbfe4c02e88c0623cd23de5a31b62c5c
BLAKE2b-256 ef91f1b58580ed2ca5a335f04d0330fb7d29a43891ccf39322ef0e03719ae2d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 797a1a164c8183381b6ddaf54adf53b262c9fa41112c74694b3d06baa9ec88a4
MD5 06669d7c621c394afd8896c4c5f029da
BLAKE2b-256 876bba7c3a076a3f9d99778e7ce4ba6cc0218da519fcba0084e7b9c0c808f7d6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.1-cp310-abi3-manylinux_2_35_aarch64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.35+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1-cp310-abi3-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 0351f0e3d4ea3b96aa6874cde0525413148b82fbba1449d086bcd253a2d567ce
MD5 88b970e80fac2c52812e89df01c0f9f3
BLAKE2b-256 80b8283694fbdc386a60c9f6c6981b5c80973e2981cdf53ddc333ceccf92ddfc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 553b0bae00a6e50480ad5b2092fda50199e03d2451220ad625c5f73e8feffadb
MD5 b0decba5f438aa5d323b1bfc11efd3c3
BLAKE2b-256 7771c3f8193269acfa4d6d6636bf4977fa5c0b67419725432260c066f03dea47

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.1-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7fcb206808238aee23882ee508c0566798be0fff179e11e96db961fbff8a0990
MD5 7407fc7f8aa02fdc57faa72bcdb90b6a
BLAKE2b-256 e845bafb5ecca084e96fa65bdc8450f13811a7775760f353652b2a9d6c63f83d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.1-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 be6ed4aa3b166b8883b7ffc0eb079d14b06fc1ae751aac131b9015e6d9d4d02c
MD5 bc0140ec2e1df925b829ddf4d58d7138
BLAKE2b-256 3e9870d7690f2cbe7d2878de544691004dbc7f84f61c87b6bf3f1a648b0e7aee

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