Typing stubs for tabulate
types-tabulate is a type stub package part of the `typeshed` project, providing static type checking information for the `tabulate` library. `tabulate` itself is a popular Python library (current version 0.11.0, released in March 2026) that pretty-prints tabular data from various data structures like lists of lists, dictionaries, or Pandas DataFrames into highly customizable, human-readable formats (e.g., plain text, grid, Markdown, HTML). `types-tabulate` ensures that code using `tabulate` can be statically analyzed by type checkers like MyPy and Pyright for correctness, without adding runtime overhead. The package releases are aligned with `typeshed` and aim to provide accurate annotations for specific `tabulate` versions, currently targeting `tabulate==0.10.*`.
Warnings
- breaking `types-tabulate` is designed to provide accurate type annotations for a specific major version range of the runtime `tabulate` library. For example, `types-tabulate==0.10.0.20260308` targets `tabulate==0.10.*`. However, the `tabulate` library itself released version `0.11.0` in March 2026, which includes API changes (e.g., dropping the `youtrack` format, adding `Decimal` support). Previous major version `0.10.0` dropped Python 3.7-3.9 support and replaced the `PRESERVE_STERILITY` global with a function argument. If your installed `tabulate` runtime version (e.g., `0.11.0`) differs from the version `types-tabulate` is designed for (e.g., `0.10.*`), your type checker may report incorrect errors or fail to catch actual runtime type issues.
- gotcha `types-tabulate` is a stub-only package (`.pyi` files) and contains no runtime code. It's solely for static type checking purposes (e.g., with MyPy or Pyright). Attempting to import or use `types-tabulate` directly at runtime will result in an `ImportError` or `AttributeError` if you try to call functions from it, as the actual executable code resides in the `tabulate` package.
- gotcha Older versions of type checkers (like MyPy or Pyright) might bundle an older copy of `typeshed`, the repository where `types-tabulate` stubs originate. This can lead to them not recognizing newer typing features or annotations introduced in more recent `types-tabulate` releases. As a result, your type checker might silently infer `Any` types for parts of `tabulate`'s API or produce unexpected type errors, reducing the effectiveness of static analysis.
Install
-
pip install types-tabulate -
pip install tabulate
Imports
- tabulate
from tabulate import tabulate
Quickstart
from tabulate import tabulate
data = [
["Name", "Age", "City"],
["Alice", 30, "New York"],
["Bob", 24, "Los Angeles"],
["Charlie", 35, "Chicago"]
]
# Print with headers from the first row
print(tabulate(data, headers="firstrow", tablefmt="grid"))
print("\n---\n")
# Or from a list of dictionaries
data_dicts = [
{"Item": "Pizza", "Price": 850},
{"Item": "Burger", "Price": 500},
{"Item": "Salad", "Price": 475}
]
print(tabulate(data_dicts, headers="keys", tablefmt="fancy_grid"))