MkDocs Table Reader Plugin
mkdocs-table-reader-plugin is an MkDocs plugin designed to directly insert tables from various file formats (like CSV, Excel, JSON, YAML, Feather) into Markdown documentation. It is currently at version 3.1.0 and is actively maintained with regular updates and improvements.
Common errors
-
jinja2.exceptions.UndefinedError: 'read_csv' is undefined
cause The `table-reader` plugin is not correctly enabled in `mkdocs.yml`, or another plugin (like `mkdocs-markdownextradata-plugin` or `mkdocs-macros-plugin`) is processing Jinja2 tags before `table-reader` has a chance to register its macros, leading to conflicts.fixVerify that `plugins: - table-reader:` is present and correctly indented in your `mkdocs.yml`. If using with `mkdocs-macros-plugin` or `mkdocs-markdownextradata-plugin`, ensure `table-reader` is listed *after* them, e.g., `plugins: - macros - table-reader`. -
FileNotFoundError: [Errno 2] No such file or directory: 'your_table.csv'
cause The specified path to the table data file is incorrect, or the file does not exist in any of the plugin's default search locations (project root, `docs/` directory, or the current Markdown page's directory).fixDouble-check the file path in your `{{ read_...() }}` tag. Ensure it's correct relative to `mkdocs.yml`, your `docs/` directory, or the current Markdown file. You can also configure a `data_path` option in `mkdocs.yml` if all your tables reside in a common subdirectory, or use `allow_missing_files: true` during development to convert errors into warnings. -
XLRDError: Excel xlsx file; not supported by xlrd
cause You are attempting to read an `.xlsx` Excel file, but the necessary `openpyxl` library is not installed. The `xlrd` library, which might be present, does not support this file format.fixInstall `openpyxl` using pip: `pip install openpyxl`. -
Poetry add mkdocs-table-reader-plugin hangs when resolving dependencies
cause This often occurs due to a Python version mismatch. Recent versions of `mkdocs-table-reader-plugin` and its `pandas` dependency require Python 3.8 or higher.fixEnsure your Python environment meets the `requires_python>=3.8` requirement. Upgrade your Python version or create a new virtual environment with Python 3.8 or newer.
Warnings
- breaking The `base_path` option for configuring the plugin was deprecated in v3.0.0. The plugin now searches for data files relative to `mkdocs.yml`, the `docs/` directory, and the current Markdown page's directory by default.
- breaking Support for Python 3.7 was dropped in version 2.1.0.
- gotcha When using `mkdocs-table-reader-plugin` alongside `mkdocs-macros-plugin` or `mkdocs-markdownextradata-plugin`, the order of plugins in `mkdocs.yml` is crucial to prevent `UndefinedError` or incorrect rendering. `table-reader` should generally be listed *after* `macros` and `markdownextradata-plugin`.
- gotcha Specific Pandas versions might cause issues with internal DataFrame methods. For example, some users experienced regressions related to `df.map` or `applymap` on older Pandas versions.
- gotcha Attempting to read modern `.xlsx` Excel files might result in an `XLRDError` if `openpyxl` is not installed.
Install
-
pip install mkdocs-table-reader-plugin
Imports
- table-reader
import mkdocs_table_reader_plugin
plugins: - table-reader:
Quickstart
mkdocs.yml:
```yaml
site_name: My Data Docs
plugins:
- search
- table-reader
# Optional: Configure data_path if all your tables are in one directory
# plugins:
# - table-reader:
# data_path: assets/tables
```
docs/data/my_table.csv:
```csv
Header1,Header2
Value1,ValueA
Value2,ValueB
```
docs/index.md:
```markdown
# My Report
Here is some data from a CSV file:
{{ read_csv('data/my_table.csv') }}
And another one, specifying pandas options:
{{ read_csv('data/my_table.csv', sep=',', header=0) }}
```