perspective-python 3.7.2__tar.gz → 3.7.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {perspective_python-3.7.2 → perspective_python-3.7.4}/Cargo.toml +3 -3
- {perspective_python-3.7.2 → perspective_python-3.7.4}/LICENSE_THIRDPARTY_cargo.yml +2 -2
- {perspective_python-3.7.2 → perspective_python-3.7.4}/PKG-INFO +1 -1
- {perspective_python-3.7.2 → perspective_python-3.7.4}/docs/lib.md +3 -174
- {perspective_python-3.7.2 → perspective_python-3.7.4}/package.json +1 -1
- perspective_python-3.7.4/perspective/__init__.py +392 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/handlers/tornado.py +95 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/multi_threaded/test_multi_threaded.py +18 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/widget/__init__.py +63 -0
- {perspective_python-3.7.2/perspective_python-3.7.2.data → perspective_python-3.7.4/perspective_python-3.7.4.data}/data/share/jupyter/labextensions/@finos/perspective-jupyterlab/package.json +2 -2
- perspective_python-3.7.4/perspective_python-3.7.4.data/data/share/jupyter/labextensions/@finos/perspective-jupyterlab/static/253.43f556e31ec8de4307a2.js +16 -0
- perspective_python-3.7.2/perspective_python-3.7.2.data/data/share/jupyter/labextensions/@finos/perspective-jupyterlab/static/remoteEntry.6c620635cc748d645b1d.js → perspective_python-3.7.4/perspective_python-3.7.4.data/data/share/jupyter/labextensions/@finos/perspective-jupyterlab/static/remoteEntry.dde85a45c0ee7558f793.js +1 -1
- {perspective_python-3.7.2 → perspective_python-3.7.4}/pyproject.toml +1 -1
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/client/client_async.rs +24 -3
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/client/client_sync.rs +21 -1
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/client/table_data.rs +2 -1
- perspective_python-3.7.2/perspective/__init__.py +0 -70
- perspective_python-3.7.2/perspective_python-3.7.2.data/data/share/jupyter/labextensions/@finos/perspective-jupyterlab/static/253.bd5b70fcb9496ba1b887.js +0 -16
- {perspective_python-3.7.2 → perspective_python-3.7.4}/LICENSE.md +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/README.md +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/build.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/docs/index.html +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/extension/finos-perspective-nbextension.json +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/handlers/__init__.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/handlers/aiohttp.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/handlers/starlette.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/templates/exported_widget.html.template +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/__init__.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/async/test_async_client.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/async/test_websocket_client.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/conftest.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/core/__init__.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/core/test_async.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/multi_threaded/__init__.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/server/__init__.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/server/test_server.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/server/test_session.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/__init__.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/arrow/date32.arrow +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/arrow/date64.arrow +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/arrow/dict.arrow +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/arrow/dict_update.arrow +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/arrow/int_float_str.arrow +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/arrow/int_float_str_file.arrow +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/arrow/int_float_str_update.arrow +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/object_sequence.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_delete.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_exception.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_leaks.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_ports.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_remove.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_table.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_table_arrow.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_table_datetime.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_table_infer.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_table_limit.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_table_numpy.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_table_pandas.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_table_polars.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_to_arrow.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_to_arrow_lz4.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_to_format.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_to_polars.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_update.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_update_arrow.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_update_pandas.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_view.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/table/test_view_expression.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/test_dependencies.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/viewer/__init__.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/viewer/test_viewer.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/widget/__init__.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/widget/test_widget.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/tests/widget/test_widget_pandas.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/widget/viewer/__init__.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/widget/viewer/validate.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/widget/viewer/viewer.py +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/perspective/widget/viewer/viewer_traitlets.py +0 -0
- {perspective_python-3.7.2/perspective_python-3.7.2.data → perspective_python-3.7.4/perspective_python-3.7.4.data}/data/share/jupyter/labextensions/@finos/perspective-jupyterlab/install.json +0 -0
- /perspective_python-3.7.2/perspective_python-3.7.2.data/data/share/jupyter/labextensions/@finos/perspective-jupyterlab/static/253.bd5b70fcb9496ba1b887.js.LICENSE.txt → /perspective_python-3.7.4/perspective_python-3.7.4.data/data/share/jupyter/labextensions/@finos/perspective-jupyterlab/static/253.43f556e31ec8de4307a2.js.LICENSE.txt +0 -0
- {perspective_python-3.7.2/perspective_python-3.7.2.data → perspective_python-3.7.4/perspective_python-3.7.4.data}/data/share/jupyter/labextensions/@finos/perspective-jupyterlab/static/815.de1b4b53d57212354a6c.js +0 -0
- {perspective_python-3.7.2/perspective_python-3.7.2.data → perspective_python-3.7.4/perspective_python-3.7.4.data}/data/share/jupyter/labextensions/@finos/perspective-jupyterlab/static/style.js +0 -0
- {perspective_python-3.7.2/perspective_python-3.7.2.data → perspective_python-3.7.4/perspective_python-3.7.4.data}/data/share/jupyter/labextensions/@finos/perspective-jupyterlab/static/third-party-licenses.json +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/client/mod.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/client/pandas.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/client/polars.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/client/proxy_session.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/client/pyarrow.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/client/update_data.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/lib.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/py_async.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/py_err.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/server/mod.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/server/server_async.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/server/server_sync.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/server/session_async.rs +0 -0
- {perspective_python-3.7.2 → perspective_python-3.7.4}/src/server/session_sync.rs +0 -0
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
[package]
|
|
14
14
|
name = "perspective-python"
|
|
15
|
-
version = "3.7.
|
|
15
|
+
version = "3.7.4"
|
|
16
16
|
edition = "2024"
|
|
17
17
|
description = "A data visualization and analytics component, especially well-suited for large and/or streaming datasets."
|
|
18
18
|
repository = "https://github.com/finos/perspective"
|
|
@@ -57,8 +57,8 @@ pyo3-build-config = "0.22.6"
|
|
|
57
57
|
python-config-rs = "0.1.2"
|
|
58
58
|
|
|
59
59
|
[dependencies]
|
|
60
|
-
perspective-client = { version = "3.7.
|
|
61
|
-
perspective-server = { version = "3.7.
|
|
60
|
+
perspective-client = { version = "3.7.4" }
|
|
61
|
+
perspective-server = { version = "3.7.4" }
|
|
62
62
|
macro_rules_attribute = "0.2.0"
|
|
63
63
|
async-lock = "2.5.0"
|
|
64
64
|
pollster = "0.3.0"
|
|
@@ -2911,14 +2911,14 @@ third_party_libraries:
|
|
|
2911
2911
|
|
|
2912
2912
|
END OF TERMS AND CONDITIONS
|
|
2913
2913
|
- package_name: perspective-client
|
|
2914
|
-
package_version: 3.7.
|
|
2914
|
+
package_version: 3.7.4
|
|
2915
2915
|
repository: https://github.com/finos/perspective
|
|
2916
2916
|
license: Apache-2.0
|
|
2917
2917
|
licenses:
|
|
2918
2918
|
- license: Apache-2.0
|
|
2919
2919
|
text: "# Apache License\n\n_Version 2.0, January 2004_ \n_<<http://www.apache.org/licenses/>>_\n\n### Terms and Conditions for use, reproduction, and distribution\n\n#### 1. Definitions\n\n“License” shall mean the terms and conditions for use, reproduction, and\ndistribution as defined by Sections 1 through 9 of this document.\n\n“Licensor” shall mean the copyright owner or entity authorized by the copyright\nowner that is granting the License.\n\n“Legal Entity” shall mean the union of the acting entity and all other entities\nthat control, are controlled by, or are under common control with that entity.\nFor the purposes of this definition, “control” means **(i)** the power, direct or\nindirect, to cause the direction or management of such entity, whether by\ncontract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the\noutstanding shares, or **(iii)** beneficial ownership of such entity.\n\n“You” (or “Your”) shall mean an individual or Legal Entity exercising\npermissions granted by this License.\n\n“Source” form shall mean the preferred form for making modifications, including\nbut not limited to software source code, documentation source, and configuration\nfiles.\n\n“Object” form shall mean any form resulting from mechanical transformation or\ntranslation of a Source form, including but not limited to compiled object code,\ngenerated documentation, and conversions to other media types.\n\n“Work” shall mean the work of authorship, whether in Source or Object form, made\navailable under the License, as indicated by a copyright notice that is included\nin or attached to the work (an example is provided in the Appendix below).\n\n“Derivative Works” shall mean any work, whether in Source or Object form, that\nis based on (or derived from) the Work and for which the editorial revisions,\nannotations, elaborations, or other modifications represent, as a whole, an\noriginal work of authorship. For the purposes of this License, Derivative Works\nshall not include works that remain separable from, or merely link (or bind by\nname) to the interfaces of, the Work and Derivative Works thereof.\n\n“Contribution” shall mean any work of authorship, including the original version\nof the Work and any modifications or additions to that Work or Derivative Works\nthereof, that is intentionally submitted to Licensor for inclusion in the Work\nby the copyright owner or by an individual or Legal Entity authorized to submit\non behalf of the copyright owner. For the purposes of this definition,\n“submitted” means any form of electronic, verbal, or written communication sent\nto the Licensor or its representatives, including but not limited to\ncommunication on electronic mailing lists, source code control systems, and\nissue tracking systems that are managed by, or on behalf of, the Licensor for\nthe purpose of discussing and improving the Work, but excluding communication\nthat is conspicuously marked or otherwise designated in writing by the copyright\nowner as “Not a Contribution.”\n\n“Contributor” shall mean Licensor and any individual or Legal Entity on behalf\nof whom a Contribution has been received by Licensor and subsequently\nincorporated within the Work.\n\n#### 2. Grant of Copyright License\n\nSubject to the terms and conditions of this License, each Contributor hereby\ngrants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,\nirrevocable copyright license to reproduce, prepare Derivative Works of,\npublicly display, publicly perform, sublicense, and distribute the Work and such\nDerivative Works in Source or Object form.\n\n#### 3. Grant of Patent License\n\nSubject to the terms and conditions of this License, each Contributor hereby\ngrants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,\nirrevocable (except as stated in this section) patent license to make, have\nmade, use, offer to sell, sell, import, and otherwise transfer the Work, where\nsuch license applies only to those patent claims licensable by such Contributor\nthat are necessarily infringed by their Contribution(s) alone or by combination\nof their Contribution(s) with the Work to which such Contribution(s) was\nsubmitted. If You institute patent litigation against any entity (including a\ncross-claim or counterclaim in a lawsuit) alleging that the Work or a\nContribution incorporated within the Work constitutes direct or contributory\npatent infringement, then any patent licenses granted to You under this License\nfor that Work shall terminate as of the date such litigation is filed.\n\n#### 4. Redistribution\n\nYou may reproduce and distribute copies of the Work or Derivative Works thereof\nin any medium, with or without modifications, and in Source or Object form,\nprovided that You meet the following conditions:\n\n- **(a)** You must give any other recipients of the Work or Derivative Works a copy of\n this License; and\n- **(b)** You must cause any modified files to carry prominent notices stating that You\n changed the files; and\n- **(c)** You must retain, in the Source form of any Derivative Works that You distribute,\n all copyright, patent, trademark, and attribution notices from the Source form\n of the Work, excluding those notices that do not pertain to any part of the\n Derivative Works; and\n- **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any\n Derivative Works that You distribute must include a readable copy of the\n attribution notices contained within such NOTICE file, excluding those notices\n that do not pertain to any part of the Derivative Works, in at least one of the\n following places: within a NOTICE text file distributed as part of the\n Derivative Works; within the Source form or documentation, if provided along\n with the Derivative Works; or, within a display generated by the Derivative\n Works, if and wherever such third-party notices normally appear. The contents of\n the NOTICE file are for informational purposes only and do not modify the\n License. You may add Your own attribution notices within Derivative Works that\n You distribute, alongside or as an addendum to the NOTICE text from the Work,\n provided that such additional attribution notices cannot be construed as\n modifying the License.\n\nYou may add Your own copyright statement to Your modifications and may provide\nadditional or different license terms and conditions for use, reproduction, or\ndistribution of Your modifications, or for any such Derivative Works as a whole,\nprovided Your use, reproduction, and distribution of the Work otherwise complies\nwith the conditions stated in this License.\n\n#### 5. Submission of Contributions\n\nUnless You explicitly state otherwise, any Contribution intentionally submitted\nfor inclusion in the Work by You to the Licensor shall be under the terms and\nconditions of this License, without any additional terms or conditions.\nNotwithstanding the above, nothing herein shall supersede or modify the terms of\nany separate license agreement you may have executed with Licensor regarding\nsuch Contributions.\n\n#### 6. Trademarks\n\nThis License does not grant permission to use the trade names, trademarks,\nservice marks, or product names of the Licensor, except as required for\nreasonable and customary use in describing the origin of the Work and\nreproducing the content of the NOTICE file.\n\n#### 7. Disclaimer of Warranty\n\nUnless required by applicable law or agreed to in writing, Licensor provides the\nWork (and each Contributor provides its Contributions) on an “AS IS” BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,\nincluding, without limitation, any warranties or conditions of TITLE,\nNON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are\nsolely responsible for determining the appropriateness of using or\nredistributing the Work and assume any risks associated with Your exercise of\npermissions under this License.\n\n#### 8. Limitation of Liability\n\nIn no event and under no legal theory, whether in tort (including negligence),\ncontract, or otherwise, unless required by applicable law (such as deliberate\nand grossly negligent acts) or agreed to in writing, shall any Contributor be\nliable to You for damages, including any direct, indirect, special, incidental,\nor consequential damages of any character arising as a result of this License or\nout of the use or inability to use the Work (including but not limited to\ndamages for loss of goodwill, work stoppage, computer failure or malfunction, or\nany and all other commercial damages or losses), even if such Contributor has\nbeen advised of the possibility of such damages.\n\n#### 9. Accepting Warranty or Additional Liability\n\nWhile redistributing the Work or Derivative Works thereof, You may choose to\noffer, and charge a fee for, acceptance of support, warranty, indemnity, or\nother liability obligations and/or rights consistent with this License. However,\nin accepting such obligations, You may act only on Your own behalf and on Your\nsole responsibility, not on behalf of any other Contributor, and only if You\nagree to indemnify, defend, and hold each Contributor harmless for any liability\nincurred by, or claims asserted against, such Contributor by reason of your\naccepting any such warranty or additional liability.\n\n_END OF TERMS AND CONDITIONS_\n\n### APPENDIX: How to apply the Apache License to your work\n\nTo apply the Apache License to your work, attach the following boilerplate\nnotice, with the fields enclosed by brackets `[]` replaced with your own\nidentifying information. (Don't include the brackets!) The text should be\nenclosed in the appropriate comment syntax for the file format. We also\nrecommend that a file or class name and description of purpose be included on\nthe same “printed page” as the copyright notice for easier identification within\nthird-party archives.\n\n Copyright 2019 The Perspective Authors\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n"
|
|
2920
2920
|
- package_name: perspective-server
|
|
2921
|
-
package_version: 3.7.
|
|
2921
|
+
package_version: 3.7.4
|
|
2922
2922
|
repository: https://github.com/finos/perspective
|
|
2923
2923
|
license: Apache-2.0
|
|
2924
2924
|
licenses:
|
|
@@ -5,8 +5,6 @@ high performance data-visualization and analytics component for the web browser.
|
|
|
5
5
|
The examples in this module are in Python. See <a href="https://docs.rs/crate/perspective/latest"><code>perspective</code></a> docs for the Rust API.
|
|
6
6
|
</div>
|
|
7
7
|
|
|
8
|
-
# Python Examples
|
|
9
|
-
|
|
10
8
|
A simple example which loads an [Apache Arrow](https://arrow.apache.org/) and
|
|
11
9
|
computes a "Group By" operation, returning a new Arrow.
|
|
12
10
|
|
|
@@ -19,8 +17,6 @@ view = table.view(group_by = ["CounterParty", "Security"])
|
|
|
19
17
|
arrow = view.to_arrow()
|
|
20
18
|
```
|
|
21
19
|
|
|
22
|
-
# What is `perspective-python`
|
|
23
|
-
|
|
24
20
|
Perspective for Python uses the exact same C++ data engine used by the
|
|
25
21
|
[WebAssembly version](https://docs.rs/perspective-js/latest/perspective_js/) and
|
|
26
22
|
[Rust version](https://docs.rs/crate/perspective/latest). The library consists
|
|
@@ -95,22 +91,6 @@ via [Conda Forge](https://conda-forge.org)
|
|
|
95
91
|
conda install -c conda-forge perspective
|
|
96
92
|
``` -->
|
|
97
93
|
|
|
98
|
-
### Jupyterlab
|
|
99
|
-
|
|
100
|
-
`PerspectiveWidget` is a JupyterLab widget that implements the same API as
|
|
101
|
-
`<perspective-viewer>`, allowing for fast, intuitive
|
|
102
|
-
transformations/visualizations of various data formats within JupyterLab.
|
|
103
|
-
|
|
104
|
-
`PerspectiveWidget` is compatible with Jupyterlab 3 and Jupyter Notebook 6 via a
|
|
105
|
-
[prebuilt extension](https://jupyterlab.readthedocs.io/en/stable/extension/extension_dev.html#prebuilt-extensions).
|
|
106
|
-
To use it, simply install `perspective-python` and the extensions should be
|
|
107
|
-
available.
|
|
108
|
-
|
|
109
|
-
`perspective-python`'s JupyterLab extension also provides convenient builtin
|
|
110
|
-
viewers for `csv`, `json`, or `arrow` files. Simply right-click on a file with
|
|
111
|
-
this extension and choose the appropriate `Perpective` option from the context
|
|
112
|
-
menu.
|
|
113
|
-
|
|
114
94
|
## `Table`
|
|
115
95
|
|
|
116
96
|
A `Table` can be created from a dataset or a schema, the specifics of which are
|
|
@@ -152,10 +132,10 @@ column_data = view.to_columns()
|
|
|
152
132
|
row_data = view.to_json()
|
|
153
133
|
```
|
|
154
134
|
|
|
155
|
-
### Pandas Support
|
|
135
|
+
### Pandas and Polars Support
|
|
156
136
|
|
|
157
|
-
Perspective's `Table` can be constructed from `pandas.DataFrame`
|
|
158
|
-
Internally, this just uses
|
|
137
|
+
Perspective's `Table` can be constructed from `pandas.DataFrame` and
|
|
138
|
+
`polars.DataFrame` objects. Internally, this just uses
|
|
159
139
|
[`pyarrow::from_pandas`](https://arrow.apache.org/docs/python/pandas.html),
|
|
160
140
|
which dictates behavior of this feature including type support.
|
|
161
141
|
|
|
@@ -345,154 +325,3 @@ const websocket = perspective.websocket("ws://localhost:8888/websocket");
|
|
|
345
325
|
const table = websocket.open_table("data_source");
|
|
346
326
|
document.getElementById("viewer").load(table);
|
|
347
327
|
```
|
|
348
|
-
|
|
349
|
-
## `PerspectiveWidget`
|
|
350
|
-
|
|
351
|
-
Building on top of the API provided by `perspective.Table`, the
|
|
352
|
-
`PerspectiveWidget` is a JupyterLab plugin that offers the entire functionality
|
|
353
|
-
of Perspective within the Jupyter environment. It supports the same API
|
|
354
|
-
semantics of `<perspective-viewer>`, along with the additional data types
|
|
355
|
-
supported by `perspective.Table`. `PerspectiveWidget` takes keyword arguments
|
|
356
|
-
for the managed `View`:
|
|
357
|
-
|
|
358
|
-
```python
|
|
359
|
-
from perspective.widget import PerspectiveWidget
|
|
360
|
-
w = perspective.PerspectiveWidget(
|
|
361
|
-
data,
|
|
362
|
-
plugin="X Bar",
|
|
363
|
-
aggregates={"datetime": "any"},
|
|
364
|
-
sort=[["date", "desc"]]
|
|
365
|
-
)
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
### Creating a widget
|
|
369
|
-
|
|
370
|
-
A widget is created through the `PerspectiveWidget` constructor, which takes as
|
|
371
|
-
its first, required parameter a `perspective.Table`, a dataset, a schema, or
|
|
372
|
-
`None`, which serves as a special value that tells the Widget to defer loading
|
|
373
|
-
any data until later. In maintaining consistency with the Javascript API,
|
|
374
|
-
Widgets cannot be created with empty dictionaries or lists—`None` should be used
|
|
375
|
-
if the intention is to await data for loading later on. A widget can be
|
|
376
|
-
constructed from a dataset:
|
|
377
|
-
|
|
378
|
-
```python
|
|
379
|
-
from perspective.widget import PerspectiveWidget
|
|
380
|
-
PerspectiveWidget(data, group_by=["date"])
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
.. or a schema:
|
|
384
|
-
|
|
385
|
-
```python
|
|
386
|
-
PerspectiveWidget({"a": int, "b": str})
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
.. or an instance of a `perspective.Table`:
|
|
390
|
-
|
|
391
|
-
```python
|
|
392
|
-
table = perspective.table(data)
|
|
393
|
-
PerspectiveWidget(table)
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
<!--
|
|
397
|
-
## `PerspectiveRenderer`
|
|
398
|
-
|
|
399
|
-
Perspective also exposes a JS-only `mimerender-extension`. This lets you view
|
|
400
|
-
`csv`, `json`, and `arrow` files directly from the file browser. You can see
|
|
401
|
-
this by right clicking one of these files and `Open With->CSVPerspective` (or
|
|
402
|
-
`JSONPerspective` or `ArrowPerspective`). Perspective will also install itself
|
|
403
|
-
as the default handler for opening `.arrow` files. -->
|
|
404
|
-
|
|
405
|
-
## `PerspectiveTornadoHandler`
|
|
406
|
-
|
|
407
|
-
Perspective ships with a pre-built Tornado handler that makes integration with
|
|
408
|
-
`tornado.websockets` extremely easy. This allows you to run an instance of
|
|
409
|
-
`Perspective` on a server using Python, open a websocket to a `Table`, and
|
|
410
|
-
access the `Table` in JavaScript and through `<perspective-viewer>`. All
|
|
411
|
-
instructions sent to the `Table` are processed in Python, which executes the
|
|
412
|
-
commands, and returns its output through the websocket back to Javascript.
|
|
413
|
-
|
|
414
|
-
### Python setup
|
|
415
|
-
|
|
416
|
-
To use the handler, we need to first have a `Server`, a `Client` and an instance
|
|
417
|
-
of a `Table`:
|
|
418
|
-
|
|
419
|
-
```python
|
|
420
|
-
SERVER = Server()
|
|
421
|
-
CLIENT = SERVER.new_local_client()
|
|
422
|
-
```
|
|
423
|
-
|
|
424
|
-
Once the server has been created, create a `Table` instance with a name. The
|
|
425
|
-
name that you host the table under is important — it acts as a unique accessor
|
|
426
|
-
on the JavaScript side, which will look for a Table hosted at the websocket with
|
|
427
|
-
the name you specify.
|
|
428
|
-
|
|
429
|
-
```python
|
|
430
|
-
TABLE = client.table(data, name="data_source_one")
|
|
431
|
-
```
|
|
432
|
-
|
|
433
|
-
After the server and table setup is complete, create a websocket endpoint and
|
|
434
|
-
provide it a reference to `PerspectiveTornadoHandler`. You must provide the
|
|
435
|
-
configuration object in the route tuple, and it must contain
|
|
436
|
-
`"perspective_server"`, which is a reference to the `Server` you just created.
|
|
437
|
-
|
|
438
|
-
```python
|
|
439
|
-
from perspective.handlers.tornado import PerspectiveTornadoHandler
|
|
440
|
-
|
|
441
|
-
app = tornado.web.Application([
|
|
442
|
-
|
|
443
|
-
# ... other handlers ...
|
|
444
|
-
|
|
445
|
-
# Create a websocket endpoint that the client JavaScript can access
|
|
446
|
-
(r"/websocket", PerspectiveTornadoHandler, {"perspective_server": SERVER, "check_origin": True})
|
|
447
|
-
])
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
Optionally, the configuration object can also include `check_origin`, a boolean
|
|
451
|
-
that determines whether the websocket accepts requests from origins other than
|
|
452
|
-
where the server is hosted. See
|
|
453
|
-
[Tornado docs](https://www.tornadoweb.org/en/stable/websocket.html#tornado.websocket.WebSocketHandler.check_origin)
|
|
454
|
-
for more details.
|
|
455
|
-
|
|
456
|
-
### JavaScript setup
|
|
457
|
-
|
|
458
|
-
Once the server is up and running, you can access the Table you just hosted
|
|
459
|
-
using `perspective.websocket` and `open_table()`. First, create a client that
|
|
460
|
-
expects a Perspective server to accept connections at the specified URL:
|
|
461
|
-
|
|
462
|
-
```javascript
|
|
463
|
-
const websocket = await perspective.websocket("ws://localhost:8888/websocket");
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
Next open the `Table` we created on the server by name:
|
|
467
|
-
|
|
468
|
-
```javascript
|
|
469
|
-
const table = await websocket.open_table("data_source_one");
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
`table` is a proxy for the `Table` we created on the server. All operations that
|
|
473
|
-
are possible through the JavaScript API are possible on the Python API as well,
|
|
474
|
-
thus calling `view()`, `schema()`, `update()` etc. on `const table` will pass
|
|
475
|
-
those operations to the Python `Table`, execute the commands, and return the
|
|
476
|
-
result back to JavaScript. Similarly, providing this `table` to a
|
|
477
|
-
`<perspective-viewer>` instance will allow virtual rendering:
|
|
478
|
-
|
|
479
|
-
```javascript
|
|
480
|
-
await viewer.load(table);
|
|
481
|
-
```
|
|
482
|
-
|
|
483
|
-
`perspective.websocket` expects a Websocket URL where it will send instructions.
|
|
484
|
-
When `open_table` is called, the name to a hosted Table is passed through, and a
|
|
485
|
-
request is sent through the socket to fetch the Table. No actual `Table`
|
|
486
|
-
instance is passed inbetween the runtimes; all instructions are proxied through
|
|
487
|
-
websockets.
|
|
488
|
-
|
|
489
|
-
This provides for great flexibility — while `Perspective.js` is full of
|
|
490
|
-
features, browser WebAssembly runtimes currently have some performance
|
|
491
|
-
restrictions on memory and CPU feature utilization, and the architecture in
|
|
492
|
-
general suffers when the dataset itself is too large to download to the client
|
|
493
|
-
in full.
|
|
494
|
-
|
|
495
|
-
The Python runtime does not suffer from memory limitations, utilizes Apache
|
|
496
|
-
Arrow internal threadpools for threading and parallel processing, and generates
|
|
497
|
-
architecture optimized code, which currently makes it more suitable as a
|
|
498
|
-
server-side runtime than `node.js`.
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
|
2
|
+
# ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
|
|
3
|
+
# ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
|
|
4
|
+
# ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
|
|
5
|
+
# ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
|
|
6
|
+
# ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
|
|
7
|
+
# ┃ Copyright (c) 2017, the Perspective Authors. ┃
|
|
8
|
+
# ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
|
|
9
|
+
# ┃ This file is part of the Perspective library, distributed under the terms ┃
|
|
10
|
+
# ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
|
|
11
|
+
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
12
|
+
|
|
13
|
+
__version__ = "3.7.4"
|
|
14
|
+
__all__ = [
|
|
15
|
+
"_jupyter_labextension_paths",
|
|
16
|
+
"Server",
|
|
17
|
+
"Client",
|
|
18
|
+
"Table",
|
|
19
|
+
"View",
|
|
20
|
+
"PerspectiveError",
|
|
21
|
+
"ProxySession",
|
|
22
|
+
"AsyncClient",
|
|
23
|
+
"AsyncServer",
|
|
24
|
+
"num_cpus",
|
|
25
|
+
"set_num_cpus",
|
|
26
|
+
"system_info",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
__doc__ = """
|
|
30
|
+
The Python language bindings for [Perspective](https://perspective.finos.org), a
|
|
31
|
+
high performance data-visualization and analytics component for the web browser.
|
|
32
|
+
|
|
33
|
+
A simple example which loads an [Apache Arrow](https://arrow.apache.org/) and
|
|
34
|
+
computes a "Group By" operation, returning a new Arrow.
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from perspective import Server
|
|
38
|
+
|
|
39
|
+
client = Server().new_local_client()
|
|
40
|
+
table = client.table(arrow_bytes_data)
|
|
41
|
+
view = table.view(group_by = ["CounterParty", "Security"])
|
|
42
|
+
arrow = view.to_arrow()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Perspective for Python uses the exact same C++ data engine used by the
|
|
46
|
+
[WebAssembly version](https://docs.rs/perspective-js/latest/perspective_js/) and
|
|
47
|
+
[Rust version](https://docs.rs/crate/perspective/latest). The library consists
|
|
48
|
+
of many of the same abstractions and API as in JavaScript, as well as
|
|
49
|
+
Python-specific data loading support for [NumPy](https://numpy.org/),
|
|
50
|
+
[Pandas](https://pandas.pydata.org/) (and
|
|
51
|
+
[Apache Arrow](https://arrow.apache.org/), as in JavaScript).
|
|
52
|
+
|
|
53
|
+
Additionally, `perspective-python` provides a session manager suitable for
|
|
54
|
+
integration into server systems such as
|
|
55
|
+
[Tornado websockets](https://www.tornadoweb.org/en/stable/websocket.html),
|
|
56
|
+
[AIOHTTP](https://docs.aiohttp.org/en/stable/web_quickstart.html#websockets), or
|
|
57
|
+
[Starlette](https://www.starlette.io/websockets/)/[FastAPI](https://fastapi.tiangolo.com/advanced/websockets/),
|
|
58
|
+
which allows fully _virtual_ Perspective tables to be interacted with by
|
|
59
|
+
multiple `<perspective-viewer>` in a web browser. You can also interact with a
|
|
60
|
+
Perspective table from python clients, and to that end client libraries are
|
|
61
|
+
implemented for both Tornado and AIOHTTP.
|
|
62
|
+
|
|
63
|
+
As `<perspective-viewer>` will only consume the data necessary to render the
|
|
64
|
+
current screen, this runtime mode allows _ludicrously-sized_ datasets with
|
|
65
|
+
instant-load after they've been manifest on the server (at the expense of
|
|
66
|
+
network latency on UI interaction).
|
|
67
|
+
|
|
68
|
+
The included `PerspectiveWidget` allows running such a viewer in
|
|
69
|
+
[JupyterLab](https://jupyterlab.readthedocs.io/en/stable/) in either server or
|
|
70
|
+
client (via WebAssembly) mode, and the included `PerspectiveTornadoHandler`
|
|
71
|
+
makes it simple to extend a Tornado server with virtual Perspective support.
|
|
72
|
+
|
|
73
|
+
The `perspective` module exports several tools:
|
|
74
|
+
|
|
75
|
+
- `Server` the constructor for a new isntance of the Perspective data engine.
|
|
76
|
+
- The `perspective.widget` module exports `PerspectiveWidget`, the JupyterLab
|
|
77
|
+
widget for interactive visualization in a notebook cell.
|
|
78
|
+
- The `perspective.handlers` modules exports web frameworks handlers that
|
|
79
|
+
interface with a `perspective-client` in JavaScript.
|
|
80
|
+
- `perspective.handlers.tornado.PerspectiveTornadoHandler` for
|
|
81
|
+
[Tornado](https://www.tornadoweb.org/)
|
|
82
|
+
- `perspective.handlers.starlette.PerspectiveStarletteHandler` for
|
|
83
|
+
[Starlette](https://www.starlette.io/) and
|
|
84
|
+
[FastAPI](https://fastapi.tiangolo.com)
|
|
85
|
+
- `perspective.handlers.aiohttp.PerspectiveAIOHTTPHandler` for
|
|
86
|
+
[AIOHTTP](https://docs.aiohttp.org),
|
|
87
|
+
|
|
88
|
+
This user's guide provides an overview of the most common ways to use
|
|
89
|
+
Perspective in Python: the `Table` API, the JupyterLab widget, and the Tornado
|
|
90
|
+
handler.
|
|
91
|
+
|
|
92
|
+
[More Examples](https://github.com/finos/perspective/tree/master/examples) are
|
|
93
|
+
available on GitHub.
|
|
94
|
+
|
|
95
|
+
## Installation
|
|
96
|
+
|
|
97
|
+
`perspective-python` contains full bindings to the Perspective API, a JupyterLab
|
|
98
|
+
widget, and a WebSocket handlers for several webserver libraries that allow you
|
|
99
|
+
to host Perspective using server-side Python.
|
|
100
|
+
|
|
101
|
+
`perspective-python` can be installed from [PyPI](https://pypi.org) via `pip`:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
pip install perspective-python
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Quick Start
|
|
108
|
+
|
|
109
|
+
A `Table` can be created from a dataset or a schema, the specifics of which are
|
|
110
|
+
[discussed](#loading-data-with-table) in the JavaScript section of the user's
|
|
111
|
+
guide. In Python, however, Perspective supports additional data types that are
|
|
112
|
+
commonly used when processing data:
|
|
113
|
+
|
|
114
|
+
- `pandas.DataFrame`
|
|
115
|
+
- `polars.DataFrame`
|
|
116
|
+
- `bytes` (encoding an Apache Arrow)
|
|
117
|
+
- `objects` (either extracting a repr or via reference)
|
|
118
|
+
- `str` (encoding as a CSV)
|
|
119
|
+
|
|
120
|
+
A `Table` is created in a similar fashion to its JavaScript equivalent:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from datetime import date, datetime
|
|
124
|
+
import numpy as np
|
|
125
|
+
import pandas as pd
|
|
126
|
+
import perspective
|
|
127
|
+
|
|
128
|
+
data = pd.DataFrame({
|
|
129
|
+
"int": np.arange(100),
|
|
130
|
+
"float": [i * 1.5 for i in range(100)],
|
|
131
|
+
"bool": [True for i in range(100)],
|
|
132
|
+
"date": [date.today() for i in range(100)],
|
|
133
|
+
"datetime": [datetime.now() for i in range(100)],
|
|
134
|
+
"string": [str(i) for i in range(100)]
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
table = perspective.table(data, index="float")
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Likewise, a `View` can be created via the `view()` method:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
view = table.view(group_by=["float"], filter=[["bool", "==", True]])
|
|
144
|
+
column_data = view.to_columns()
|
|
145
|
+
row_data = view.to_json()
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Pandas and Polars Support
|
|
149
|
+
|
|
150
|
+
Perspective's `Table` can be constructed from `pandas.DataFrame` and
|
|
151
|
+
`polars.DataFrame` objects. Internally, this just uses
|
|
152
|
+
[`pyarrow::from_pandas`](https://arrow.apache.org/docs/python/pandas.html),
|
|
153
|
+
which dictates behavior of this feature including type support.
|
|
154
|
+
|
|
155
|
+
If the dataframe does not have an index set, an integer-typed column named
|
|
156
|
+
`"index"` is created. If you want to preserve the indexing behavior of the
|
|
157
|
+
dataframe passed into Perspective, simply create the `Table` with
|
|
158
|
+
`index="index"` as a keyword argument. This tells Perspective to once again
|
|
159
|
+
treat the index as a primary key:
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
data.set_index("datetime")
|
|
163
|
+
table = perspective.table(data, index="index")
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### Time Zone Handling
|
|
167
|
+
|
|
168
|
+
When parsing `"datetime"` strings, times are assumed _local time_ unless an
|
|
169
|
+
explicit timezone offset is parsed. All `"datetime"` columns (regardless of
|
|
170
|
+
input time zone) are _output_ to the user as `datetime.datetime` objects in
|
|
171
|
+
_local time_ according to the Python runtime.
|
|
172
|
+
|
|
173
|
+
This behavior is consistent with Perspective's behavior in JavaScript. For more
|
|
174
|
+
details, see this in-depth
|
|
175
|
+
[explanation](https://github.com/finos/perspective/pull/867) of
|
|
176
|
+
`perspective-python` semantics around time zone handling.
|
|
177
|
+
|
|
178
|
+
#### Callbacks and Events
|
|
179
|
+
|
|
180
|
+
`perspective.Table` allows for `on_update` and `on_delete` callbacks to be
|
|
181
|
+
set—simply call `on_update` or `on_delete` with a reference to a function or a
|
|
182
|
+
lambda without any parameters:
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
def update_callback():
|
|
186
|
+
print("Updated!")
|
|
187
|
+
|
|
188
|
+
# set the update callback
|
|
189
|
+
on_update_id = view.on_update(update_callback)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def delete_callback():
|
|
193
|
+
print("Deleted!")
|
|
194
|
+
|
|
195
|
+
# set the delete callback
|
|
196
|
+
on_delete_id = view.on_delete(delete_callback)
|
|
197
|
+
|
|
198
|
+
# set a lambda as a callback
|
|
199
|
+
view.on_delete(lambda: print("Deleted x2!"))
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
If the callback is a named reference to a function, it can be removed with
|
|
203
|
+
`remove_update` or `remove_delete`:
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
view.remove_update(on_update_id)
|
|
207
|
+
view.remove_delete(on_delete_id)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Callbacks defined with a lambda function cannot be removed, as lambda functions
|
|
211
|
+
have no identifier.
|
|
212
|
+
|
|
213
|
+
### Hosting `Table` and `View` instances
|
|
214
|
+
|
|
215
|
+
`Server` "hosts" all `perspective.Table` and `perspective.View` instances
|
|
216
|
+
created by its connected `Client`s. Hosted tables/views can have their methods
|
|
217
|
+
called from other sources than the Python server, i.e. by a `perspective-viewer`
|
|
218
|
+
running in a JavaScript client over the network, interfacing with
|
|
219
|
+
`perspective-python` through the websocket API.
|
|
220
|
+
|
|
221
|
+
The server has full control of all hosted `Table` and `View` instances, and can
|
|
222
|
+
call any public API method on hosted instances. This makes it extremely easy to
|
|
223
|
+
stream data to a hosted `Table` using `.update()`:
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
server = perspective.Server()
|
|
227
|
+
client = server.new_local_client()
|
|
228
|
+
table = client.table(data, name="data_source")
|
|
229
|
+
|
|
230
|
+
for i in range(10):
|
|
231
|
+
# updates continue to propagate automatically
|
|
232
|
+
table.update(new_data)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
The `name` provided is important, as it enables Perspective in JavaScript to
|
|
236
|
+
look up a `Table` and get a handle to it over the network. Otherwise, `name`
|
|
237
|
+
will be assigned randomlu and the `Client` must look this up with
|
|
238
|
+
`CLient.get_hosted_table_names()`
|
|
239
|
+
|
|
240
|
+
### Client/Server Replicated Mode
|
|
241
|
+
|
|
242
|
+
Using Tornado and
|
|
243
|
+
[`PerspectiveTornadoHandler`](python.md#perspectivetornadohandler), as well as
|
|
244
|
+
`Perspective`'s JavaScript library, we can set up "distributed" Perspective
|
|
245
|
+
instances that allows multiple browser `perspective-viewer` clients to read from
|
|
246
|
+
a common `perspective-python` server, as in the
|
|
247
|
+
[Tornado Example Project](https://github.com/finos/perspective/tree/master/examples/python-tornado).
|
|
248
|
+
|
|
249
|
+
This architecture works by maintaining two `Tables`—one on the server, and one
|
|
250
|
+
on the client that mirrors the server's `Table` automatically using `on_update`.
|
|
251
|
+
All updates to the table on the server are automatically applied to each client,
|
|
252
|
+
which makes this architecture a natural fit for streaming dashboards and other
|
|
253
|
+
distributed use-cases. In conjunction with [multithreading](#multi-threading),
|
|
254
|
+
distributed Perspective offers consistently high performance over large numbers
|
|
255
|
+
of clients and large datasets.
|
|
256
|
+
|
|
257
|
+
_*server.py*_
|
|
258
|
+
|
|
259
|
+
```python
|
|
260
|
+
from perspective import Server
|
|
261
|
+
from perspective.hadnlers.tornado import PerspectiveTornadoHandler
|
|
262
|
+
|
|
263
|
+
# Create an instance of Server, and host a Table
|
|
264
|
+
SERVER = Server()
|
|
265
|
+
CLIENT = SERVER.new_local_client()
|
|
266
|
+
|
|
267
|
+
# The Table is exposed at `localhost:8888/websocket` with the name `data_source`
|
|
268
|
+
client.table(data, name = "data_source")
|
|
269
|
+
|
|
270
|
+
app = tornado.web.Application([
|
|
271
|
+
# create a websocket endpoint that the client JavaScript can access
|
|
272
|
+
(r"/websocket", PerspectiveTornadoHandler, {"perspective_server": SERVER})
|
|
273
|
+
])
|
|
274
|
+
|
|
275
|
+
# Start the Tornado server
|
|
276
|
+
app.listen(8888)
|
|
277
|
+
loop = tornado.ioloop.IOLoop.current()
|
|
278
|
+
loop.start()
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Instead of calling `load(server_table)`, create a `View` using `server_table`
|
|
282
|
+
and pass that into `viewer.load()`. This will automatically register an
|
|
283
|
+
`on_update` callback that synchronizes state between the server and the client.
|
|
284
|
+
|
|
285
|
+
_*index.html*_
|
|
286
|
+
|
|
287
|
+
```html
|
|
288
|
+
<perspective-viewer id="viewer" editable></perspective-viewer>
|
|
289
|
+
|
|
290
|
+
<script type="module">
|
|
291
|
+
// Create a client that expects a Perspective server
|
|
292
|
+
// to accept connections at the specified URL.
|
|
293
|
+
const websocket = await perspective.websocket(
|
|
294
|
+
"ws://localhost:8888/websocket"
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
// Get a handle to the Table on the server
|
|
298
|
+
const server_table = await websocket.open_table("data_source_one");
|
|
299
|
+
|
|
300
|
+
// Create a new view
|
|
301
|
+
const server_view = await table.view();
|
|
302
|
+
|
|
303
|
+
// Create a Table on the client using `perspective.worker()`
|
|
304
|
+
const worker = await perspective.worker();
|
|
305
|
+
const client_table = await worker.table(view);
|
|
306
|
+
|
|
307
|
+
// Load the client table in the `<perspective-viewer>`.
|
|
308
|
+
document.getElementById("viewer").load(client_table);
|
|
309
|
+
</script>
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
For a more complex example that offers distributed editing of the server
|
|
313
|
+
dataset, see
|
|
314
|
+
[client_server_editing.html](https://github.com/finos/perspective/blob/master/examples/python-tornado/client_server_editing.html).
|
|
315
|
+
|
|
316
|
+
We also provide examples for Starlette/FastAPI and AIOHTTP:
|
|
317
|
+
|
|
318
|
+
- [Starlette Example Project](https://github.com/finos/perspective/tree/master/examples/python-starlette).
|
|
319
|
+
- [AIOHTTP Example Project](https://github.com/finos/perspective/tree/master/examples/python-aiohttp).
|
|
320
|
+
|
|
321
|
+
### Server-only Mode
|
|
322
|
+
|
|
323
|
+
The server setup is identical to [Distributed Mode](#distributed-mode) above,
|
|
324
|
+
but instead of creating a view, the client calls `load(server_table)`: In
|
|
325
|
+
Python, use `Server` and `PerspectiveTornadoHandler` to create a websocket
|
|
326
|
+
server that exposes a `Table`. In this example, `table` is a proxy for the
|
|
327
|
+
`Table` we created on the server. All API methods are available on _proxies_,
|
|
328
|
+
the.g.us calling `view()`, `schema()`, `update()` on `table` will pass those
|
|
329
|
+
operations to the Python `Table`, execute the commands, and return the result
|
|
330
|
+
back to Javascript.
|
|
331
|
+
|
|
332
|
+
```html
|
|
333
|
+
<perspective-viewer id="viewer" editable></perspective-viewer>
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
```javascript
|
|
337
|
+
const websocket = perspective.websocket("ws://localhost:8888/websocket");
|
|
338
|
+
const table = websocket.open_table("data_source");
|
|
339
|
+
document.getElementById("viewer").load(table);
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
"""
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
import functools
|
|
346
|
+
|
|
347
|
+
from .perspective import (
|
|
348
|
+
Client,
|
|
349
|
+
PerspectiveError,
|
|
350
|
+
ProxySession,
|
|
351
|
+
Server,
|
|
352
|
+
AsyncServer,
|
|
353
|
+
AsyncClient,
|
|
354
|
+
# NOTE: these are classes without constructors,
|
|
355
|
+
# so we import them just for type hinting
|
|
356
|
+
Table, # noqa: F401
|
|
357
|
+
View, # noqa: F401
|
|
358
|
+
num_cpus,
|
|
359
|
+
set_num_cpus,
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
GLOBAL_SERVER = Server()
|
|
364
|
+
GLOBAL_CLIENT = GLOBAL_SERVER.new_local_client()
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
@functools.wraps(Client.table)
|
|
368
|
+
def table(*args, **kwargs):
|
|
369
|
+
return GLOBAL_CLIENT.table(*args, **kwargs)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
@functools.wraps(Client.open_table)
|
|
373
|
+
def open_table(*args, **kwargs):
|
|
374
|
+
return GLOBAL_CLIENT.table(*args, **kwargs)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
@functools.wraps(Client.get_hosted_table_names)
|
|
378
|
+
def get_hosted_table_names(*args, **kwargs):
|
|
379
|
+
return GLOBAL_CLIENT.get_hosted_table_names(*args, **kwargs)
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
@functools.wraps(Client.system_info)
|
|
383
|
+
def system_info(*args, **kwargs):
|
|
384
|
+
return GLOBAL_CLIENT.system_info(*args, **kwargs)
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def _jupyter_labextension_paths():
|
|
388
|
+
"""
|
|
389
|
+
Read by `jupyter labextension develop`
|
|
390
|
+
@private
|
|
391
|
+
"""
|
|
392
|
+
return [{"src": "labextension", "dest": "@finos/perspective-jupyterlab"}]
|