dbx-model-catalog-server 0.1.8__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.
@@ -0,0 +1,89 @@
1
+ # ---- Secrets / environment ----------------------------------------------
2
+ .env
3
+ .env.*
4
+ *.env
5
+ .envrc
6
+ secrets.*
7
+ *.secret
8
+
9
+ # ---- Lock files (may embed local proxy URLs / creds -- do not commit) -----
10
+ uv.lock
11
+ poetry.lock
12
+ Pipfile.lock
13
+ package-lock.json
14
+ npm-shrinkwrap.json
15
+ yarn.lock
16
+ pnpm-lock.yaml
17
+ bun.lock
18
+ bun.lockb
19
+
20
+ # ---- Python --------------------------------------------------------------
21
+ __pycache__/
22
+ *.py[cod]
23
+ *$py.class
24
+ *.egg
25
+ *.egg-info/
26
+ .eggs/
27
+ build/
28
+ dist/
29
+ wheels/
30
+ .installed.cfg
31
+ .Python
32
+ .venv/
33
+ venv/
34
+ env/
35
+ ENV/
36
+ .python-version
37
+ .pytest_cache/
38
+ .ruff_cache/
39
+ .mypy_cache/
40
+ .dmypy.json
41
+ .pyre/
42
+ .ipynb_checkpoints/
43
+ .coverage
44
+ .coverage.*
45
+ htmlcov/
46
+ .tox/
47
+ .nox/
48
+
49
+ # ---- Node / npm / bun ----------------------------------------------------
50
+ node_modules/
51
+ .npm/
52
+ .bun/
53
+ .pnp.*
54
+ .yarn/
55
+ dist/
56
+ build/
57
+ dist-node/
58
+ *.tsbuildinfo
59
+ packages/js/web/dist/
60
+
61
+ # ---- Databricks ----------------------------------------------------------
62
+ .databricks/
63
+ .databricks-login.json
64
+
65
+ # ---- IDE / editor caches -------------------------------------------------
66
+ .idea/
67
+ .vscode/
68
+ *.swp
69
+ *.swo
70
+ *.sublime-project
71
+ *.sublime-workspace
72
+ .history/
73
+
74
+ # ---- Temp / scratch ------------------------------------------------------
75
+ .kanna/
76
+ tmp/
77
+ temp/
78
+ *.tmp
79
+ *.temp
80
+ *.log
81
+ *.bak
82
+ *.cache
83
+
84
+ # ---- OS cruft ------------------------------------------------------------
85
+ .DS_Store
86
+ .DS_Store?
87
+ ._*
88
+ Thumbs.db
89
+ desktop.ini
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.5
2
+ Name: dbx-model-catalog-server
3
+ Version: 0.1.8
4
+ Summary: Chanx server for dbx-model-catalog
5
+ Requires-Python: >=3.12
6
+ Requires-Dist: chanx[fast-channels]<3,>=2.13
7
+ Requires-Dist: dbx-model-catalog
8
+ Requires-Dist: fastapi<1,>=0.120
9
+ Requires-Dist: pynect<2,>=1.0.0
10
+ Requires-Dist: uvicorn[standard]<1,>=0.40
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.28,<2"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "dbx-model-catalog-server"
7
+ version = "0.1.8"
8
+ description = "Chanx server for dbx-model-catalog"
9
+ requires-python = ">=3.12"
10
+ dependencies = [
11
+ "chanx[fast_channels]>=2.13,<3",
12
+ "dbx-model-catalog",
13
+ "fastapi>=0.120,<1",
14
+ "pynect>=1.0.0,<2",
15
+ "uvicorn[standard]>=0.40,<1",
16
+ ]
17
+
18
+ [tool.hatch.build.targets.wheel]
19
+ packages = ["src/dbx_model_catalog_server"]
20
+
21
+ [tool.pynect]
22
+ name = "dbx-model-catalog"
23
+ app = "dbx_model_catalog_server.app:app"
24
+ out = "../../js/client/src/_generated"
25
+
26
+ [tool.uv.sources]
27
+ dbx-model-catalog = { workspace = true }
@@ -0,0 +1,3 @@
1
+ from .app import app
2
+
3
+ __all__ = ["app"]
@@ -0,0 +1,142 @@
1
+ import os
2
+ from collections.abc import AsyncIterator
3
+ from pathlib import Path
4
+ from typing import Literal
5
+
6
+ from chanx.core.decorators import channel, ws_handler
7
+ from chanx.fast_channels import asyncapi_docs, asyncapi_spec_json
8
+ from chanx.fast_channels.type_defs import AsyncAPIConfig
9
+ from chanx.messages.base import BaseMessage
10
+ from dbx_model_catalog import (
11
+ CatalogFilters,
12
+ CatalogModelRecord,
13
+ CatalogSearchIndexPayload,
14
+ ModelCatalog,
15
+ ModelCatalogClient,
16
+ )
17
+ from fastapi import FastAPI, Request
18
+ from fastapi.responses import HTMLResponse, JSONResponse
19
+ from fastapi.staticfiles import StaticFiles
20
+ from pynect import AsyncJsonWebsocketConsumer
21
+
22
+
23
+ class GetCatalogRequest(BaseMessage):
24
+ action: Literal["get_catalog"] = "get_catalog"
25
+ payload: CatalogFilters
26
+
27
+
28
+ class GetCatalogResponse(BaseMessage):
29
+ action: Literal["catalog"] = "catalog"
30
+ payload: ModelCatalog
31
+
32
+
33
+ class GetSearchIndexRequest(BaseMessage):
34
+ action: Literal["get_search_index"] = "get_search_index"
35
+ payload: CatalogFilters
36
+
37
+
38
+ class GetSearchIndexResponse(BaseMessage):
39
+ action: Literal["search_index"] = "search_index"
40
+ payload: CatalogSearchIndexPayload
41
+
42
+
43
+ class ListModelsRequest(BaseMessage):
44
+ action: Literal["list_models"] = "list_models"
45
+ payload: CatalogFilters
46
+
47
+
48
+ class ListModelsResponse(BaseMessage):
49
+ action: Literal["models"] = "models"
50
+ payload: list[CatalogModelRecord]
51
+
52
+
53
+ class StreamModelsRequest(BaseMessage):
54
+ action: Literal["stream_models"] = "stream_models"
55
+ payload: CatalogFilters
56
+
57
+
58
+ class StreamModelsResponse(BaseMessage):
59
+ action: Literal["model"] = "model"
60
+ payload: CatalogModelRecord
61
+
62
+
63
+ def _catalog_path() -> Path | None:
64
+ configured = os.environ.get("DBX_MODEL_CATALOG_PATH")
65
+ return Path(configured).expanduser().resolve() if configured else None
66
+
67
+
68
+ def _catalog_service() -> ModelCatalogClient:
69
+ path = _catalog_path()
70
+ return (
71
+ ModelCatalogClient.from_json(path.read_bytes())
72
+ if path is not None
73
+ else ModelCatalogClient.from_published()
74
+ )
75
+
76
+
77
+ catalog = _catalog_service()
78
+
79
+
80
+ @channel(name="models", description="Read and filter the model catalog")
81
+ class ModelsConsumer(AsyncJsonWebsocketConsumer):
82
+ @ws_handler
83
+ async def get_catalog(self, _message: GetCatalogRequest) -> GetCatalogResponse:
84
+ return GetCatalogResponse(payload=catalog.catalog)
85
+
86
+ @ws_handler
87
+ async def get_search_index(
88
+ self,
89
+ _message: GetSearchIndexRequest,
90
+ ) -> GetSearchIndexResponse:
91
+ return GetSearchIndexResponse(payload=catalog.search_index)
92
+
93
+ @ws_handler
94
+ async def list_models(self, message: ListModelsRequest) -> ListModelsResponse:
95
+ return ListModelsResponse(payload=catalog.filter(message.payload))
96
+
97
+ @ws_handler
98
+ async def stream_models(
99
+ self,
100
+ message: StreamModelsRequest,
101
+ ) -> AsyncIterator[StreamModelsResponse]:
102
+ for model in catalog.filter(message.payload):
103
+ yield StreamModelsResponse(payload=model)
104
+
105
+
106
+ app = FastAPI(title="dbx-model-catalog", version="1.0.0")
107
+ app.router.add_websocket_route("/ws/models", ModelsConsumer.as_asgi())
108
+
109
+ asyncapi_config = AsyncAPIConfig(
110
+ description="Python-owned dbx-model-catalog API",
111
+ version="1.0.0",
112
+ )
113
+
114
+
115
+ @app.get("/health")
116
+ async def health() -> dict[str, str]:
117
+ return {"status": "ok"}
118
+
119
+
120
+ @app.get("/asyncapi")
121
+ async def asyncapi_documentation(request: Request) -> HTMLResponse:
122
+ return await asyncapi_docs(request=request, app=app, config=asyncapi_config)
123
+
124
+
125
+ @app.get("/asyncapi.json")
126
+ async def asyncapi_json(request: Request) -> JSONResponse:
127
+ return await asyncapi_spec_json(
128
+ request=request,
129
+ app=app,
130
+ config=asyncapi_config,
131
+ )
132
+
133
+
134
+ web_directory = (
135
+ Path(__file__).resolve().parents[5]
136
+ / "packages"
137
+ / "js"
138
+ / "web"
139
+ / "dist"
140
+ )
141
+ if (web_directory / "index.html").is_file():
142
+ app.mount("/", StaticFiles(directory=web_directory, html=True), name="web")