API Reference

class viur.scriptor.file.File(data: bytes, filename: str = None)

Represents an opened file or data. Used to open files from the user or build files for the user to download.

Parameters:
  • data – The bytes the file should contain.

  • filename – The name the file should have.

classmethod from_string(text: str, filename: str = 'text.txt')

creates a text-file from a string

Parameters:
  • textstring-content the file should have

  • filename – name the file should have

Returns:

File-object

classmethod from_bytes(data: bytes, filename: str = 'bytes.bin')

creates a binary file from bytes

Parameters:
  • databytes the file should contain

  • filename – name the file should have

Returns:

File-object

async classmethod from_url(url: str, filename: str | None = None)

downloads a file from a URL and wraps it in a File object

Parameters:
  • url – URL to download the file from

  • filename – name the file should have; if omitted, the filename is taken from the response

Returns:

File-object

classmethod from_table(table: list[list[str, ...]] | list[dict[str, str]], header: list[str] = None, filename: str = 'table.xlsx', fill_empty: bool = False, auto_str: bool = False, csv_delimiter=',')

creates a CSV- or XLSX-file containing a single table

Parameters:
  • table – table that should be saved: Either a list of lists or a list of dicts (one for each row)

  • header – (optional) header of the table, if table is a list of dicts, the header defines the order of columns

  • filename – name the file should have

  • fill_empty – if true, missing data is replaced by an empty string (this is primarily intended for testing and debugging)

  • auto_str – if true, all keys and values are automatically converted to str

  • csv_delimiter – the delimiter used to separate fields in csv-tables, ignored for xlsx

Returns:

File-object

get_filename()

returns the name of the file

Returns:

name of the file

get_size()

returns the size of the files data in bytes

Returns:

the size of the files data in bytes

as_bytes()

returns the content of the file as bytes

Returns:

file-data

as_text(encoding: str = None)

decodes the whole content of the file as a string and returns it

Parameters:

encoding – (optional) if set, the content of the file is decoded using this encoding, otherwise the encoding is automatically guessed

Returns:

content of the file as a string

as_object_from_json()

parses JSON-data to a python-object representing the decoded data of the json-file, throws an exception if the file is not a valid JSON-file

Returns:

python-object represented by the JSON-file

as_list_table(csv_delimiter=None)

loads tabular data (i.e. a csv- or xlsx-file) as a list of lists

Returns:

list of lists representing a table

as_dict_table(csv_delimiter=None)

loads tabular data (i.e. a csv- or xlsx-file) as a list of dicts

Returns:

list of dicts representing a table

async save_dialog(prompt: str = 'Please select a file to save to:')

asks the user where to save the file and saves it

Parameters:

prompt – (optional) the prompt the user will read

async classmethod open_dialog(prompt: str = 'Please select a file to open:', types: list[dict] = [])

