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.3.tar.gz (7.1 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.3-cp314-cp314t-win_arm64.whl (2.4 MB view details)

Uploaded CPython 3.14tWindows ARM64

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

Uploaded CPython 3.14tWindows x86-64

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

Uploaded CPython 3.14tmanylinux: glibc 2.35+ ARM64

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

Uploaded CPython 3.14tmacOS 11.0+ ARM64

torchfont-0.9.3-cp314-cp314t-macosx_10_12_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.14tmacOS 10.12+ x86-64

torchfont-0.9.3-cp38-abi3-win_arm64.whl (2.4 MB view details)

Uploaded CPython 3.8+Windows ARM64

torchfont-0.9.3-cp38-abi3-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.8+Windows x86-64

torchfont-0.9.3-cp38-abi3-manylinux_2_35_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.35+ ARM64

torchfont-0.9.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

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

torchfont-0.9.3-cp38-abi3-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

torchfont-0.9.3-cp38-abi3-macosx_10_12_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: torchfont-0.9.3.tar.gz
  • Upload date:
  • Size: 7.1 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.3.tar.gz
Algorithm Hash digest
SHA256 57384ec55a678183d5963e9a655d5f92d5e5695fb2117fdcf7aae05e8703e1a0
MD5 2a58638d275a8b959387e031eb37b5e6
BLAKE2b-256 4b1ca2ddeaaee37a9121b5c03c0976b7e2c535d7de5d36277525636cffba39dc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.3-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.3-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 e7f0a371896ce37a25db9a6fbe3eecb162d7369134274e7d63b19926a1eeab68
MD5 ccbb73d4cddd91a901215df2965d3be1
BLAKE2b-256 9b93d0da9d87f8150d7b0bd729dffca504612581a571a4549f68f53348e5d671

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.3-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.3-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 28d763323106b8ad0a261535a6657d643df072012d589185d7048712a8dcd1f3
MD5 9b9ab444f0a90f3cdfc84d25c9bbb3e4
BLAKE2b-256 f0f420403d0c9bbfd9923d7d152f47251b434c2a0fe99eff331ff3cff3629885

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.3-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.3-cp314-cp314t-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 af70535dce6b3f7736c350676aba4f921117794fef9cf3df388f5bb4213a3de0
MD5 2061664b3296ce74f3ab1af093c89600
BLAKE2b-256 19423b97a7b00e11e28d809cd4eb143e0d498d80eac2239b629bf4998080730f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.3-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.3-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5ea0a76dc762a74f870ad89066eb14182aa17338a1e02ef8f2a09fb9c9a5be1
MD5 fbbb2fa37b9e2140d6277ffa5332daa7
BLAKE2b-256 ddcf64d347a9a1415e48c213623a672a6fcb21d4c09161a56d20ad5a0ad9b747

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.3-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.3-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2170c6c6281d101cb829588f031b1ee7ee3bd75f4a42d4f2153a169de76b30ff
MD5 9df1340ee144d9c968347a8af56d2399
BLAKE2b-256 1efc0d0051c4a450d8771c1b3884718bc90778a3f1912a84249cc4704a2bcee4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.9.3-cp314-cp314t-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 2.3 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.3-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a634a386e45a037f5ce4dd64b19e1ca7c2d9dd2e320b9733a0fe6c09e5899cdd
MD5 6757d309ee959b88ff497cbdce9ea395
BLAKE2b-256 9e5087f8ea56399cd54e5294bb274bcfd4c427a50290efe0b26e1c7962823a92

See more details on using hashes here.

File details

Details for the file torchfont-0.9.3-cp38-abi3-win_arm64.whl.

File metadata

  • Download URL: torchfont-0.9.3-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.8+, 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.3-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 b5c93e2e2ba0b66a25fded51bfbe87d4eb45a33918d347efb6cb43863c556ce8
MD5 ea90e8dbeaf462a6eeaa27c8c4bfcbeb
BLAKE2b-256 90bddbbf25a1640aab641729d9be3e502972fa224bced3ba4670fce35a54c633

See more details on using hashes here.

File details

Details for the file torchfont-0.9.3-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: torchfont-0.9.3-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.8+, 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.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9bc91f8b168e0efe7a1a57b79171dbf644d451104014e5b7465da4e2f4aafae7
MD5 ac68b60b77e20a4a00ae8df079e5eb28
BLAKE2b-256 804531f6bbe971a0c2efa2d8209972b470daf9981831dafde7ec69d2a32fb48a

See more details on using hashes here.

File details

Details for the file torchfont-0.9.3-cp38-abi3-manylinux_2_35_aarch64.whl.

File metadata

  • Download URL: torchfont-0.9.3-cp38-abi3-manylinux_2_35_aarch64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.8+, 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.3-cp38-abi3-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 0dd00fdf9770975856ca04eae18181181088eb63c90170c34261001ded1b911b
MD5 a356a796a2d0b062120b7e42bf59c2da
BLAKE2b-256 065b95cb3f79eba4ce51c90a93c3eb8acb351cc4fbd751075791ffc6f36a8568

See more details on using hashes here.

File details

Details for the file torchfont-0.9.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: torchfont-0.9.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.8+, 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.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 baf5453bcc6e3e5721b6b68781a5664c0370c2d455f3dccec62403549dd1b118
MD5 f557ec314efc3299fa09c31f48f0a1e6
BLAKE2b-256 c5bdbcff02920b9b52da237e5d53ccc5eb91d152b4d3943c7499dfea367e70b4

See more details on using hashes here.

File details

Details for the file torchfont-0.9.3-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: torchfont-0.9.3-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.8+, 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.3-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eb3efaf8c97b7ee1ed5ad1b81b658754fbba71910cbff7bf90941c26dae43b9a
MD5 17430b8ba6d3a0de6c43a2be09dc45a3
BLAKE2b-256 d10f2d047e00e60c7bc4cbb0c3fa5d19d3f60f658a82992dd45f7db226c84a30

See more details on using hashes here.

File details

Details for the file torchfont-0.9.3-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: torchfont-0.9.3-cp38-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.8+, 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.3-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1802d38cc63e0be87c86985ba61ce9ee7209917016f189d483852bc5fc770f90
MD5 e65651df298d5fb2d2973d9d1727d90e
BLAKE2b-256 e39866a67be6ad892a910431a5722099f0dad9db6fdc33383e4b1217ffd9348c

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