Module datapane.client.api.files

Functions

def get_wrapper(x: Any, default_to_json: bool, error_msg: Optional[str] = None) ‑> BaseAsset
def save(obj: Any, default_to_json: bool = False) ‑> datapane.client.api.common.DPTmpFile
def convert(obj: Any) ‑> DataBlock

Attempt to convert/wrap a 'primitive' Python object into a Datapane 'boxed' object

Classes

class BaseAsset

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::

class Mapping(Generic[KT, VT]): def getitem(self, key: KT) -> VT: … # Etc.

This class can then be used as follows::

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default

Ancestors

  • typing.Generic
  • abc.ABC

Subclasses

Class variables

var mimetype : str
var obj_type : ~T
var block_type : Type[DataBlock]
var ext : str
var file_mode : str

Methods

def write(self, x: ~T) ‑> datapane.client.api.common.DPTmpFile
def write_file(self, f: , x: ~T)
def to_block(self, x: ~T) ‑> DataBlock
class BasePickleWriter

Creates a pickle file from any object

Ancestors

Class variables

var mimetype : str
var obj_type : ~T
var block_type : Type[DataBlock]

File blocks are used to attach a file to the report that can be displayed (if possible) and downloaded by report viewers

Any types of files may be attached, for instance, images (png / jpg), PDFs, JSON data, Excel files, etc.

var ext : str
var file_mode : str

Methods

def write_file(self, f: , x: Any)
class BaseJsonWriter

Creates a JSON file from any object

Ancestors

Class variables

var file_mode : str
var mimetype : str
var obj_type : ~T
var block_type : Type[DataBlock]

File blocks are used to attach a file to the report that can be displayed (if possible) and downloaded by report viewers

Any types of files may be attached, for instance, images (png / jpg), PDFs, JSON data, Excel files, etc.

var ext : str

Methods

def write_file(self, f: , x: Any)
class StringWrapper

Creates a Json for a string File, or Markdown for a Block

Ancestors

Class variables

var file_mode : str
var mimetype : str
var obj_type : ~T

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

var block_type : Type[DataBlock]

Markdown objects store Markdown text that can be displayed as formatted text when viewing your report.

Note: This object is also available as dp.Text, and any strings provided directly to the Report/Group object are converted automatically to Markdown blocks

Tip: You can also insert a dataframe in a Markdown block as a table by using df.to_markdown(), or use dp.Table or dp.DataTable for dedicated dataframe tables.

var ext : str

Methods

def write_file(self, f: , x: Any)
class PathWrapper

Creates a File block around Path objects

Ancestors

Class variables

var mimetype : str
var ext : str
var file_mode : str
var obj_type : ~T

PurePath subclass that can make system calls.

Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa.

var block_type : Type[DataBlock]

File blocks are used to attach a file to the report that can be displayed (if possible) and downloaded by report viewers

Any types of files may be attached, for instance, images (png / jpg), PDFs, JSON data, Excel files, etc.

Methods

def to_block(self, x: ~T) ‑> DataBlock
class BaseTable

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::

class Mapping(Generic[KT, VT]): def getitem(self, key: KT) -> VT: … # Etc.

This class can then be used as follows::

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default

Ancestors

Subclasses

Class variables

var obj_type : ~U
var mimetype : str
var ext : str
var TABLE_CELLS_LIMIT : int
var block_type : Type[DataBlock]

Table blocks store the contents of a dataframe as a HTML table whose style can be customised using pandas' Styler API.

Note: Please use Table component when saving files locally over the DataTable component which has more features but requires publishing your report

var allowed_attrs
var allowed_tags
var allowed_protocols

Methods

def write_file(self, f: , x: ~U)
def to_block(self, x: ~T) ‑> DataBlock
def render_html(self, obj: ~U) ‑> str
class StylerTable

Creates a styled html table from a pandas Styler object

Ancestors

Class variables

var TABLE_CELLS_LIMIT : int
var obj_type : ~U

Helps style a DataFrame or Series according to the data with HTML and CSS.

Parameters

data : Series or DataFrame
Data to be styled - either a Series or DataFrame.
precision : int
Precision to round floats to, defaults to pd.options.display.precision.
table_styles : list-like, default None
List of {selector: (attr, value)} dicts; see Notes.
uuid : str, default None
A unique identifier to avoid CSS collisions; generated automatically.
caption : str, default None
Caption to attach to the table.
table_attributes : str, default None
Items that show up in the opening <table> tag in addition to automatic (by default) id.
cell_ids : bool, default True
If True, each cell will have an id attribute in their HTML tag. The id takes the form T_<uuid>_row<num_row>_col<num_col> where <uuid> is the unique identifier, <num_row> is the row number and <num_col> is the column number.
na_rep : str, optional

