tablate.Table#
- class tablate.Table(columns, rows, name=None, frame_divider=None, multiline=None, max_lines=None, background=None, background_padding=None, multiline_header=None, max_lines_header=None, hide_header=None, column_divider=None, column_padding=None, header_base_divider=None, row_line_divider=None, odd_row_background=None, even_row_background=None, text_style=None, text_align=None, text_color=None, header_styles=None, html_default_colors=None, html_px_multiplier=None, html_styles=None, html_header_styles=None, container_border=None, container_padding=None, container_width=None, html_container_styles=None)[source]#
Create a TablateItem table frame (multiple rows of multiple columns) to Tablate instance.
- Parameters:
columns (
List[TableColumnInput]) – List of column dicts containing a required column key and optional (str, int, float) to display, as well as column specific styling options. [required]rows (
List[Dict[str,Union[str,int,float]]]) – List of row dicts containing the (str, int, float) values for each column key. [required]name (
Optional[str]) – Frame name (to prevent duplicate entries). [default: None]frame_divider (
Optional[Literal['none','blank','thin','thick','double']]) – Dividing line at the bottom of the frame. [default: ‘thick’]background (
Optional[Literal['white','grey','red','green','yellow','blue','magenta','cyan','dark_red','dark_green','dark_yellow','dark_blue','dark_magenta','dark_cyan','dark_grey','black']]) – Background color for the table frame. [default: None]background_padding (
Optional[int]) – Additional padding applied to text if background color set (ASCII only). [default: 1]multiline (
Optional[bool]) – Whether the text may wrap to multiple lines. [default: False]max_lines (
Optional[int]) – Maximum number of lines to which the text may wrap. [default: None]multiline_header (
Optional[bool]) – Whether the header text may wrap to multiple lines. [default: False]max_lines_header (
Optional[int]) – Maximum number of lines to which the header text may wrap. [default: None]hide_header (
Optional[bool]) – Whether to not render the header. [default: False]column_divider (
Optional[Literal['blank','thin','thick','double']]) – Dividing line between columns. [default: ‘thin’]column_padding (
Optional[int]) – Text padding within each column. [default: 1]header_base_divider (
Optional[Literal['none','blank','thin','thick','double']]) – Dividing line at the bottom of the table header frame. [default: ‘thick’]row_line_divider (
Optional[Literal['none','blank','thin','thick','double']]) – Dividing line between each row of the table frame. [default: ‘thin’]odd_row_background (
Optional[Literal['white','grey','red','green','yellow','blue','magenta','cyan','dark_red','dark_green','dark_yellow','dark_blue','dark_magenta','dark_cyan','dark_grey','black']]) – Background color for odd rows of table frame. [default: None]even_row_background (
Optional[Literal['white','grey','red','green','yellow','blue','magenta','cyan','dark_red','dark_green','dark_yellow','dark_blue','dark_magenta','dark_cyan','dark_grey','black']]) – Background color for even rows of table frame. [default: None]text_style (
Optional[Literal['normal','bold','underlined','bold_underlined']]) – Text style for table frame. [default: ‘normal’]text_align (
Optional[Literal['left','center','right']]) – Text alignment for table frame. [default: ‘left’]text_color (
Optional[Literal['white','grey','red','green','yellow','blue','magenta','cyan','dark_red','dark_green','dark_yellow','dark_blue','dark_magenta','dark_cyan','dark_grey','black']]) – Text color for grid frame. [default: None]header_styles (
Optional[BaseStylesInput]) – Specific styles to apply to the table header frame. [default: None (inherits table styles)]html_px_multiplier (
Optional[int]) – Multiplier applied to HTML px properties. [default: 1]html_styles (
Optional[HtmlTableFrameStylesInput]) – HTML specific styles for table frame. [default: { “html_frame_styles”: {“html_frame_divider_style”: “thick”, “html_frame_divider_weight: 1, “html_frame_divider_color”: ‘black’, “html_multiline”: True (False for Table frames), “html_max_lines”: None, “html_background”: None }, “html_column_styles”: {“html_column_divider_style”: “thin”, “html_column_divider_weight”: 1, “html_column_divider_color”: “black”, “html_padding”: “6px”}, “html_text_styles”: {“html_text_style”: ‘normal’, “html_text_align”: ‘left’, “html_text_color”: None, “html_text_size”: 16 }, “html_row_styles”: {“html_row_line_divider_weight”: 1, “html_row_line_divider_style”: “thin”, “html_row_line_divider_color”: None, “html_odds_background”: None, “html_evens_background”: None} }] (Tablate constructor option html_default_colors applies styles to table headers and even rows, separately from, but overwritten by, this html_styles dict)html_header_styles (
Optional[HtmlStylesInput]) – HTML specific styles for table header frame. [default: None (inherits table styles)]container_border (
Optional[Literal['blank','thin','thick','double']]) – outer border style for the Tablate container instance. [default: ‘thick’]container_padding (
Optional[int]) – outer padding (in Unicode character width) for the Tablate container instance. [default: 1]container_width (
Optional[int]) – outer width (in Unicode character width) for the Tablate container instance. [default: 120 or terminal width]html_container_styles (
Optional[HtmlContainerStylesInput]) – style dictionary for HTML specific styles for Tablate container instance. [default: None]
- apply(function, raise_merge_error=True)#
Iterates over frame items and calls the passed function for on each iteration. Optionally, if the functions returns a valid frame options dict or global options dicts, these will be set to the internal store. If there is an error, trying to set the return objects, the .apply() method will break and reset the internal stores.
Note
As a rule of thumb, the return objects should have the same form as the third (frame options) and forth (global options) arguments passed to the .apply() method.
- Parameters:
function (
Callable[[str,Literal['text','grid','table'],dict,dict],Tuple[dict,dict]]) – A function called for each frame element. The function accepts four arguments: the frame type, the frame name, the frame options and the global options. The function may return a tuple containing the frame options and the global options. Tablate will attempt to apply the return values, if set, to its internal frame store and the global options store.raise_merge_error (
bool) – If set to True, the apply function will raise an
- apply_style(selector, css, sub_selector=None)#
Applies custom CSS styling to the Tablate container instance. CSS stylings are scoped to the specific Tablate container instance.
- Parameters:
selector (
str) – The HTML classnames within the Tablate container instance.css (
str) – The CSS style to be set (for instance: background-color: #FFFFFF).sub_selector (
Optional[str]) – An additional selector appended immediately after the main selector block.
- property name#
The name of the frame.
- Type:
Returns
- print()#
Prints an ASCII rendering of the Tablate container instance.
- Return type:
None
- rename(new_name)#
Renames the frame. :type new_name:
str:param new_name: The new name set on the frame.
- to_dict()#
Returns: A Pandas compatible dict.
- to_html()#
Generates an HTML rendering of the Tablate container instance.
Returns: An HTML rendering of the Tablate container instance.
- Return type:
str
- to_string()#
Generates an ASCII rendering of the Tablate container instance.
Returns: An ASCII rendering of the Tablate container instance.
- Return type:
str