Typing stubs for Babel

2.11.0.15 · active · verified Sun Apr 12

types-babel provides PEP 561 type stubs for the babel package. It allows type-checking tools like MyPy, Pyright, and PyCharm to analyze code that uses the babel library. The current version is 2.11.0.15. As part of the Typeshed project, updates to these stubs are frequent, driven by community contributions and are released to PyPI up to once a day when changes are made.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use a function from the `babel` library (`format_date`) and implicitly leverage the type annotations provided by `types-babel` when running a type checker like MyPy. Ensure you have both `babel` and `mypy` installed. If your `babel` version is 2.12.1 or newer, `types-babel` is not needed.

from datetime import date
from babel.dates import format_date

def main():
    today = date(2026, 4, 12)
    # types-babel provides type information for functions like format_date
    formatted_today: str = format_date(today, locale='en_US')
    print(f"Today is: {formatted_today}")

    # Example of a type error (uncomment to see mypy in action):
    # invalid_type: int = format_date(today, locale='en_US')

if __name__ == '__main__':
    main()

# To run type checking, install mypy and babel:
# pip install babel mypy
# Then, run: mypy your_script_name.py

view raw JSON →