Representation for missing values. If na_rep is None, no special formatting is applied.

Added in version: 1.0.0

Attributes

env : Jinja2 jinja2.Environment
 
template : Jinja2 Template
 
loader : Jinja2 Loader
 

See Also

DataFrame.style
Return a Styler object containing methods for building a styled HTML representation for the DataFrame.

Notes

Most styling will be done by passing style functions into Styler.apply or Styler.applymap. Style functions should return values with strings containing CSS 'attr: value' that will be applied to the indicated cells.

If using in the Jupyter notebook, Styler has defined a _repr_html_ to automatically render itself. Otherwise call Styler.render to get the generated HTML.

CSS classes are attached to the generated HTML

  • Index and Column names include index_name and level<k> where k is its level in a MultiIndex
  • Index label cells include

  • row_heading

  • row<n> where n is the numeric position of the row
  • level<k> where k is the level in a MultiIndex

  • Column label cells include

  • col_heading
  • col<n> where n is the numeric position of the column
  • level<k> where k is the level in a MultiIndex

  • Blank cells include blank

  • Data cells include data
var block_type : Type[DataBlock]

Inherited from: BaseTable.block_type

Table blocks store the contents of a dataframe as a HTML table whose style can be customised using pandas' Styler API …

Methods

def render_html(self, obj: ~U) ‑> str
class DataFrameTable

Creates an html table from the dataframe

Ancestors

Class variables

var TABLE_CELLS_LIMIT : int
var obj_type : ~U

Two-dimensional, size-mutable, potentially heterogeneous tabular data.

Data structure also contains labeled axes (rows and columns). Arithmetic operations align on both row and column labels. Can be thought of as a dict-like container for Series objects. The primary pandas data structure.

Parameters

data : ndarray (structured or homogeneous), Iterable, dict, or DataFrame

Dict can contain Series, arrays, constants, or list-like objects.

Changed in version: 0.23.0

If data is a dict, column order follows insertion-order for Python 3.6 and later.

Changed in version: 0.25.0

If data is a list of dicts, column order follows insertion-order for Python 3.6 and later.

index : Index or array-like
Index to use for resulting frame. Will default to RangeIndex if no indexing information part of input data and no index provided.
columns : Index or array-like
Column labels to use for resulting frame. Will default to RangeIndex (0, 1, 2, …, n) if no column labels are provided.
dtype : dtype, default None
Data type to force. Only a single dtype is allowed. If None, infer.
copy : bool, default False
Copy data from inputs. Only affects DataFrame / 2d ndarray input.

See Also

DataFrame.from_records
Constructor from tuples, also record arrays.
DataFrame.from_dict
From dicts of Series, arrays, or dicts.
read_csv
Read a comma-separated values (csv) file into DataFrame.
read_table
Read general delimited file into DataFrame.
read_clipboard
Read text from clipboard into DataFrame.

Examples

Constructing DataFrame from a dictionary.

>>> d = {'col1': [1, 2], 'col2': [3, 4]}
>>> df = pd.DataFrame(data=d)
>>> df
   col1  col2
0     1     3
1     2     4

Notice that the inferred dtype is int64.

>>> df.dtypes
col1    int64
col2    int64
dtype: object

To enforce a single dtype:

>>> df = pd.DataFrame(data=d, dtype=np.int8)
>>> df.dtypes
col1    int8
col2    int8
dtype: object

Constructing DataFrame from numpy ndarray:

>>> df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
...                    columns=['a', 'b', 'c'])
>>> df2
   a  b  c
0  1  2  3
1  4  5  6
2  7  8  9
var block_type : Type[DataBlock]

Inherited from: BaseTable.block_type

Table blocks store the contents of a dataframe as a HTML table whose style can be customised using pandas' Styler API …

Methods

def render_html(self, obj: ~U) ‑> str
class PlotAsset

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::

class Mapping(Generic[KT, VT]): def getitem(self, key: KT) -> VT: … # Etc.

This class can then be used as follows::

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default

Ancestors

Subclasses

Class variables

var mimetype : str
var obj_type : ~T
var ext : str
var file_mode : str
var block_type : Type[DataBlock]

Plot blocks store a Python-based plot object, including ones created by Altair, Plotly, Matplotlib, Bokeh, and Folium, for interactive display in your report when viewed in the browser.

class MatplotBasePlot

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::

