Sheets

A Sheet is a representation of some source, usually a Path. A path can be opened, returning a sheet, and/or a sheet can be saved to path.

visidata.vd.openPath(p, filetype=None, create=False)

Call open_<filetype>(p) or openurl_<p.scheme>(p, filetype). Return constructed but unloaded sheet of appropriate type. If True, create will return a new, blank Sheet if file does not exist.

visidata.vd.openSource(p, filetype=None, create=False, **kwargs)

Return unloaded sheet object for p opened as the given filetype and with kwargs as option overrides. p can be a Path or a string (filename, url, or “-” for stdin). when true, create will return a blank sheet, if file does not exist.

visidata.vd.saveSheets(givenpath, *vsheets, confirm_overwrite=True)

Save all vsheets to givenpath.

Sheets API

class visidata.BaseSheet(*names, rows=(), **kwargs)[source]

Base class for all sheet types.

BaseSheet.name

Name of this sheet.

visidata.BaseSheet.__len__(self)

Number of elements on this sheet.

visidata.BaseSheet.__copy__(self)

Return shallow copy of sheet.

visidata.BaseSheet.reload(self)

Load sheet from self.source. Override in subclass.

TableSheet

Sheets are generally specialized for their rowtype, and TableSheet, used for sheets with rows and columns, is the most common base class. (So common, that it was originally just called Sheet. For clarity, TableSheet is preferred, but Sheet is a valid alias that will never be deprecated.)

class visidata.TableSheet(*names, rows=(), **kwargs)[source]

Base class for sheets with row objects and column views.

visidata.TableSheet.rows

List of row objects on this sheet.

visidata.TableSheet.columns

List of all Column objects on this sheet (including hidden columns).

TableSheet.nRows

Number of rows on this sheet.

TableSheet.nCols

Number of columns on this sheet.

TableSheet.visibleCols

List of non-hidden columns in display order.

TableSheet.nVisibleCols

Number of visible columns on this sheet.

visidata.TableSheet.addRow(self, row, index=None)

Insert row at index, or append at end of rows if index is None.

visidata.TableSheet.addColumn(self, *cols, index=None)

Insert all cols into columns at index, or append to end of columns if index is None. If index is None, columns are being added by loader, instead of by user. If added by user, mark sheet as modified. Columns added by loader share sheet’s defer status. Columns added by user are not marked as deferred. Return first column.

visidata.TableSheet.iterload(self)

Generate rows from self.source. Override in subclass.

visidata.TableSheet.rowid(self, row)

Return a unique and stable hash of the row object. Must be fast. Overridable.

visidata.TableSheet.column(self, colname)

Return first column whose name matches colname.

visidata.TableSheet.openRow(sheet, row, rowidx=None)

Return Sheet diving into row.

visidata.TableSheet.openCell(sheet, col, row, rowidx=None)

Return Sheet diving into cell at row in col.

visidata.TableSheet.gatherBy(self, func, gerund='gathering')

Generate rows for which func(row) returns True, starting from the cursor.

Other Common Sheet Types

These can be used as base classes, or instantiated as they are, or used as templates for rows with similar structure,

class visidata.IndexSheet(*names, rows=(), **kwargs)[source]

Base class for tabular sheets with rows that are Sheets.

class visidata.TextSheet(*names, rows=(), **kwargs)[source]

Displays any iterable source, with linewrap if options.wrap is set.

class visidata.SequenceSheet(*names, rows=(), **kwargs)[source]

Sheets with ColumnItem columns, and rows that are Python sequences (list, namedtuple, etc).

class visidata.PyobjSheet(*names, **kwargs)[source]

Generic Sheet for any Python object. Return specialized subclasses for lists of objects, namedtuples, and dicts.

The Sheet Stack

visidata.vd.sheets

The “sheet stack”, a list of active sheets (available as the Sheets Sheet via Shift+S). The top sheet, or the displayed sheet, is the first item in the list (vd.sheets[0]).

visidata.vd.sheet

The top sheet on the sheet stack.

visidata.vd.push(vs, pane=0, load=True)

Push Sheet vs onto vd.sheets stack for pane (0 for active pane, -1 for inactive pane). Remove from other position if already on sheets stack.

visidata.vd.replace(vs)

Replace top sheet with the given sheet vs.

visidata.vd.remove(vs)

Remove vs from sheets stack, without asking for confirmation.

visidata.vd.quit(*sheets)

Remove sheets from sheets stack, asking for confirmation if needed.

visidata.vd.getSheet(sheetname)

Return Sheet from the sheet stack. sheetname can be a sheet name or a sheet number indexing directly into vd.sheets.