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,
    author = {Fujioka, Takumu},
    title  = {{TorchFont: A Machine Learning library for Vector Fonts}},
    year   = {2025},
    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.2.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.2-cp314-cp314t-win_arm64.whl (2.5 MB view details)

Uploaded CPython 3.14tWindows ARM64

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

Uploaded CPython 3.14tWindows x86-64

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

Uploaded CPython 3.14tmanylinux: glibc 2.35+ ARM64

torchfont-0.10.2-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.2-cp314-cp314t-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

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

Uploaded CPython 3.14tmacOS 10.12+ x86-64

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

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+manylinux: glibc 2.35+ ARM64

torchfont-0.10.2-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.2-cp310-abi3-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

torchfont-0.10.2-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.2.tar.gz.

File metadata

  • Download URL: torchfont-0.10.2.tar.gz
  • Upload date:
  • Size: 7.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","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.2.tar.gz
Algorithm Hash digest
SHA256 a513a8d0ea07955ecc5a12d2e53465888e987178650d0e8f5b4751f129b87b2e
MD5 c1cc26ec67cbb86d1f6d935baf7ab80d
BLAKE2b-256 19db898a05c3b29eb4d489c954f4b4cd3f8253ea32449606c35c5ae8a6dd7856

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.2-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.21 {"installer":{"name":"uv","version":"0.11.21","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.2-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 58c2da93ab99da48c4fd6f909d471f9812be2441095ebf5ef0c95fbd2e15ae10
MD5 b6efd0b3b7e7323a37a48c2e25e218ed
BLAKE2b-256 2096cfc58da93e5aac4e707f28424d6edf008dca1b4f8b55da4f0666b64ad38b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.2-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.21 {"installer":{"name":"uv","version":"0.11.21","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.2-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 71a4c2ee1baa7a56fa26d6ee76018ffd625708c6d689d8482144939c313a4122
MD5 6680d1a2b0e772ab16c84a874c5f2464
BLAKE2b-256 e258ec8438e55beec06ba798b34f9a86bb67e52b5cb3cea69e5267e7bbb837c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.2-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.21 {"installer":{"name":"uv","version":"0.11.21","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.2-cp314-cp314t-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 8b8f6b775e1702d6834f024ae7d4b84216ee6595af5becf6d2a527048762c94b
MD5 4e966acb2484df06bb13c50bda06d4aa
BLAKE2b-256 9f0eecb02e00f7f73233156962f42a22f4dc7a5abb493286f25ccedb5fcd8c59

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.2-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.21 {"installer":{"name":"uv","version":"0.11.21","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.2-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e39586d5fa011271ff0d7f55219c49477834b2bdba7b90f9b9414b738aea91ea
MD5 e34ac2444b6d9084cca06ac3198ca49f
BLAKE2b-256 c9c1f2ccacc296990221d6f2dfc273c93e61a84f7d8599ace7824713aa030f84

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.2-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.21 {"installer":{"name":"uv","version":"0.11.21","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.2-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2d317ee0ec0c030428d667784ca7e785f65b8448ee44ded563e25e405729bde3
MD5 9b11cced86015eec64e70841e441a30a
BLAKE2b-256 088ef7599207d5d35f3679cdd8764bb114c27307a05276ba9a21d54785697857

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.2-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.21 {"installer":{"name":"uv","version":"0.11.21","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.2-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0b4e1c7a40f6384b02ed0619bda5aee52da4292666de477c408555a5655b96c5
MD5 9e2337bdecb0fd8ec7aa8ccfaed51ee5
BLAKE2b-256 6800c8be25f34d3a68be5f8ef28ca33b1def75f16c8460b00d618656a0e8585c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.2-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.21 {"installer":{"name":"uv","version":"0.11.21","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.2-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 99bbed89fa1cace18987aba77064e5544f5a362e9591db790a2054e02dd7810e
MD5 ac823b216c416b14514de560dcac5bd5
BLAKE2b-256 ebfe29c23cda92b8a8ac05d4f51ceab99c3ffb9d0a7ed9ccb5542292622b722b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.2-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.21 {"installer":{"name":"uv","version":"0.11.21","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.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6c8b75135acdfd75f8649c0590c5658c3fc802c0ae21a32bf86da0797b4d9daf
MD5 64bab74de82cfa6c2727b4ebb1e470b5
BLAKE2b-256 b4f5b8fe03ff9200930b652de87dba3830fc8c6af25287e3ec83cdad05ac1949

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.2-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.21 {"installer":{"name":"uv","version":"0.11.21","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.2-cp310-abi3-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 62da9f09d65176c7cc9952a89cadf4384f4898bc8283abdad18507c48bef61ae
MD5 5c5ed64575acfc6e0133ffdb9a006f87
BLAKE2b-256 9113e0d036c75e50efb21544aacd8c16201bfd2a148489eb0c630bfe594670a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.2-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.21 {"installer":{"name":"uv","version":"0.11.21","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.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e94c348f9abc91475841762958d4bd9ce171d979bc8f13a767aefb63a11f9287
MD5 4a1d31aff2cbb9e64ca7f7a43f1b5d2a
BLAKE2b-256 c8fa8d804de72d876cecc0324e5e585e42d884e5ac9319bfa9afe442b1c0e8f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.2-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.21 {"installer":{"name":"uv","version":"0.11.21","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.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 44d18696d4137c300f970c7c7412d6b35356685c1d1a26f449a3db23c59f5f62
MD5 c60c0a1c91b8e665d43c2b278d6d204d
BLAKE2b-256 2df6c608442cd3135a9e3cd16f8d806165788c09094a43ad234ee8dcf3df307d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchfont-0.10.2-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.21 {"installer":{"name":"uv","version":"0.11.21","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.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 87da0203faed33c591701f0ce3ac863f70fd5e5c6d023aef448cee94976e1db3
MD5 f2cbb9c2c54ca6731001a16cafd8d624
BLAKE2b-256 6ddfcbe15a94fcada5c9e4bc7e3c5e8e54d8c77f48df6e4bf2d4f82d0b076502

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