class Mapping(Generic[KT, VT]): def getitem(self, key: KT) -> VT: … # Etc.

This class can then be used as follows::

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default

Ancestors

Subclasses

Class variables

var obj_type : ~T
var block_type : Type[DataBlock]

Inherited from: PlotAsset.block_type

Plot blocks store a Python-based plot object, including ones created by Altair, Plotly, Matplotlib, Bokeh, and Folium, for interactive display in your …

var file_mode : str
var ext : str
var mimetype : str
class MatplotFigurePlot

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::

class Mapping(Generic[KT, VT]): def getitem(self, key: KT) -> VT: … # Etc.

This class can then be used as follows::

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default

Ancestors

Class variables

var mimetype : str
var block_type : Type[DataBlock]

Inherited from: MatplotBasePlot.block_type

Plot blocks store a Python-based plot object, including ones created by Altair, Plotly, Matplotlib, Bokeh, and Folium, for interactive display in your …

var ext : str
var file_mode : str
var obj_type : ~T

Methods

def write(self, x: Figure) ‑> datapane.client.api.common.DPTmpFile
class MatplotAxesPlot

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::

class Mapping(Generic[KT, VT]): def getitem(self, key: KT) -> VT: … # Etc.

This class can then be used as follows::

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default

Ancestors

Class variables

var mimetype : str
var block_type : Type[DataBlock]

Inherited from: MatplotBasePlot.block_type

Plot blocks store a Python-based plot object, including ones created by Altair, Plotly, Matplotlib, Bokeh, and Folium, for interactive display in your …

var ext : str
var file_mode : str
var obj_type : ~T

Methods

def write(self, x: Axes) ‑> datapane.client.api.common.DPTmpFile
class MatplotNDArrayPlot

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::

class Mapping(Generic[KT, VT]): def getitem(self, key: KT) -> VT: … # Etc.

This class can then be used as follows::

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default

Ancestors

Class variables

var mimetype : str
var block_type : Type[DataBlock]

Inherited from: MatplotBasePlot.block_type

Plot blocks store a Python-based plot object, including ones created by Altair, Plotly, Matplotlib, Bokeh, and Folium, for interactive display in your …

var ext : str
var file_mode : str
var obj_type : ~T

ndarray(shape, dtype=float, buffer=None, offset=0, strides=None, order=None)

An array object represents a multidimensional, homogeneous array of fixed-size items. An associated data-type object describes the format of each element in the array (its byte-order, how many bytes it occupies in memory, whether it is an integer, a floating point number, or something else, etc.)

Arrays should be constructed using array, zeros or empty (refer to the See Also section below). The parameters given here refer to a low-level method (ndarray(…)) for instantiating an array.

For more information, refer to the numpy module and examine the methods and attributes of an array.

Parameters

(for the new method; see Notes below)

shape : tuple of ints
Shape of created array.
dtype : data-type, optional
Any object that can be interpreted as a numpy data type.
buffer : object exposing buffer interface, optional
Used to fill the array with data.
offset : int, optional
Offset of array data in buffer.
strides : tuple of ints, optional
Strides of data in memory.
order : {'C', 'F'}, optional
Row-major (C-style) or column-major (Fortran-style) order.

Attributes

T : ndarray
Transpose of the array.
data : buffer
The array's elements, in memory.
dtype : dtype object
Describes the format of the elements in the array.
flags : dict
Dictionary containing information related to memory use, e.g., 'C_CONTIGUOUS', 'OWNDATA', 'WRITEABLE', etc.
flat : numpy.flatiter object
Flattened version of the array as an iterator. The iterator allows assignments, e.g., x.flat = 3 (See ndarray.flat for assignment examples; TODO).
imag : ndarray
Imaginary part of the array.
real : ndarray
Real part of the array.
size : int
Number of elements in the array.
itemsize : int
The memory use of each array element in bytes.
nbytes : int
The total number of bytes required to store the array data, i.e., itemsize * size.
ndim : int
The array's number of dimensions.
shape : tuple of ints
Shape of the array.
strides : tuple of ints
The step-size required to move from one element to the next in memory. For example, a contiguous (3, 4) array of type int16 in C-order has strides (8, 2). This implies that to move from element to element in memory requires jumps of 2 bytes. To move from row-to-row, one needs to jump 8 bytes at a time (2 * 4).
ctypes : ctypes object
Class containing properties of the array needed for interaction with ctypes.
base : ndarray
If the array is a view into another array, that array is its base (unless that array is also a view). The base array is where the array data is actually stored.

See Also

array
Construct an array.
zeros
Create an array, each element of which is zero.
empty
Create an array, but leave its allocated memory unchanged (i.e., it contains "garbage").
dtype
Create a data-type.

Notes

There are two modes of creating an array using __new__:

  1. If buffer is None, then only shape, dtype, and order are used.
  2. If buffer is an object exposing the buffer interface, then all keywords are interpreted.

No __init__ method is needed because the array is fully initialized after the __new__ method.

Examples

These examples illustrate the low-level ndarray constructor. Refer to the See Also section above for easier ways of constructing an ndarray.

First mode, buffer is None:

>>> np.ndarray(shape=(2,2), dtype=float, order='F')
array([[0.0e+000, 0.0e+000], # random
       [     nan, 2.5e-323]])

Second mode:

>>> np.ndarray((2,), buffer=np.array([1,2,3]),
...            offset=np.int_().itemsize,
...            dtype=int) # offset = 1*itemsize, i.e. skip first element
array([2, 3])

Methods

def write(self, x: numpy.ndarray) ‑> datapane.client.api.common.DPTmpFile
class BokehBasePlot

Returns an interactive Bokeh application, supports both basic plots and layout plots via subclasses

Ancestors

Subclasses

Class variables

var obj_type : ~T
var block_type : Type[DataBlock]

Inherited from: PlotAsset.block_type

Plot blocks store a Python-based plot object, including ones created by Altair, Plotly, Matplotlib, Bokeh, and Folium, for interactive display in your …

var file_mode : str
var mimetype : str
var ext : str

Methods

def write_file(self, f: , app)
class BokehPlot

Returns an interactive Bokeh application, supports both basic plots and layout plots via subclasses

Ancestors

Class variables

var mimetype : str
var block_type : Type[DataBlock]

Inherited from: BokehBasePlot.block_type

Plot blocks store a Python-based plot object, including ones created by Altair, Plotly, Matplotlib, Bokeh, and Folium, for interactive display in your …

var ext : str
var file_mode : str
var obj_type : ~T
class BokehLayoutPlot

Returns an interactive Bokeh application, supports both basic plots and layout plots via subclasses

Ancestors

Class variables

var mimetype : str
var block_type : Type[DataBlock]

Inherited from: BokehBasePlot.block_type

Plot blocks store a Python-based plot object, including ones created by Altair, Plotly, Matplotlib, Bokeh, and Folium, for interactive display in your …

var ext : str
var file_mode : str
var obj_type : ~T
class AltairPlot

Creates a vega-light chart from Altair Chart / pdvega Axes object.

Ancestors

Class variables

var block_type : Type[DataBlock]

Inherited from: PlotAsset.block_type

Plot blocks store a Python-based plot object, including ones created by Altair, Plotly, Matplotlib, Bokeh, and Folium, for interactive display in your …

var file_mode : str
var mimetype : str
var ext : str
var obj_type : ~T

Base class for schema wrappers.

Each derived class should set the _schema class attribute (and optionally the _rootschema class attribute) which is used for validation.

Methods

def write_file(self, f: , chart: altair.utils.schemapi.SchemaBase)
class PlotlyPlot

Creates a plotly graph from a figure object

Ancestors

Class variables

var block_type : Type[DataBlock]

Inherited from: PlotAsset.block_type

Plot blocks store a Python-based plot object, including ones created by Altair, Plotly, Matplotlib, Bokeh, and Folium, for interactive display in your …

var file_mode : str
var mimetype : str
var ext : str
var obj_type : ~T

Methods

def write_file(self, f: , chart: PFigure)
class FoliumPlot

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::

class Mapping(Generic[KT, VT]): def getitem(self, key: KT) -> VT: … # Etc.

This class can then be used as follows::

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default

Ancestors

Class variables

var block_type : Type[DataBlock]

Plot blocks store a Python-based plot object, including ones created by Altair, Plotly, Matplotlib, Bokeh, and Folium, for interactive display in your report when viewed in the browser.

var file_mode : str
var mimetype : str
var ext : str
var obj_type : ~T

Methods

def write_file(self, f: , m: Map)
class p

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::

class Mapping(Generic[KT, VT]): def getitem(self, key: KT) -> VT: … # Etc.

This class can then be used as follows::

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default

Ancestors

Class variables

var block_type : Type[DataBlock]

Inherited from: PlotAsset.block_type

Plot blocks store a Python-based plot object, including ones created by Altair, Plotly, Matplotlib, Bokeh, and Folium, for interactive display in your …

var file_mode : str
var mimetype : str
var ext : str
var obj_type : ~T

Methods

def write_file(self, f: , m: Map)