Skip to main content

windows-fonts

Enumerate and discover fonts on Windows

Why this module exists

Most (all?) python modules that render text to an image (matplotlib, PIL/Pillow etc) need to take a filename on Windows, but happily take a font name on other platforms, which is a) annoying from a cross-platform standpoint, and b) requires a bit of "faff" for the user to discover the font file for a given font.

Synopsis

>>> from windows_fonts import FontCollection, Weight
>>> fonts = FontCollection()

>>> # Get the first variant (light/regular/bold etc) for a named family
>>> family = fonts['Arial']

>>> variant = family[0]
>>> variant
<FontVariant name=Regular, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.REGULAR>
>>> print(variant.filename, variant.weight, variant.style)
C:\WINDOWS\FONTS\ARIAL.TTF Weight.REGULAR Style.NORMAL

>>> # Find the "closest" variant for a given family
>>> variant = family.get_best_variant(weight=Weight.BOLD)  # Or `style=Style.ITALIC, or both
>>> variant
<FontVariant name=Bold, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>

>>> # Or to find all "matching" variants in priority order:
>>> for variant  in family.get_matching_variants(weight=Weight.BOLD):
...    variant
...
<FontVariant name=Bold, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>
<FontVariant name=Bold, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>
<FontVariant name=Black, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BLACK>
<FontVariant name=Narrow Bold, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>
<FontVariant name=Narrow Bold, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>
<FontVariant name=Bold Italic, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>
<FontVariant name=Italic Bold, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>
<FontVariant name=Narrow Bold Italic, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>
<FontVariant name=Narrow Italic Bold, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>

Find a specific Font Variant

Some font families are aggregated, for instance Arial and Arial Narrow both are placed under the "Arial" family by the Win32 APIs. But if you want to be able to directly get to the Arial Narrow font files you need to use the top-level get_matching_variants function:

>>> get_matching_variants(win32_family_names="Arial Narrow")
[<FontVariant name=Narrow, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.REGULAR>,
 <FontVariant name=Narrow Italic, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.REGULAR>,
 <FontVariant name=Narrow Bold, family=<FontFamily name="Arial">, style=Style.NORMAL weight=Weight.BOLD>,
 <FontVariant name=Narrow Bold Italic, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>]

Or if you know the full name already:

>>> get_matching_variants(full_name="Arial Narrow Bold Italic")
[<FontVariant name=Narrow Bold Italic, family=<FontFamily name="Arial">, style=Style.ITALIIC weight=Weight.BOLD>]

Get information about a Font Variant

.information is a dict-like object. The some keys will not be available on every font.

>>> info = variant.information
>>> import pprint
>>> pprint.pprint(dict(info))
{'copyright': '© 2008 The Monotype Corporation. All Rights Reserved.',
 'description': ...,
 'designer': 'Robin Nicholas, Patricia Saunders',
 'full_name': 'Arial Narrow Italic',
 'license_description': ...,
 'manufacturer': 'The Monotype Corporation',
 'postscript_name': 'ArialNarrow-Italic',
 'preferred_family_names': 'Arial',
 'preferred_subfamily_names': 'Narrow Italic',
 'trademark': 'Arial is a trademark of The Monotype Corporation in the United '
              'States and/or other countries.',
 'typographic_subfamily_names': 'Narrow Italic',
 'typographic_family_names': 'Arial',
 'versions': 'Version 2.40',
 'win32_family_names': 'Arial Narrow',
 'win32_subfamily_names': 'Italic'}

Requirements

Python >= 3.7
Windows Vista and up
Some functions or methods need Windows 10 (get_matching_variants top-level function, and FontFamily.get_matching_variants when called with width, slant, optical_size, or italic parameters).

Release files for windows-fonts 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for windows-fonts 1.0.0
File Size Uploaded
windows_fonts-1.0.0.tar.gz 22.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for windows-fonts 1.0.0
File
windows_fonts-1.0.0-cp311-none-win_amd64.whl CPython 3.11 none Windows x86-64 Details
windows_fonts-1.0.0-cp310-none-win_amd64.whl CPython 3.10 none Windows x86-64 Details
windows_fonts-1.0.0-cp39-none-win_amd64.whl CPython 3.9 none Windows x86-64 Details
windows_fonts-1.0.0-cp38-none-win_amd64.whl CPython 3.8 none Windows x86-64 Details
windows_fonts-1.0.0-cp37-none-win_amd64.whl CPython 3.7 none Windows x86-64 Details

Total release size: 1.0 MB

Release files / windows_fonts-1.0.0.tar.gz

Download URL windows_fonts-1.0.0.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b87e8ee54936fd9a46b9d23f84011e076044c15febf40a902ffb289a89f1b26f
BLAKE2b-256 checksum
How to use checksums
ba575d66d0b9464582993ef54b810e63de482134b1cc7223a9edf10dab9dc301
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / windows_fonts-1.0.0-cp311-none-win_amd64.whl

Download URL windows_fonts-1.0.0-cp311-none-win_amd64.whl
Size 197.8 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
2426cda4cb5839166f74e7bb78cc20c66546873667fbbd7a78be0b365d1536db
BLAKE2b-256 checksum
How to use checksums
ffd6641de124bdc73eda758ceec30440c7a6c830d675821d9bd6c343bcf817bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / windows_fonts-1.0.0-cp310-none-win_amd64.whl

Download URL windows_fonts-1.0.0-cp310-none-win_amd64.whl
Size 197.8 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
05a20d9ebe29fd993eba1b9f9489b5978631c7a28e6cb47ccfa315940ebfa3a0
BLAKE2b-256 checksum
How to use checksums
b866097e1b715d49687cd38ab94710d8ddb6546a59f6c2beafe5dc68d436d9a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / windows_fonts-1.0.0-cp39-none-win_amd64.whl

Download URL windows_fonts-1.0.0-cp39-none-win_amd64.whl
Size 198.1 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
2b7c5f76525b15e2c1139062dd4bf4693bc2ce72e4d3f9a08c6a178e0026a603
BLAKE2b-256 checksum
How to use checksums
f009cead05bc9411acf702cbca4ba389e1387fcfeddaae1d436e2d8ff8504759
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / windows_fonts-1.0.0-cp38-none-win_amd64.whl

Download URL windows_fonts-1.0.0-cp38-none-win_amd64.whl
Size 197.6 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
51585401b3677204ea84bc1db2b46439960cd9fb7fda32b9b95fbb41823113c8
BLAKE2b-256 checksum
How to use checksums
ad323b14e6b3994daebe813afce062d451898dbc1f923e475026b3b4a97afeb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / windows_fonts-1.0.0-cp37-none-win_amd64.whl

Download URL windows_fonts-1.0.0-cp37-none-win_amd64.whl
Size 197.7 kB
Tags CPython 3.7 Windows x86-64
SHA-256 checksum
How to use checksums
ff8fd5d351d32ad03f44b20e990833fcef9411d76035961822b80c7053f81848
BLAKE2b-256 checksum
How to use checksums
0ea8fd8af2430b56e6dc6416b106e71462499925c87992d21780b9429d898629
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

1.0.0 This release

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page