spaday-perspective 0.1.0__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.
Files changed (31) hide show
  1. spaday_perspective-0.1.0/.gitignore +157 -0
  2. spaday_perspective-0.1.0/LICENSE +201 -0
  3. spaday_perspective-0.1.0/PKG-INFO +168 -0
  4. spaday_perspective-0.1.0/README.md +130 -0
  5. spaday_perspective-0.1.0/js/build.mjs +41 -0
  6. spaday_perspective-0.1.0/js/package.json +59 -0
  7. spaday_perspective-0.1.0/js/playwright.config.js +30 -0
  8. spaday_perspective-0.1.0/js/pnpm-lock.yaml +2801 -0
  9. spaday_perspective-0.1.0/js/pnpm-workspace.yaml +2 -0
  10. spaday_perspective-0.1.0/js/src/css/index.css +0 -0
  11. spaday_perspective-0.1.0/js/src/html/index.html +13 -0
  12. spaday_perspective-0.1.0/js/src/ts/css.d.ts +9 -0
  13. spaday_perspective-0.1.0/js/src/ts/index.ts +145 -0
  14. spaday_perspective-0.1.0/js/tests/index.spec.js +20 -0
  15. spaday_perspective-0.1.0/js/tools/bundle.mjs +60 -0
  16. spaday_perspective-0.1.0/js/tools/css.mjs +52 -0
  17. spaday_perspective-0.1.0/js/tools/externals.mjs +18 -0
  18. spaday_perspective-0.1.0/js/tools/getarg.mjs +23 -0
  19. spaday_perspective-0.1.0/js/tools/html.mjs +0 -0
  20. spaday_perspective-0.1.0/js/tsconfig.json +24 -0
  21. spaday_perspective-0.1.0/pyproject.toml +173 -0
  22. spaday_perspective-0.1.0/spaday_perspective/__init__.py +15 -0
  23. spaday_perspective-0.1.0/spaday_perspective/components.cem.json +22 -0
  24. spaday_perspective-0.1.0/spaday_perspective/components.py +32 -0
  25. spaday_perspective-0.1.0/spaday_perspective/extension/cdn/index.js +16052 -0
  26. spaday_perspective-0.1.0/spaday_perspective/extension/cdn/index.js.map +7 -0
  27. spaday_perspective-0.1.0/spaday_perspective/extension/css/index.css +0 -0
  28. spaday_perspective-0.1.0/spaday_perspective/extension/esm/index.js +124 -0
  29. spaday_perspective-0.1.0/spaday_perspective/extension/esm/index.js.map +7 -0
  30. spaday_perspective-0.1.0/spaday_perspective/extension/index.html +13 -0
  31. spaday_perspective-0.1.0/spaday_perspective/tests/test_all.py +25 -0
