Struct perspective_python::Client

source ·
pub struct Client(/* private fields */);
Expand description

An instance of a Client is a unique connection to a single perspective_server::Server, whether locally in-memory or remote over some transport like a WebSocket.

The examples in this module are in JavaScript. See perspective docs for the Rust API.

The browser and node.js libraries both support the websocket(url) constructor, which connects to a remote perspective_server::Server instance over a WebSocket transport.

In the browser, the worker() constructor creates a new Web Worker perspective_server::Server and returns a Client connected to it.

In node.js, a pre-instantied Client connected synhronously to a global singleton perspective_server::Server is the default module export.

§JavaScript Examples

Create a Web Worker perspective_server::Server in the browser and return a Client instance connected for it:

import perspective from "@finos/perspective";
const client = await perspective.worker();

Create a WebSocket connection to a remote perspective_server::Server:

import perspective from "@finos/perspective";
const client = await perspective.websocket("ws://locahost:8080/ws");

Access the synchronous client in node.js:

import { default as client } from "@finos/perspective";
The examples in this module are in Python. See perspective docs for the Rust API.

§Python Examples

Create a perspective_server::Server and a local, synchronous Client instance connected for it:

import perspective;
server = perspective.Server()
client = server.new_local_client();

§Examples

Create a perspective_server::Server and a synchronous Client via the perspective crate:

use perspective::server::Server;
use perspective::LocalClient;

let server = Server::default();
let client = perspective::LocalClient::new(&server);

Implementations§

source§

impl Client

source

pub fn new(callback: Py<PyAny>) -> PyResult<Self>

source

