How to Enable Data Integrity and Table Size Checking in Outfancy
Enable data integrity and table size checking in Outfancy by calling Table.set_check_data(True) and Table.set_check_table_size(True) on your Table instance before invoking render().
Outfancy is a Python library designed for rendering clean, formatted tables in terminal environments. When working with dynamic datasets, you can activate built-in validation mechanisms to catch structural errors and enforce row limits before the rendering pipeline executes.
Understanding the Validation Options
Outfancy's table rendering engine validates incoming datasets through two independent checks defined in outfancy/table.py:
- Data integrity checking validates that your dataset is a non-empty list of tuples with consistent column counts, ensuring no tuple contains lists or boolean values.
- Table size checking verifies that the number of rows does not exceed the configured
maximum_number_of_rowsthreshold.
Both checks are disabled by default (self.check_data = False and self.check_table_size = False) and must be explicitly enabled via setter methods.
Enabling Data Integrity Checking
To validate dataset structure before rendering, call set_check_data(True) on your Table instance. When enabled, the render() method invokes check_data_integrity() (lines 84-124 in outfancy/table.py) to verify:
- The dataset is a non-empty list of tuples
- Every tuple has identical length (consistent columns)
- No tuple element is a list or boolean
If validation fails, render() returns an error string instead of the formatted table:
from outfancy import Table
tbl = Table()
tbl.set_check_data(True)
# This will fail validation due to inconsistent tuple lengths and invalid types
bad_data = [
(1, 'Alice'), # 2 columns
(2, ['Bob', 'extra']), # list inside tuple → invalid
(3, 'Carol', 'Manager', 'extra') # 4 columns
]
result = tbl.render(bad_data)
print(result)
# Output: --- Table > Render > check_data_integrity: Corrupt or invalid data. ---
Configuring Table Size Limits
To enforce row count limits, enable size checking with set_check_table_size(True) and optionally configure the limit using set_maximum_number_of_rows() (default is -1 for unlimited). This triggers the check_correct_table_size() method (lines 72-84 in outfancy/table.py):
tbl = Table()
tbl.set_check_table_size(True)
tbl.set_maximum_number_of_rows(2) # Allow only 2 rows
data = [
(1, 'Alice'),
(2, 'Bob'),
(3, 'Carol')
]
result = tbl.render(data)
print(result)
# Output: --- Table > Render: The data dimensions are incongruent. ---
Complete Implementation Example
Here is a full implementation enabling both validation layers with a configured row limit:
from outfancy import Table
# Create a Table instance
tbl = Table()
# Enable both safety checks
tbl.set_check_data(True) # Validate data structure and content
tbl.set_check_table_size(True) # Enforce row-count limits
# Set maximum rows (optional, defaults to -1/unlimited)
tbl.set_maximum_number_of_rows(100)
# Render a valid dataset
data = [
(1, 'Alice', 'Engineer'),
(2, 'Bob', 'Designer'),
(3, 'Carol', 'Manager')
]
result = tbl.render(data)
print(result)
How Validation Works in the Rendering Pipeline
According to the source code in outfancy/table.py, the render() method (around lines 300-324) consults these boolean flags early in the execution flow:
if self.check_data:
if self.check_data_integrity(data):
return '--- Table > Render > check_data_integrity: Corrupt or invalid data. ---'
if self.check_table_size:
if self.check_correct_table_size(data):
return '--- Table > Render: The data dimensions are incongruent. --- '
The flags are initialized in the Table class constructor at lines 46-51:
- Integrity flag and setter: Lines 46-48 define
self.check_dataandset_check_data() - Size flag and setter: Lines 49-51 define
self.check_table_sizeandset_check_table_size()
Because these checks execute before any formatting logic, they prevent processing overhead on invalid datasets.
Summary
- Data integrity checking validates tuple structure, column consistency, and prohibited data types via
Table.set_check_data(True), implemented incheck_data_integrity()at lines 84-124 ofoutfancy/table.py. - Table size checking enforces row limits via
Table.set_check_table_size(True)andset_maximum_number_of_rows(), implemented incheck_correct_table_size()at lines 72-84. - Both checks are evaluated at the start of the
render()method (lines 300-324) before any table formatting occurs. - Failed validations return descriptive error strings rather than raising exceptions.
Frequently Asked Questions
What happens if I enable data integrity checking but pass an empty list?
The check_data_integrity() method validates that the dataset is non-empty. Passing an empty list will trigger the validation failure, causing render() to return the error message: --- Table > Render > check_data_integrity: Corrupt or invalid data. ---.
Can I enable only one check without the other?
Yes, the two validation systems operate independently. You can call set_check_data(True) without enabling table size checking, or vice versa. Each flag controls only its specific validation routine in the rendering pipeline.
Does enabling these checks affect rendering performance?
The validation adds minimal overhead because it executes early in the render() method before expensive formatting operations. The integrity check iterates through the dataset once to validate tuple lengths and types, while the size check simply compares len(data) against maximum_number_of_rows.
Where are the setter methods defined in the source code?
The setter methods are defined in outfancy/table.py. Specifically, set_check_data() appears around lines 46-48 and set_check_table_size() around lines 49-51, alongside the boolean flag initializations in the Table class constructor.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →