Skip to main content

Module h2o_wave.core

Functions

clone_expando

def clone_expando(source: Expando, exclude_keys: Union[list, tuple, None] = None, include_keys: Union[list, tuple, None] = None) ‑> Expando

Clone an expando instance. Creates a shallow clone.

Args
source
The expando to clone.
exclude_keys
Keys to exclude while cloning.
include_keys
Keys to include while cloning.
Returns

The expando clone.

copy_expando

def copy_expando(source: Expando, target: Expando, exclude_keys: Union[list, tuple, None] = None, include_keys: Union[list, tuple, None] = None) ‑> Expando

Copy all entries from the source expando instance to the target expando instance.

Args
source
The expando to copy from.
target
The expando to copy to.
exclude_keys
Keys to exclude while copying.
include_keys
Keys to include while copying.
Returns

The target expando.

data

def data(fields: Union[str, tuple, list], size: int = 0, rows: Union[dict, list, None] = None, columns: Union[dict, list, None] = None, pack=False, t: Optional[str] = None) ‑> Union[Data, str]

Create a Data instance for associating data with cards.

data()(fields, size) creates a placeholder for data and allocates memory on the Wave server.

data()(fields, size, rows) creates a placeholder and initializes it with the provided rows.

If pack() is True, the size parameter is ignored, and the function returns a packed string representing the data.

Args
fields
The names of the fields (columns names) in the data, either a list or tuple or string containing space-separated names.
size
The number of rows to allocate memory for. Positive for fixed buffers, negative for cyclic buffers and zero for variable length buffers.
rows
The rows in this data.
columns
The columns in this data.
pack
True to return a packed string representing the data instead of a Data placeholder.
t
Buffer type. One of 'list', 'map', 'cyclic' or 'fixed'. Overrides the buffer type inferred from the size.
Returns

Either a Data placeholder or a packed string representing the data.

expando_to_dict

def expando_to_dict(e: Expando) ‑> dict

Extract an expando's underlying dictionary. Any modifications to the dictionary also affect the original expando.

Args
e
The expando instance.
Returns

The expando's dictionary.

marshal

def marshal(d: Any) ‑> str

Marshal to JSON.

Args
d
Any object or value.
Returns

A string containing the JSON-serialized form.

pack

def pack(data: Any) ‑> str

Pack (compress) the provided value.

Args
data
Any object or value.

The object or value compressed into a string.

unmarshal

def unmarshal(s: str) ‑> Any

Unmarshal a JSON string.

Args
s
A string containing JSON-serialized data.
Returns

The deserialized object or value.

Classes

AsyncPage

class AsyncPage(site: AsyncSite, url: str)

Represents a reference to a remote Wave page. Similar to Page except that this class exposes async methods.

Args
site
The parent site.
url
The URL of this page.

Methods

load

async def load(self) ‑> dict

Retrieve the serialized form of this page from the remote site.

Returns

The serialized form of this page

save

async def save(self)

Save the page. Sends all local changes made to this page to the remote site.

Ancestors

Inherited members

AsyncSite

class AsyncSite

Represents a reference to the remote Wave site. Similar to Site except that this class exposes async methods.

Methods

download

async def download(self, url: str, path: str) ‑> str

Download a file from the site.

Args
url
The URL of the file.
path
The local directory or file path to download to. If a directory is provided, the original name of the file is retained.
Returns

The path to the downloaded file.

load

async def load(self, url) ‑> dict

Retrieve data at the given URL, typically the serialized form of a page.

Args
url
The URL to read.
Returns

The serialized page.

proxy

async def proxy(self, method: str, url: str, headers: Optional[Dict[str, List[str]]] = None, body: Optional[str] = None)
async def unlink(self, path: str)

Signal the end of a stream.

Args
path
The path of the stream

unload

async def unload(self, url: str)

Delete an uploaded file from the site.

Args
url
The URL of the file to delete.
async def uplink(self, path: str, content_type: str, file: Union[IO[str], IO[bytes], str, bytes]) ‑> str

Create or update a stream of images.

The typical use of this function is to transmit a stream of images to a web page, providing the appearance of a video. The path returned by this function can be passed to ui.image() or ui.image_card() (or even a custom HTML img element). The stream is displayed in browsers using multipart/x-mixed-replace content. Callers must call the unlink() function to signal end-of-stream.

Args
path
a unique path or name for the stream (e.g. 'foo/bar/qux.png'). Must be a valid URL path.
content_type
The MIME type of the streamed content (e.g. 'image/jpeg', 'image/png', etc.).
file
A file or file-like object (on-disk file, standard I/O, in-memory buffers, sockets or pipes).
Returns

The stream endpoint, typically used as an image path.

upload

async def upload(self, files: List[str]) ‑> List[str]

Upload local files to the site.

Args
files
A list of file paths of the files to be uploaded.
Returns

A list of remote URLs for the uploaded files, in order.

upload_dir

async def upload_dir(self, directory: str) ‑> str

WARNING: Experimental and subject to change. Upload whole directory to the site with directory structure preserved.

Args
directory
Folder to be uploaded.
Returns

A list of remote URLs for the uploaded directory (always size of 1).

Data

class Data(fields: Union[str, tuple, list], size: int = 0, data: Union[dict, list, None] = None, t: Optional[str] = None)

Represents a data placeholder. A data placeholder is used to allocate memory on the Wave server to store data.

Args
fields
The names of the fields (columns names) in the data, either a list or tuple or string containing space-separated names.
size
The number of rows to allocate memory for. Positive for fixed buffers, negative for cyclic buffers and zero for variable length buffers.
data
Initial data. Must be either a key-row dict for variable-length buffers OR a row list for fixed-size and cyclic buffers.
t
Buffer type. One of 'list', 'map', 'cyclic' or 'fixed'. Overrides the buffer type inferred from the size.

Methods

dump

def dump(self)

Expando

class Expando(args: Optional[Dict[~KT, ~VT]] = None)

Represents an object whose members (attributes) can be dynamically added and removed at run time.

Args
args
An optional dict of attribute-value pairs to initialize the expando instance with.

Page

class Page(site: Site, url: str)

Represents a reference to a remote Wave page.

Args
site
The parent site.
url
The URL of this page.

Methods

load

def load(self) ‑> dict

Retrieve the serialized form of this page from the remote site.

Returns

The serialized form of this page

save

def save(self)

Save the page. Sends all local changes made to this page to the remote site.

Ancestors

Inherited members

PageBase

class PageBase(url: str)

Represents a remote page.

Args
url
The URL of the remote page.

Methods

add

def add(self, key: str, card: Any) ‑> Ref

Add a card to this page.

Args
key
The card's key. Must uniquely identify the card on the page. Overwrites any other card with the same key.
card
A card. Use one of the ui.*_card() to create cards.
Returns

A reference to the added card.

drop

def drop(self)

Delete this page from the remote site. Same as del site[url].

Subclasses

Ref

class Ref(page: PageBase, key: str)

Represents a local reference to an element on a Page. Any changes made to this local reference are tracked and sent to the remote Wave server when the page is saved.

ServiceError

class ServiceError(*args, **kwargs)

Common base class for all non-exit exceptions.

Ancestors

  • builtins.Exception
  • builtins.BaseException

Site

class Site

Represents a reference to the remote Wave site. A Site instance is used to obtain references to the site's pages.

Methods

download

def download(self, url: str, path: str) ‑> str

Download a file from the site.

Args
url
The URL of the file.
path
The local directory or file path to download to. If a directory is provided, the original name of the file is retained.
Returns

The path to the downloaded file.

load

def load(self, url) ‑> dict

Retrieve data at the given URL, typically the serialized form of a page.

Args
url
The URL to read.
Returns

The serialized page.

proxy

def proxy(self, method: str, url: str, headers: Optional[Dict[str, List[str]]] = None, body: Optional[str] = None)
def unlink(self, path: str)

Signal the end of a stream.

Args
path
The path of the stream

unload

def unload(self, url: str)

Delete an uploaded file from the site.

Args
url
The URL of the file to delete.
def uplink(self, path: str, content_type: str, file: Union[IO[str], IO[bytes], str, bytes]) ‑> str

Create or update a stream of images.

The typical use of this function is to transmit a stream of images to a web page, providing the appearance of a video. The path returned by this function can be passed to ui.image() or ui.image_card() (or even a custom HTML img element). The stream is displayed in browsers using multipart/x-mixed-replace content. Callers must call the unlink() function to signal end-of-stream.

Args
path
a unique path or name for the stream (e.g. 'foo/bar/qux.png'). Must be a valid URL path.
content_type
The MIME type of the streamed content (e.g. 'image/jpeg', 'image/png', etc.).
file
A file or file-like object (on-disk file, standard I/O, in-memory buffers, sockets or pipes).
Returns

The stream endpoint, typically used as an image path.

upload

def upload(self, files: List[str]) ‑> List[str]

Upload local files to the site.

Args
files
A list of file paths of the files to be uploaded..
Returns

A list of remote URLs for the uploaded files, in order.

upload_dir

def upload_dir(self, directory: str) ‑> str

WARNING: Experimental and subject to change. Upload whole directory to the site with directory structure preserved.

Args
directory
Folder to be uploaded.
Returns

A list of remote URLs for the uploaded directory (always size of 1).