pub fn handle_response( &self, py: Python<'_>, response: Py<PyBytes>, ) -> PyResult<bool>

source

pub fn table( &self, py: Python<'_>, input: Py<PyAny>, limit: Option<u32>, index: Option<Py<PyString>>, name: Option<Py<PyString>>, ) -> PyResult<Table>

Creates a new Table from either a schema or data.

The Client::table factory function can be initialized with either a schema (see Table::schema), or data in one of these formats:

  • Apache Arrow
  • CSV
  • JSON row-oriented
  • JSON column-oriented

When instantiated with data, the schema is inferred from this data. While this is convenient, inferrence is sometimes imperfect e.g. when the input is empty, null or ambiguous. For these cases, Client::table can first be instantiated with a explicit schema.

When instantiated with a schema, the resulting Table is empty but with known column names and column types. When subsqeuently populated with Table::update, these columns will be coerced to the schema’s type. This behavior can be useful when Client::table’s column type inferences doesn’t work.

The resulting Table is virtual, and invoking its methods dispatches events to the perspective_server::Server this Client connects to, where the data is stored and all calculation occurs.

§Arguments
  • arg - Either schema or initialization data.
  • options - Optional configuration which provides one of:
    • limit - The max number of rows the resulting Table can store.
    • index - The column name to use as an index column. If this Table is being instantiated by data, this column name must be present in the data.
    • name - The name of the table. This will be generated if it is not provided.
§JavaScript Examples

Load a CSV from a string:

const table = await client.table("x,y\n1,2\n3,4");

Load an Arrow from an ArrayBuffer:

import * as fs from "node:fs/promises";
const table2 = await client.table(await fs.readFile("superstore.arrow"));

Create a table with an index:

const table = await client.table(data, { index: "Row ID" });
§Python Examples

Load a CSV from a str:

table = client.table("x,y\n1,2\n3,4")
§Examples

Load a CSV from a String:

let opts = TableInitOptions::default();
let data = TableData::Update(UpdateData::Csv("x,y\n1,2\n3,4".into()));
let table = client.table(data, opts).await?;
source

pub fn open_table(&self, name: String) -> PyResult<Table>

Opens a Table that is hosted on the perspective_server::Server that is connected to this Client.

The name property of TableInitOptions is used to identify each Table. Table names can be looked up for each Client via Client::get_hosted_table_names.

§JavaScript Examples

Get a virtual Table named “table_one” from this Client

const tables = await client.open_table("table_one");
§Python Examples
tables = client.open_table("table_one");
§Examples
let tables = client.open_table("table_one").await;
source

pub fn get_hosted_table_names(&self) -> PyResult<Vec<String>>

Retrieves the names of all tables that this client has access to.

name is a string identifier unique to the Table (per Client), which can be used in conjunction with Client::open_table to get a Table instance without the use of Client::table constructor directly (e.g., one created by another Client).

§JavaScript Examples
const tables = await client.get_hosted_table_names();
§Python Examples
tables = client.get_hosted_table_names();
§Examples
let tables = client.get_hosted_table_names().await;
source

pub fn set_loop_callback(&self, loop_cb: Py<PyAny>) -> PyResult<()>

Methods such as View::on_update take a callback function as an argument, which may be invoked by the Perspective runtime when updates occur. If provided a loop callback function via Client::set_loop_callback, such callback function invocations be passed to the loop callback instead.

Client::set_loop_callback can be used to control scheduling/conflation (e.g. by adding a delay), as well as executor integration.

Trait Implementations§

source§

impl HasPyGilRef for Client

§

type AsRefTarget = PyCell<Client>

Utility type to make Py::as_ref work.
source§

impl IntoPy<Py<PyAny>> for Client

source§

fn into_py(self, py: Python<'_>) -> PyObject

Performs the conversion.
source§

impl PyClass for Client

§

type Frozen = False

Whether the pyclass is frozen. Read more
source§

impl PyClassImpl for Client

source§

const IS_BASETYPE: bool = true

#[pyclass(subclass)]
source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
§

type BaseType = PyAny

Base class
§

type ThreadChecker = SendablePyClass<Client>

This handles following two situations: Read more
§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
source§

fn items_iter() -> PyClassItemsIter

source§

fn doc(py: Python<'_>) -> PyResult<&'static CStr>

Rendered class doc
source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

source§

fn dict_offset() -> Option<isize>

source§

fn weaklist_offset() -> Option<isize>

source§

impl PyClassNewTextSignature<Client> for PyClassImplCollector<Client>

source§

fn new_text_signature(self) -> Option<&'static str>

source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a Client

§

type Holder = Option<PyRef<'py, Client>>

source§

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder, ) -> PyResult<Self>

source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut Client

§

type Holder = Option<PyRefMut<'py, Client>>

source§

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder, ) -> PyResult<Self>

source§

impl PyMethods<Client> for PyClassImplCollector<Client>

source§

fn py_methods(self) -> &'static PyClassItems

source§

impl PyTypeInfo for Client

source§

const NAME: &'static str = "Client"

Class name.
source§

const MODULE: Option<&'static str> = ::core::option::Option::None

Module name, if any.
source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
source§

fn type_object(py: Python<'_>) -> &PyType

👎Deprecated since 0.21.0: PyTypeInfo::type_object will be replaced by PyTypeInfo::type_object_bound in a future PyO3 version
Returns the safe abstraction over the type object.
source§

fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.
source§

fn is_type_of(object: &PyAny) -> bool

👎Deprecated since 0.21.0: PyTypeInfo::is_type_of will be replaced by PyTypeInfo::is_type_of_bound in a future PyO3 version
Checks if object is an instance of this type or a subclass of this type.
source§

fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.
source§

fn is_exact_type_of(object: &PyAny) -> bool

👎Deprecated since 0.21.0: PyTypeInfo::is_exact_type_of will be replaced by PyTypeInfo::is_exact_type_of_bound in a future PyO3 version
Checks if object is an instance of this type.
source§

fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.
source§

impl DerefToPyAny for Client

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> PyErrArguments for T
where T: IntoPy<Py<PyAny>> + Send + Sync,

source§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
source§

impl<T> PyTypeCheck for T
where T: PyTypeInfo,

source§

const NAME: &'static str = <T as PyTypeInfo>::NAME

Name of self. This is used in error messages, for example.
source§

fn type_check(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of Self, which may include a subtype. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> Ungil for T
where T: Send,