@@ -0,0 +1,157 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.a
8
+ *.o
9
+ *.dSYM
10
+ *.so
11
+ *.obj
12
+ *.dll
13
+ *.exp
14
+ *.lib
15
+
16
+ # Rust
17
+ target
18
+ target-capi
19
+
20
+ # Distribution / packaging
21
+ .Python
22
+ build/
23
+ develop-eggs/
24
+ dist/
25
+ downloads/
26
+ eggs/
27
+ .eggs/
28
+ lib/
29
+ lib64/
30
+ parts/
31
+ sdist/
32
+ var/
33
+ wheels/
34
+ pip-wheel-metadata/
35
+ share/python-wheels/
36
+ *.egg-info/
37
+ .installed.cfg
38
+ *.egg
39
+ MANIFEST
40
+
41
+ # PyInstaller
42
+ *.manifest
43
+ *.spec
44
+
45
+ # Installer logs
46
+ pip-log.txt
47
+ pip-delete-this-directory.txt
48
+
49
+ # Unit test / coverage reports
50
+ htmlcov/
51
+ .tox/
52
+ .nox/
53
+ .coverage
54
+ .coverage.*
55
+ .cache
56
+ nosetests.xml
57
+ coverage.xml
58
+ junit.xml
59
+ *.cover
60
+ *.py,cover
61
+ .hypothesis/
62
+ .pytest_cache/
63
+
64
+ # Django
65
+ *.log
66
+ local_settings.py
67
+ db.sqlite3
68
+ db.sqlite3-journal
69
+
70
+ # IPython
71
+ profile_default/
72
+ ipython_config.py
73
+
74
+ # pyenv
75
+ .python-version
76
+
77
+ # pipenv
78
+ Pipfile.lock
79
+
80
+ # Celery
81
+ celerybeat-schedule
82
+ celerybeat.pid
83
+
84
+ # Airspeed Velocity
85
+ .asv
86
+
87
+ # Environments
88
+ .env
89
+ .venv
90
+ env/
91
+ venv/
92
+ ENV/
93
+ env.bak/
94
+ venv.bak/
95
+
96
+ # Spyder project settings
97
+ .spyderproject
98
+ .spyproject
99
+
100
+ # Rope project settings
101
+ .ropeproject
102
+
103
+ # mkdocs documentation
104
+ /site
105
+
106
+ # mypy
107
+ .mypy_cache/
108
+ .dmypy.json
109
+ dmypy.json
110
+
111
+ # Pyre type checker
112
+ .pyre/
113
+
114
+ # Documentation
115
+ /site
116
+ index.md
117
+ docs/_build/
118
+ docs/api
119
+ docs/html
120
+ docs/index.md
121
+ docs/jupyter_execute
122
+ docs/src/_build/
123
+ docs/superpowers
124
+ index.md
125
+
126
+ # JS
127
+ js/coverage
128
+ js/dist
129
+ js/lib
130
+ js/node_modules
131
+ js/test-results
132
+ js/playwright-report
133
+ js/*.tgz
134
+
135
+ # Jupyter
136
+ .ipynb_checkpoints
137
+ .autoversion
138
+ Untitled*.ipynb
139
+ spaday_perspective/extension
140
+ spaday_perspective/nbextension
141
+ spaday_perspective/labextension
142
+
143
+ # Emscripten SDK (locally installed)
144
+ emsdk
145
+
146
+ # Mac
147
+ .DS_Store
148
+
149
+ # Hydra
150
+ /outputs/
151
+ /multirun/
152
+
153
+ # AI
154
+ ROADMAP.md
155
+ AGENTS.md
156
+ .github/hooks/sdlc.json
157
+ .superpowers
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 1kbgz
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.4
2
+ Name: spaday-perspective
3
+ Version: 0.1.0
4
+ Summary: perspective for spaday
5
+ Project-URL: Repository, https://github.com/1kbgz/spaday-perspective
6
+ Project-URL: Homepage, https://github.com/1kbgz/spaday-perspective
7
+ Author-email: 1kbgz <dev@1kbgz.com>
8
+ License: Apache-2.0
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: spaday>=0.3.0
21
+ Provides-Extra: develop
22
+ Requires-Dist: build; extra == 'develop'
23
+ Requires-Dist: bump-my-version; extra == 'develop'
24
+ Requires-Dist: check-dist; extra == 'develop'
25
+ Requires-Dist: codespell; extra == 'develop'
26
+ Requires-Dist: hatch-js; extra == 'develop'
27
+ Requires-Dist: hatchling; extra == 'develop'
28
+ Requires-Dist: mdformat; extra == 'develop'
29
+ Requires-Dist: mdformat-tables>=1; extra == 'develop'
30
+ Requires-Dist: pytest; extra == 'develop'
31
+ Requires-Dist: pytest-cov; extra == 'develop'
32
+ Requires-Dist: ruff; extra == 'develop'
33
+ Requires-Dist: twine; extra == 'develop'
34
+ Requires-Dist: ty; extra == 'develop'
35
+ Requires-Dist: uv; extra == 'develop'
36
+ Requires-Dist: wheel; extra == 'develop'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # spaday-perspective
40
+
41
+ [Perspective](https://perspective-dev.github.io) for [spaday](https://1kbgz.github.io/spaday/)
42
+
43
+ [![Build Status](https://github.com/1kbgz/spaday-perspective/actions/workflows/build.yaml/badge.svg?branch=main&event=push)](https://github.com/1kbgz/spaday-perspective/actions/workflows/build.yaml)
44
+ [![codecov](https://codecov.io/gh/1kbgz/spaday-perspective/branch/main/graph/badge.svg)](https://codecov.io/gh/1kbgz/spaday-perspective)
45
+ [![License](https://img.shields.io/github/license/1kbgz/spaday-perspective)](https://github.com/1kbgz/spaday-perspective)
46
+ [![PyPI](https://img.shields.io/pypi/v/spaday-perspective.svg)](https://pypi.python.org/pypi/spaday-perspective)
47
+
48
+ ## Overview
49
+
50
+ `spaday-perspective` moves the existing `PerspectivePanel` integration out of spaday core. Its
51
+ self-contained `<perspective-panel>` bundle includes Perspective's client, viewer, workspace, datagrid,
52
+ themes, and viewer WASM.
53
+
54
+ ## Interactive example
55
+
56
+ This complete app serves a live Perspective table. **Add trade** streams a new row into the grid,
57
+ the select switches between flat and grouped layouts, and the checkbox changes the viewer theme.
58
+
59
+ ```python
60
+ import perspective
61
+ from perspective.handlers.starlette import PerspectiveStarletteHandler
62
+ from starlette.responses import JSONResponse
63
+ from starlette.routing import Route, WebSocketRoute
64
+ from starlette.websockets import WebSocket
65
+
66
+ from spaday import CallEndpoint, cond, element, eq, field, obj
67
+ from spaday.backends.starlette import serve
68
+ from spaday_perspective import PerspectivePanel
69
+
70
+ server = perspective.Server()
71
+ client = server.new_local_client()
72
+ trades = client.table(
73
+ [
74
+ {"id": 1, "symbol": "AAPL", "side": "buy", "price": 211.10},
75
+ {"id": 2, "symbol": "MSFT", "side": "sell", "price": 503.02},
76
+ ],
77
+ name="trades",
78
+ )
79
+ next_id = 2
80
+
81
+
82
+ async def add_trade(_request):
83
+ global next_id
84
+ next_id += 1
85
+ trades.update(
86
+ [
87
+ {
88
+ "id": next_id,
89
+ "symbol": "AAPL" if next_id % 2 else "MSFT",
90
+ "side": "buy" if next_id % 2 else "sell",
91
+ "price": 210 + next_id,
92
+ }
93
+ ]
94
+ )
95
+ return JSONResponse({"id": next_id})
96
+
97
+
98
+ async def perspective_socket(websocket: WebSocket):
99
+ await PerspectiveStarletteHandler(perspective_server=server, websocket=websocket).run()
100
+
101
+
102
+ def layout(*, grouped=False):
103
+ viewer = {"table": "trades", "plugin": "Datagrid", "columns": ["symbol", "side", "price"]}
104
+ if grouped:
105
+ viewer.update({"group_by": ["symbol"], "columns": ["price"], "aggregates": {"price": "avg"}})
106
+ return {
107
+ "sizes": [1],
108
+ "detail": {"main": {"type": "tab-area", "widgets": ["trades"], "currentIndex": 0}},
109
+ "master": {"sizes": [], "widgets": []},
110
+ "mode": "globalFilters",
111
+ "viewers": {"trades": viewer},
112
+ }
113
+
114
+
115
+ panel = (
116
+ PerspectivePanel()
117
+ .compute("theme", cond(field("dark"), "dark", "light"))
118
+ .compute(
119
+ "config",
120
+ obj(
121
+ {
122
+ "ws_url": "/perspective",
123
+ "tables": ["trades"],
124
+ "layout": cond(eq(field("view"), "grouped"), layout(grouped=True), layout()),
125
+ }
126
+ ),
127
+ )
128
+ .style(display="block", height="70vh", margin_top="1rem")
129
+ )
130
+
131
+ view = element("select").bind("value", "view", mode="two-way").child(
132
+ element("option", "Blotter", value="blotter"),
133
+ element("option", "Average by symbol", value="grouped"),
134
+ )
135
+ dark = element("input", type="checkbox").bind("checked", "dark", mode="two-way")
136
+ page = (
137
+ element("main")
138
+ .style(margin="1rem", font_family="system-ui")
139
+ .child(element("button").text("Add trade").on("click", CallEndpoint("POST", "/api/trades")))
140
+ .child(view)
141
+ .child(element("label").child(dark, " Dark theme"))
142
+ .child(panel)
143
+ )
144
+
145
+ app = serve(
146
+ page,
147
+ packages=["perspective"],
148
+ store={"view": "blotter", "dark": False},
149
+ routes=[
150
+ Route("/api/trades", add_trade, methods=["POST"]),
151
+ WebSocketRoute("/perspective", perspective_socket),
152
+ ],
153
+ )
154
+ ```
155
+
156
+ Save this as `app.py`, then run
157
+ `pip install spaday-perspective perspective-python starlette uvicorn` and `uvicorn app:app`.
158
+ Open <http://127.0.0.1:8000>.
159
+
160
+ This keeps Perspective's bulk data on its native websocket. A spaday/transports model only needs to
161
+ carry the small serializable connection/layout config. Replacing `config` reconnects when `ws_url`
162
+ changes and restores changed layouts; `theme` accepts `light`, `dark`, or a Perspective theme name.
163
+
164
+ Installing this project registers the `perspective` entry point with spaday. The equivalent explicit
165
+ forms are `packages=[spaday_perspective.package]` and `packages=["spaday_perspective:package"]`.
166
+
167
+ > [!NOTE]
168
+ > This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).
@@ -0,0 +1,130 @@
1
+ # spaday-perspective
2
+
3
+ [Perspective](https://perspective-dev.github.io) for [spaday](https://1kbgz.github.io/spaday/)
4
+
5
+ [![Build Status](https://github.com/1kbgz/spaday-perspective/actions/workflows/build.yaml/badge.svg?branch=main&event=push)](https://github.com/1kbgz/spaday-perspective/actions/workflows/build.yaml)
6
+ [![codecov](https://codecov.io/gh/1kbgz/spaday-perspective/branch/main/graph/badge.svg)](https://codecov.io/gh/1kbgz/spaday-perspective)
7
+ [![License](https://img.shields.io/github/license/1kbgz/spaday-perspective)](https://github.com/1kbgz/spaday-perspective)
8
+ [![PyPI](https://img.shields.io/pypi/v/spaday-perspective.svg)](https://pypi.python.org/pypi/spaday-perspective)
9
+
10
+ ## Overview
11
+
12
+ `spaday-perspective` moves the existing `PerspectivePanel` integration out of spaday core. Its
13
+ self-contained `<perspective-panel>` bundle includes Perspective's client, viewer, workspace, datagrid,
14
+ themes, and viewer WASM.
15
+
16
+ ## Interactive example
17
+
18
+ This complete app serves a live Perspective table. **Add trade** streams a new row into the grid,
19
+ the select switches between flat and grouped layouts, and the checkbox changes the viewer theme.
20
+
21
+ ```python
22
+ import perspective
23
+ from perspective.handlers.starlette import PerspectiveStarletteHandler
24
+ from starlette.responses import JSONResponse
25
+ from starlette.routing import Route, WebSocketRoute
26
+ from starlette.websockets import WebSocket
27
+
28
+ from spaday import CallEndpoint, cond, element, eq, field, obj
29
+ from spaday.backends.starlette import serve
30
+ from spaday_perspective import PerspectivePanel
31
+
32
+ server = perspective.Server()
33
+ client = server.new_local_client()
34
+ trades = client.table(
35
+ [
36
+ {"id": 1, "symbol": "AAPL", "side": "buy", "price": 211.10},
37
+ {"id": 2, "symbol": "MSFT", "side": "sell", "price": 503.02},
38
+ ],
39
+ name="trades",
40
+ )
41
+ next_id = 2
42
+
43
+
44
+ async def add_trade(_request):
45
+ global next_id
46
+ next_id += 1
47
+ trades.update(
48
+ [
49
+ {
50
+ "id": next_id,
51
+ "symbol": "AAPL" if next_id % 2 else "MSFT",
52
+ "side": "buy" if next_id % 2 else "sell",
53
+ "price": 210 + next_id,
54
+ }
55
+ ]
56
+ )
57
+ return JSONResponse({"id": next_id})
58
+
59
+
60
+ async def perspective_socket(websocket: WebSocket):
61
+ await PerspectiveStarletteHandler(perspective_server=server, websocket=websocket).run()
62
+
63
+
64
+ def layout(*, grouped=False):
65
+ viewer = {"table": "trades", "plugin": "Datagrid", "columns": ["symbol", "side", "price"]}
66
+ if grouped:
67
+ viewer.update({"group_by": ["symbol"], "columns": ["price"], "aggregates": {"price": "avg"}})
68
+ return {
69
+ "sizes": [1],
70
+ "detail": {"main": {"type": "tab-area", "widgets": ["trades"], "currentIndex": 0}},
71
+ "master": {"sizes": [], "widgets": []},
72
+ "mode": "globalFilters",
73
+ "viewers": {"trades": viewer},
74
+ }
75
+
76
+
77
+ panel = (
78
+ PerspectivePanel()
79
+ .compute("theme", cond(field("dark"), "dark", "light"))
80
+ .compute(
81
+ "config",
82
+ obj(
83
+ {
84
+ "ws_url": "/perspective",
85
+ "tables": ["trades"],
86
+ "layout": cond(eq(field("view"), "grouped"), layout(grouped=True), layout()),
87
+ }
88
+ ),
89
+ )
90
+ .style(display="block", height="70vh", margin_top="1rem")
91
+ )
92
+
93
+ view = element("select").bind("value", "view", mode="two-way").child(
94
+ element("option", "Blotter", value="blotter"),
95
+ element("option", "Average by symbol", value="grouped"),
96
+ )
97
+ dark = element("input", type="checkbox").bind("checked", "dark", mode="two-way")
98
+ page = (
99
+ element("main")
100
+ .style(margin="1rem", font_family="system-ui")
101
+ .child(element("button").text("Add trade").on("click", CallEndpoint("POST", "/api/trades")))
102
+ .child(view)
103
+ .child(element("label").child(dark, " Dark theme"))
104
+ .child(panel)
105
+ )
106
+
107
+ app = serve(
108
+ page,
109
+ packages=["perspective"],
110
+ store={"view": "blotter", "dark": False},
111
+ routes=[
112
+ Route("/api/trades", add_trade, methods=["POST"]),
113
+ WebSocketRoute("/perspective", perspective_socket),
114
+ ],
115
+ )
116
+ ```
117
+
118
+ Save this as `app.py`, then run
119
+ `pip install spaday-perspective perspective-python starlette uvicorn` and `uvicorn app:app`.
120
+ Open <http://127.0.0.1:8000>.
121
+
122
+ This keeps Perspective's bulk data on its native websocket. A spaday/transports model only needs to
123
+ carry the small serializable connection/layout config. Replacing `config` reconnects when `ws_url`
124
+ changes and restores changed layouts; `theme` accepts `light`, `dark`, or a Perspective theme name.
125
+
126
+ Installing this project registers the `perspective` entry point with spaday. The equivalent explicit
127
+ forms are `packages=[spaday_perspective.package]` and `packages=["spaday_perspective:package"]`.
128
+
129
+ > [!NOTE]
130
+ > This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).