Loading

CSV files

The {csv-include} directive allows you to include and render CSV files as formatted tables in your documentation. The directive automatically parses CSV content and renders it using the standard table styles defined in table.css.

Sample user data from the database
Name Age City Occupation
John Doe 30 New York Software Engineer
Jane Smith 25 Los Angeles Product Manager
Bob Johnson 35 Chicago Data Scientist
Alice Brown 28 San Francisco UX Designer
Charlie Wilson 32 Boston DevOps Engineer
:::{csv-include} _snippets/sample-data.csv
:::
		

The CSV file directive supports several options to customize the table rendering:

Add a descriptive caption above the table:

:::{csv-include} _snippets/sample-data.csv
:caption: Sample user data from the database
:::
		

Specify a custom field separator (default is comma):

:::{csv-include} _snippets/sample-data.csv
:separator: ;
:::
		

CSV files with many columns are rendered as scrollable tables:

Product inventory with 12 columns
Product SKU Category Brand Price Stock Weight Rating Reviews Color Size Material
Laptop Pro LP-001 Electronics TechCorp 1299.99 45 2.3kg 4.5 1250 Silver 15 inch Aluminum
Wireless Mouse WM-002 Accessories ClickMaster 49.99 230 0.1kg 4.2 890 Black Standard Plastic
USB-C Hub UH-003 Accessories ConnectAll 79.99 180 0.2kg 4.7 654 Gray Compact Metal
Mechanical Keyboard MK-004 Accessories TypeFast 159.99 92 0.8kg 4.8 2100 White Full ABS Plastic
Monitor Stand MS-005 Furniture DeskPro 89.99 67 1.5kg 4.1 445 Black Large Steel
:::{csv-include} _snippets/sample-data-12-columns.csv
:caption: Product inventory with 12 columns
:::
		

The directive includes built-in performance limits to handle large files efficiently:

  • Row limit: Maximum of 25,000 rows will be displayed
  • Column limit: Maximum of 15 columns will be displayed
  • File size limit: Maximum file size of 10MB

The CSV directive is optimized for large files:

  • Files are processed using streaming to avoid loading everything into memory
  • Built-in size validation prevents processing of files that exceed 10MB
  • Row and column limits protect against accidentally rendering massive tables
  • Warning messages are displayed when limits are exceeded

For optimal performance with large CSV files, consider:

  • Breaking very large files into smaller, more manageable chunks