chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:25:07 +08:00
commit a26e856398
1681 changed files with 296950 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
# python-starlette
This example contains a simple `perspective-python` folder that uses
Starlette/FastAPI to serve a static dataset.
<span class="warning">
This example will not work outside the Perspective source tree! You will need a working local Perspective build to run it.
</span>
+11
View File
@@ -0,0 +1,11 @@
{
"name": "python-starlette",
"private": true,
"version": "4.5.2",
"description": "An example of editing a `perspective-python` server from the browser.",
"scripts": {
"start": "PYTHONPATH=../../python/perspective python3 server.py"
},
"keywords": [],
"license": "Apache-2.0"
}
+60
View File
@@ -0,0 +1,60 @@
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
# ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
# ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
# ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
# ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
# ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
# ┃ Copyright (c) 2017, the Perspective Authors. ┃
# ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
# ┃ This file is part of the Perspective library, distributed under the terms ┃
# ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
import os
import os.path
import logging
import uvicorn
from fastapi import FastAPI, WebSocket
from starlette.responses import FileResponse
from starlette.staticfiles import StaticFiles
from perspective import Server
from perspective.handlers.starlette import PerspectiveStarletteHandler
here = os.path.abspath(os.path.dirname(__file__))
file_path = os.path.join(
here, ".", "node_modules", "superstore-arrow", "superstore.lz4.arrow"
)
def static_node_modules_handler(rest_of_path):
return FileResponse("../../node_modules/{}".format(rest_of_path))
def make_app():
server = Server()
client = server.new_local_client()
with open(file_path, mode="rb") as file:
client.table(file.read(), index="Row ID", name="data_source_one")
async def websocket_handler(websocket: WebSocket):
handler = PerspectiveStarletteHandler(
perspective_server=server, websocket=websocket
)
await handler.run()
static_html_files = StaticFiles(directory="../python-tornado", html=True)
app = FastAPI()
app.add_api_websocket_route("/websocket", websocket_handler)
app.get("/node_modules/{rest_of_path:path}")(static_node_modules_handler)
app.mount("/", static_html_files)
return app
if __name__ == "__main__":
app = make_app()
logging.critical("Listening on http://localhost:8080")
uvicorn.run(app, host="0.0.0.0", port=8080)