asks the user for a file to open :param prompt: (optional) the prompt the user will read :param types: Types of files Example: types= [

{

“description”: “Images”, “accept”:{

“image/*”: [“.png”, “.gif”, “.jpeg”, “.jpg”],

},

}

] https://developer.mozilla.org/en-US/docs/Web/API/Window/showOpenFilePicker#examples :return: File-object

download()

downloads the file to the users download-directory

async upload(node: str = None, return_full_skel: bool = False) str | dict

Uploads this file to the ViUR file module.

Parameters:
  • node – Key of the target parent node (folder). Defaults to root.

  • return_full_skel – If True, returns the full file skeleton dict instead of just the upload key.

Returns:

The upload key (str) or the full file skeleton (dict) if return_full_skel is True.

class viur.scriptor.requests.WebRequest

provides methods to request data from HTTP-Servers

async classmethod get(url, params=None, headers=None, **kwargs)

handles HTTP-GET-requests

Parameters:
  • url – the URL of the endpoint

  • params – parameters of the request (for the query string)

  • headers – HTTP-headers to send with the request

  • kwargs – additional parametrs

Returns:

WebResponse

async classmethod download(url, **kwargs)

convenience-method for simple HTTP-GET-Reuests that don’t need parameters or headers

Parameters:
  • url – the URL of the endpoint

  • kwargs – additional parameters

Returns:

WebResponse

async classmethod post(url, data, params=None, headers=None, **kwargs)

handles HTTP-POST-requests

Parameters:
  • url – the URL of the endpoint

  • data – the data to send to the endpoint

  • params – parameters of the request

  • headers – HTTP-headers to send with the request

  • kwargs – additional parametrs

Returns:

WebResponse

async classmethod put(url, data, params=None, headers=None, **kwargs)

handles HTTP-PUT-requests

Parameters:
  • url – the URL of the endpoint

  • data – the data to send to the endpoint

  • params – parameters of the request

  • headers – HTTP-headers to send with the request

  • kwargs – additional parametrs

Returns:

WebResponse

async classmethod delete(url, params, data, headers, **kwargs)

handles HTTP-DELETE-requests

Parameters:
  • url – the URL of the endpoint

  • data – the data to send to the endpoint

  • parameters – parameters of the request

  • headers – HTTP-headers to send with the request

  • kwargs – additional parametrs

Returns:

WebResponse

async classmethod request(method: str, url, **kwargs)

handles general HTTP-requests

Parameters:
  • method – the method to use (GET, PUT, POST or DELETE)

  • url – the URL of the endpoint

  • kwargs – additional parameters

Returns:

WebResponse

class viur.scriptor.requests.WebResponse(url, http_status_code, content)

represents the result of a WebRequest, can have the requested content or information about errors.

get_url()

returns the url that was requested

Returns:

the url that was requested

get_status_code()

returns the HTTP-status-code returned from the server

Returns:

the HTTP-status-code

get_content()

returns the content of the HTTP-response

Returns:

the content of the HTTP-response

class viur.scriptor.dialog.Dialog
print(*, sep=' ', end='\n', file=None, flush=False)

displays Text

Parameters:
  • argsstring / objects that should be displayed.

  • sepstring inserted between values, default a space.

  • endstring appended after the last value, default a newline. ignored in browser.

  • file – a file-like object (stream); defaults to the current sys.stdout. ignored in browser.

  • flush – whether to forcibly flush the stream. ignored in browser.

async alert(image=None)

Shows a message to the user and blocks until it is confirmed.

Parameters:
  • text – The message to be displayed

  • image – displays an image in the alert-box

async raw_html(in_multiple: bool = False)

Shows preformatted html to the user.

Parameters:
  • html – the preformatted html as a string

  • in_multiple – If true only the config of the Dialog is returned

async select(title: str = None, text: str = None, multiselect: bool = False, image=None, default_value: list[str] | str = None, in_multiple: bool = False, show_values: bool = False)

Gives the user a choice between different options. If multiselect is False, only one selection is allowed, otherwise the user can select multiple options.

Parameters:
  • options – the selectable options

  • title – the title on top of the select-box

  • text – the text to be displayed

  • multiselect – if True, multiple options can be selected, otherwise only one

  • image – displays an image in the select-box

  • default_value – The default value for the options.

  • in_multiple – If true only the config of the Dialog is returned

  • show_values – If true the values show in the select-box

Returns:

a tuple of the selected options

async confirm(title: str = None, yes: str = 'Yes', no: str = 'No')

Asks the user to answer a Yes/No Question

Parameters:
  • title – the title on top of the confirm-box

  • text – the text to be displayed

  • yes – (optional) the word for ‘yes’

  • no – (optional) the word for ‘no’

Returns:

async text(title: str = 'Text Input', empty: bool = None, placeholder: str = None, image=None, multiline=False, default_value: str = None, in_multiple: bool = False)

prompts the user to enter text

Parameters:
  • prompt – the prompt the user will be shown

  • title – the title of the textbox

  • empty – allow the empty string as a valid result

  • image – displays an image in the text-box

  • placeholder – the placeholder-text to be displayed in the textbox while it is empty

  • multiline – enables multiline-input

  • default_value – optional default value

  • in_multiple – If true only the config of the Dialog is returned

Returns:

the text entered by the user

async number(title: str = 'Number Input', placeholder: str = None, image=None, default_value: int | float = None, in_multiple: bool = False)

prompts the user to input a number

Parameters:
  • prompt – the prompt the user will be shown

  • title – the title of the number-box

  • placeholder – the placeholder-text to be displayed in the box while it is empty

  • image – displays an image in the number-box

  • default_value – optional default value

  • in_multiple – If true only the config of the Dialog is returned

Returns:

the number the user entered

async date(use_time: bool = False, image=None, default_value: str | date | datetime = None, in_multiple: bool = False)

prompts the user to input a date

Parameters:
  • prompt – the prompt the user will be shown

  • use_time – also input time in addition to the date

  • image – displays an image in the date-box

  • default_value – optional default value

  • in_multiple – If true only the config of the Dialog is returned

Returns:

the date entered by the user

async table(rows: list[list[str]], select: bool = None, multiselect: bool = None, image=None)

displays a table

Parameters:
  • header – the header of the table

  • rows – the data of the tabel

  • select – if True, the user can select a row

  • multiselect – if True and select is True, the user can select multiple rows

  • image – displays an image in the table-box

Returns:

list of indices of selected items (if select is True)

async multiple(components: list[dict] | dict[str, dict], send_button_text: str, reuse: bool = False)

Shows multiple input components in a single dialog and waits for the user to submit them.

Each component is built by calling the corresponding Dialog-method with in_multiple=True (e.g. await Dialog.text(..., in_multiple=True)). The return value mirrors the structure of components: a list if components is a list, or a dict with the same keys if it is a dict.

Parameters:
  • title – heading displayed at the top of the dialog

  • components – input component configs as a list[dict] or dict[str, dict], built with in_multiple=True on Dialog.text, Dialog.number, Dialog.select, or Dialog.date

  • send_button_text – label of the submit button at the bottom of the dialog

  • reuse – if True, the component definitions are not re-sent to the browser; use this when showing the same dialog repeatedly in a loop

Returns:

user inputs as a list or dict, matching the structure of components

class viur.scriptor.progressbar.ProgressBar

Displays or updates a progress bar during long-running operations.

In the browser (Pyodide) context a visual progress bar is rendered in the UI. In the CLI context progress information is printed to stdout. Call ProgressBar.unset() when the operation is complete to hide the progress bar.

static set(percent: int = 0, current_step: int = -1, total_steps: int = -1, text: str = '')

displays a progressbar in the browser, prints progress-information in CLI

Parameters:
  • percent – the percentage of the process that is complete (a value between 0 and 100)

  • current_step – the number of completed steps

  • total_steps – the number of total steps

  • text – additional text to be displayed

static unset()

removes the progressbar, does nothing in CLI

class viur.scriptor.directory_handler.DirectoryHandler(directory_handle)
async classmethod open()

prompts the user to select a directory to work with.

Returns:

a DirectoryHandler for the selected directory

async list_files()

lists the files in the selected directory

Returns:

a list of all names of files present in the selected directory

async list_subdirs()

lists the subdirectories in the selected directory

Returns:

a list of all names of subdirectories present in the selected directory

async get_subdirectory_handler(dirname, create=False)

opens a subdirectory in a child-DirectoryHandler

Parameters:
  • dirname – the name of the subdirectory that should be opened

  • create – if set to true, the directory will be created if it doesn’t already exist

Returns:

DirectoryHandler for the subdirectory

async open_file_for_writing(filename: str, create: bool = True, may_already_exist: bool = False)

opens a file from the selected directory for writing. (the content is completely replaced if the file already existed)

Parameters:
  • filename – the name of the file to be written to

  • create – if the file should be created if it doesn’t already exist

  • may_already_exist – if the file may already exist

Returns:

a WritableFileFromDirectoryHandler representing the writable file

async close_all()

closes all open WritableFileFromDirectoryHandler originating from this DirectoryHandler and all of its child-DirectoryHandlers (after this, they can’t be written to anymore)

Intended to be called at the end of the script to make sure all files are correctly saved.

async write_to_file(data: bytes, filename: str, may_already_exist: bool = False)

writes data to a file in this directory

Parameters:
  • data – the data that should be the new content of the file

  • filename – the name of the file the data should be written to

  • may_already_exist – if the file may already exist and should be replaced

async read_from_file(filename: str, start: int = 0, end: int = None)

reads data from a file

Parameters:
  • filename – the name of the file data should be read from

  • start – the starting position in the file to read from

  • end – the end position in the file to read to

Returns:

the content of the file (or a part thereof) as bytes

class viur.scriptor.directory_handler.WritableFileFromDirectoryHandler(writable, parent, filename, file)
get_filename()

returns the name if the opened file

Returns:

the name of the opened file

async write(data: bytes)

writes data to the opened file

Parameters:

data – the data to write to the file

async close()

closes the file (data may not be persisted properly if the file isn’t closed)

class viur.scriptor.logger.Logger(name='scriptor')

The logger for the pyodide-context that logs to the browser.

log(level: str, msg: str, *args, **kwargs)

logs a message with the given log-level

Parameters:
  • level – log-level (debug, info, warning, error, critical or fatal)

  • msg – the message to be logged

  • args – additional arguments. ignored in browser.

  • kwargs – additional keyword-arguments. ignored in browser.

info(msg: str, *args, **kwargs)

logs a message with the log level ‘info’

Parameters:
  • msg – the message to be logged

  • args – additional arguments. ignored in browser.

  • kwargs – additional keyword-arguments. ignored in browser.

debug(msg: str, *args, **kwargs)

logs a message with the log level ‘debug’

Parameters:
  • msg – the message to be logged

  • args – additional arguments. ignored in browser.

  • kwargs – additional keyword-arguments. ignored in browser.

error(msg: str, *args, **kwargs)

logs a message with the log level ‘error’

Parameters:
  • msg – the message to be logged

  • args – additional arguments. ignored in browser.

  • kwargs – additional keyword-arguments. ignored in browser.

critical(msg: str, *args, **kwargs)

logs a message with the log level ‘critical’

Parameters:
  • msg – the message to be logged

  • args – additional arguments. ignored in browser.

  • kwargs – additional keyword-arguments. ignored in browser.

fatal(msg: str, *args, **kwargs)

logs a message with the log level ‘fatal’

Parameters:
  • msg – the message to be logged

  • args – additional arguments. ignored in browser.

  • kwargs – additional keyword-arguments. ignored in browser.

warn(msg: str, *args, **kwargs)

logs a message with the log level ‘warning’

Parameters:
  • msg – the message to be logged

  • args – additional arguments. ignored in browser.

  • kwargs – additional keyword-arguments. ignored in browser.

warning(msg: str, *args, **kwargs)

logs a message with the log level ‘warning’

Parameters:
  • msg – the message to be logged

  • args – additional arguments. ignored in browser.

  • kwargs – additional keyword-arguments. ignored in browser.

exception(msg: str, *args, exc_info: bool = True, **kwargs)

logs a message with the log level ‘fatal’.

the exc_info-argument is ignored in the browser.

Parameters:
  • msg – the message to be logged

  • args – additional arguments. ignored in browser.

  • exc_info – if true, exception information will be logged. ignored in browser.

  • kwargs – additional keyword-arguments. ignored in browser.

setLevel(level: str)

sets the minimal level of log-messages to be printed.

Parameters:

level – the minimal level of log-messages that should be printed.

class viur.scriptor.module.Modules(base_url: str, username: str = None, password: str = None, login_skey: str = None, cookies: str = None)

used to retrieve modules from the viur-backend

async get_module(module_name: str)

gets a modules from the viur-backend

Parameters:

module_name – the name of the module

Returns:

the module, either a TreeModule, a ListModule or a SingletonModule

get_base_url()

returns the base-url of the viur server

Returns:

the base-url of the viur server

async viur_request(method: str, url: str, params=None, renderer: str = None, raw: bool = False)

requests data from the viur server.

Parameters:
  • method – one of “GET”, “POST”, “PUT”, “DELETE”, “PATCH” or “SECURE_POST”

  • url – the url of the requested resource

  • params – additional parameters

  • renderer – the viur-renderer for the requested data

  • raw – if true the raw response will be returned

Returns:

the requested data renderd by the renderer

class viur.scriptor.module.ListModule(*args, **kwargs)

This class is not meant to be instantiated by the user. It is returned by module for any modules that have multiple independent records.

async preview(params: dict = None, group: str = '', **kwargs)

acts like add or edit, returns the same result, but doesn’t save data to the database

Parameters:
  • params – parameters to pass to the database

  • group – the group

  • kwargs – additional keyword-arguments

Returns:

the database-record that would have been created with structure- and error-information

async structure(group: str = '', **kwargs)

returns the structure of the database-model

Parameters:
  • group – applies group-specific modifiers to the structure

  • kwargs – additional keyword-arguments

Returns:

the structure of the database model

async view(key: str, group: str = '', **kwargs) dict

retrieves a single record from the database

Parameters:
  • key – the key of the databse record

  • group – filters result to only contain records belonging to that group and applies group-specific modifiers

  • kwargs – additional keyword-arguments

Returns:

the retrieved record

async edit(key: str = '', params: dict = None, group: str = '', **kwargs)

writes changes to a database-record

Parameters:
  • key – the key of the record to be edited

  • params – parameters to pass to the database

  • group – applied group-specific modifiers to the model

  • kwargs – additional keyword-arguments

Returns:

the edited database-record with structure- and error-information

async list(params: dict = None, group: str = '', limit: int = None, min_limit: int = None, **kwargs)

retrieves multiple records from the database (all if called without parameters)

Parameters:
  • params – parameters to pass to the database

  • group – the group the records belong to

  • limit – maximum amount of entries that should be fetched. Note: The amount of entries per request/batch must be specified as “limit” in the params.

  • min_limit – minimum amount of entries that should be fetched if batch size is larger there are more records.

  • kwargs – additional keyword-arguments

Returns:

an asynchronous generator yielding the retrieved records

async add(params: dict = None, group: str = '', **kwargs)

adds a record to the database

Parameters:
  • params – parameters to pass to the database

  • group – the group the records belong to

  • kwargs – additional keyword-arguments

Returns:

the new record

async delete(key: str, params: dict = None, **kwargs)

deletes a record from the database

Parameters:
  • key – the key of the record that will be deleted

  • params – parameters to pass to the database

  • kwargs – additional keyword-arguments

Returns:

True if the deletion was successful, otherwise raises an exception

property name: str

returns the name of the database-model

Returns:

the name of the database-model

class viur.scriptor.module.TreeModule(*args, **kwargs)

This class is not meant to be instantiated by the user. It is returned by module for modules that have records in a tree-structure.

async list_root_nodes(**kwargs)

return all root nodes (nodes without a parent)

Parameters:

kwargs – additional keyword-arguments

Returns:

list of dicts with the root-nodes names and keys

async move(key: str, parentNode: str, **kwargs)

moves a node to a new parent

Parameters:
  • key – the key of the record that will be moved

  • parentNode – the new parent the record will be moved to

  • kwargs – additional keyword-arguments

Returns:

the edited database-record with structure- and error-information

async for_each(callback: callable, root_node_key: str = None, params: dict = None, **kwargs)

retrieves records from the database, then calls a callback function on each of them

Parameters:
  • callback – the function to call on each retrieved record (parameters are skel_type and entry, both as keyword-arguments, callback may be sync or async)

  • root_node_key – the key of the root-node of which you want to iterate all children

  • params – parameters to pass to the database

  • kwargs – additional keyword-arguments

async preview(params: dict = None, skel_type: str = '', **kwargs)

acts like add or edit, returns the same result, but doesn’t save data to the database

Parameters:
  • params – parameters to pass to the database

  • skel_type – the skel_type of the record (either “node” or “leaf”)

  • kwargs – additional keyword-arguments

Returns:

the database-record that would have been created with structure- and error-information

async structure(skel_type: str = '', **kwargs)

returns the structure of the database-model

Parameters:
  • kwargs – additional keyword-arguments

  • skel_type – the skel_type (either “node” or “leaf”)

Returns:

the structure of the database model

async view(key: str, skel_type: str = '', **kwargs) dict

retrieves a single record from the database

Parameters:
  • key – the key of the databse record

  • skel_type – the skel_type of the record (either “node” or “leaf”)

  • kwargs – additional keyword-arguments

Returns:

the retrieved record

async edit(key: str = '', params: dict = None, skel_type: str = '', **kwargs)

writes changes to a database-record

Parameters:
  • key – the key of the record to be edited

  • params – parameters to pass to the database

  • skel_type – the skel_type of the record (either “node” or “leaf”)

  • kwargs – additional keyword-arguments

Returns:

the edited database-record with structure- and error-information

async list(params: dict = None, skel_type: str = '', limit: int = None, min_limit: int = None, **kwargs)

retrieves multiple records from the database (all if called without parameters)

Parameters:
  • params – parameters to pass to the database

  • skel_type – the skel_type of the record (either “node” or “leaf”)

  • limit – maximum amount of entries that should be fetched. Note: The amount of entries per request/batch must be specified as “limit” in the params.

  • min_limit – minimum amount of entries that should be fetched if batch size is larger there are more records.

  • kwargs – additional keyword-arguments

Returns:

an asynchronous generator yielding the retrieved records

async add(params: dict = None, skel_type: str = '', **kwargs)

adds a record to the database

Parameters:
  • params – parameters to pass to the database

  • skel_type – the skel_type of the record (either “node” or “leaf”)

  • kwargs – additional keyword-arguments

Returns:

the new record

async delete(key: str, params: dict = None, **kwargs)

deletes a record from the database

Parameters:
  • key – the key of the record that will be deleted

  • params – parameters to pass to the database

  • kwargs – additional keyword-arguments

Returns:

True if the deletion was successful, otherwise raises an exception

property name: str

returns the name of the database-model

Returns:

the name of the database-model

class viur.scriptor.module.SingletonModule(name: str, parent)

This class is not meant to be instantiated by the user. It is returned by module for modules of type “singleton”.

edit(params: dict = None, **kwargs)

saves changes to a record in the database

Parameters:
  • params – parameters to pass to the database

  • kwargs – additional keyword-arguments

Returns:

the edited database-record with structure- and error-information

async preview(params: dict = None, **kwargs)

acts like add or edit, returns the same result, but doesn’t save data to the database

Parameters:
  • params – parameters to pass to the database

  • kwargs – additional keyword-arguments

Returns:

the database-record that would have been created with structure- and error-information

async structure(**kwargs)

returns the structure of the database-model

Parameters:

kwargs – additional keyword-arguments

Returns:

the structure of the database model

async view(key: str, **kwargs) dict

retrieves a single record from the database

Parameters:
  • key – the key of the databse record

  • kwargs – additional keyword-arguments

Returns:

the retrieved record

property name: str

returns the name of the database-model

Returns:

the name of the database-model

viur.scriptor.export_import.export_to_excel(data, structure, filename='export.xlsx')

Converts data from the database into an Excel (.xlsx) File object.

Parameters:
  • data – list of records as returned by list()

  • structure – the module structure as returned by structure()

  • filename – name of the resulting file, must end in .xlsx (default: "export.xlsx")

Returns:

a File object containing the exported Excel data

Raises:

ValueError – if filename does not end with .xlsx

viur.scriptor.export_import.export_to_csv(data, structure, filename='export.csv', csv_delimiter=',')

Converts data from the database into a CSV File object.

Parameters:
  • data – list of records as returned by list()

  • structure – the module structure as returned by structure()

  • filename – name of the resulting file, must end in .csv (default: "export.csv")

  • csv_delimiter – column delimiter for CSV output (default: ",")

Returns:

a File object containing the exported CSV data

Raises:

ValueError – if filename does not end with .csv

viur.scriptor.export_import.export_to_json(data, structure, filename='export.json')

Converts data from the database into a JSON File object.

Parameters:
  • data – list of records as returned by list()

  • structure – the module structure as returned by structure()

  • filename – name of the resulting file (default: "export.json")

Returns:

a File object containing the exported JSON data (pretty-printed, keys sorted)

async viur.scriptor.export_import.export_module(name='', filename='export.json', csv_delimiter=',')

Exports all records of a ViUR module into a File object.

Fetches all records from the module and exports them into the format determined by the filename extension: .json, .xlsx, or .csv.

Parameters:
  • name – name of the module to export

  • filename – name of the resulting file including the extension (default: "export.json")

  • csv_delimiter – column delimiter when exporting as CSV (default: ",")

Returns:

a File object containing all exported records

Raises:

NotImplementedError – if the file extension is not .json, .xlsx, or .csv

viur.scriptor.export_import.filter_module_structure_with_withelist(structure, whitelist)

Returns a copy of structure that only contains bones listed in whitelist.

Use this to restrict an export or import to a specific subset of fields.

Parameters:
  • structure – the module structure as returned by structure()

  • whitelist – list of bone names to keep

Returns:

a filtered copy of structure

viur.scriptor.export_import.filter_module_structure_with_blacklist(structure, blacklist)

Returns a copy of structure with all bones listed in blacklist removed.

Use this to exclude specific fields from an export or import.

Parameters:
  • structure – the module structure as returned by structure()

  • blacklist – list of bone names to remove

Returns:

a filtered copy of structure

async viur.scriptor.export_import.import_from_table(table_as_dicts, module, structure=None, *, add_or_edit_mode: Literal['edit', 'add_or_edit', 'add'] = 'edit', tree_skel_type=None, dry_run=False, progress_callback=None, query_params_callback=None, server_result_callback=None, exception_callback=None)

Imports records from a table (e.g. from a CSV or Excel file) into a ViUR module.

Each row of table_as_dicts is written to the module using edit, add_or_edit, or add, depending on add_or_edit_mode. The table columns must match the bone names of the module’s structure (as exported by export_to_table or export_to_csv).

Parameters:
  • table_as_dicts – iterable of dicts, each representing one row (e.g. from File.to_table())

  • module – the module to import into (a ListModule, TreeModule, etc.)

  • structure – the module structure as returned by structure(); fetched automatically if omitted

  • add_or_edit_mode – one of "edit" (default), "add_or_edit", or "add"

  • tree_skel_type – required for TreeModule; either "leaf" or "node"

  • dry_run – if True, the data is processed but not written to the database

  • progress_callback – called with index and total keyword arguments before each record

  • query_params_callback – called with the prepared request params dict before each request

  • server_result_callback – called with the server’s response dict after each request

  • exception_callback – called with (exception, params) when a request raises an exception

Raises:

ValueError – if tree_skel_type is missing or invalid for a TreeModule

class viur.scriptor.message.Message

Sends system messages to the user interface.

In the browser (Pyodide) context a toast-style notification is displayed. In the CLI context the message is printed to stdout.

static send(type: str = 'success', title: str = '', text: str = '')

Shows a message to the user. :param type: The type of message to send. :param title: The title of message to be displayed :param text: The message to be displayed

viur.scriptor.utils.extract_items(data: list[...] | dict[...], selectors: list[str | int | EllipsisType, ...], join_with: str = None)

extracts items from a data-structure using a list of selectors

Parameters:
  • data – the data to extract from

  • selectors – the selectors to extract the data

  • join_with – the string with which items should be joined

Returns:

extracted data

viur.scriptor.utils.map_extract_items(data: list[...] | dict[...], selector_mapping: dict[str, list[str | int | EllipsisType, ...]], join_with: str = None)

extracts items from a data-structure using a mapping of lists of selectors

Parameters:
  • data – the data to extract from (a dict or a list of dicts)

  • selector_mapping – the selector-mapping to extract the data

  • join_with – the string with which items should be joined

Returns:

a dictionary of the extracted data