dbx-model-catalog 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,54 @@
1
+ Metadata-Version: 2.5
2
+ Name: dbx-model-catalog
3
+ Version: 0.1.8
4
+ Summary: Shared Pydantic models and query services for the Databricks model catalog
5
+ Requires-Python: >=3.12
6
+ Requires-Dist: brotli<2,>=1.1
7
+ Requires-Dist: diskcache<6,>=5.6
8
+ Requires-Dist: platformdirs<5,>=4.3
9
+ Requires-Dist: pydantic<3,>=2.14
10
+ Requires-Dist: python-dateutil<3,>=2.9
11
+ Requires-Dist: rapidfuzz<4,>=3.14
12
+ Description-Content-Type: text/markdown
13
+
14
+ # dbx-model-catalog
15
+
16
+ This Python package contains the Pydantic schema and local read, filter, query,
17
+ and search client for the Databricks model catalog.
18
+
19
+ Load the public catalog:
20
+
21
+ ```py
22
+ from dbx_model_catalog import ModelCatalogClient
23
+
24
+ catalog = ModelCatalogClient.from_published()
25
+ models = catalog.list()
26
+ active = catalog.filter({"status": ["active"]})
27
+ ranked = catalog.search("claude reasoning", limit=5)
28
+ ```
29
+
30
+ `from_published()` downloads
31
+ <https://raw.githubusercontent.com/reggie-db/dbx-model-catalog/main/packages/js/web/catalog/v15/catalog.json>
32
+ and caches the
33
+ payload for one hour in the platform-native user cache directory. Pass
34
+ `refresh=True` to replace the cached value or `cache_ttl` to change its
35
+ lifetime. The package selects the schema lane it was built against; newer
36
+ catalog schema versions can coexist without changing this URL. Every catalog
37
+ includes its source-derived last update timestamp in `updated_at`.
38
+
39
+ Load explicit data when the published endpoint is not appropriate:
40
+
41
+ ```py
42
+ from pathlib import Path
43
+ from dbx_model_catalog import ModelCatalogClient
44
+
45
+ local = ModelCatalogClient.from_json(Path("catalog.json").read_bytes())
46
+ remote = ModelCatalogClient.from_url("https://example.com/catalog.json")
47
+ ```
48
+
49
+ The client also supports Brotli payloads through `from_brotli()`. Search builds
50
+ one in-memory index for the loaded catalog and uses RapidFuzz across model
51
+ identity, publisher, capabilities, tasks, use cases, modalities, availability,
52
+ leaderboards, benchmarks, and notices. Relevance is combined with independent
53
+ version, freshness, lifecycle, leaderboard, and benchmark scores. Query and
54
+ filter operations return standard typed `CatalogModelRecord` lists.
@@ -0,0 +1,41 @@
1
+ # dbx-model-catalog
2
+
3
+ This Python package contains the Pydantic schema and local read, filter, query,
4
+ and search client for the Databricks model catalog.
5
+
6
+ Load the public catalog:
7
+
8
+ ```py
9
+ from dbx_model_catalog import ModelCatalogClient
10
+
11
+ catalog = ModelCatalogClient.from_published()
12
+ models = catalog.list()
13
+ active = catalog.filter({"status": ["active"]})
14
+ ranked = catalog.search("claude reasoning", limit=5)
15
+ ```
16
+
17
+ `from_published()` downloads
18
+ <https://raw.githubusercontent.com/reggie-db/dbx-model-catalog/main/packages/js/web/catalog/v15/catalog.json>
19
+ and caches the
20
+ payload for one hour in the platform-native user cache directory. Pass
21
+ `refresh=True` to replace the cached value or `cache_ttl` to change its
22
+ lifetime. The package selects the schema lane it was built against; newer
23
+ catalog schema versions can coexist without changing this URL. Every catalog
24
+ includes its source-derived last update timestamp in `updated_at`.
25
+
26
+ Load explicit data when the published endpoint is not appropriate:
27
+
28
+ ```py
29
+ from pathlib import Path
30
+ from dbx_model_catalog import ModelCatalogClient
31
+
32
+ local = ModelCatalogClient.from_json(Path("catalog.json").read_bytes())
33
+ remote = ModelCatalogClient.from_url("https://example.com/catalog.json")
34
+ ```
35
+
36
+ The client also supports Brotli payloads through `from_brotli()`. Search builds
37
+ one in-memory index for the loaded catalog and uses RapidFuzz across model
38
+ identity, publisher, capabilities, tasks, use cases, modalities, availability,
39
+ leaderboards, benchmarks, and notices. Relevance is combined with independent
40
+ version, freshness, lifecycle, leaderboard, and benchmark scores. Query and
41
+ filter operations return standard typed `CatalogModelRecord` lists.
@@ -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"
7
+ version = "0.1.8"
8
+ description = "Shared Pydantic models and query services for the Databricks model catalog"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ dependencies = [
12
+ "brotli>=1.1,<2",
13
+ "diskcache>=5.6,<6",
14
+ "platformdirs>=4.3,<5",
15
+ "pydantic>=2.14,<3",
16
+ "python-dateutil>=2.9,<3",
17
+ "rapidfuzz>=3.14,<4",
18
+ ]
19
+
20
+ [dependency-groups]
21
+ dev = ["pytest>=8.4,<9"]
22
+
23
+ [tool.hatch.build.targets.wheel]
24
+ packages = ["src/dbx_model_catalog"]
25
+
26
+ [tool.pytest.ini_options]
27
+ testpaths = ["tests"]
@@ -0,0 +1,93 @@
1
+ from .client import (
2
+ CatalogCacheDirectory,
3
+ CatalogFetch,
4
+ CatalogPayloadDecoder,
5
+ CatalogPayloadEncoding,
6
+ ModelCatalogClient,
7
+ PUBLISHED_CATALOG_BASE_URL,
8
+ PUBLISHED_CATALOG_CACHE_TTL,
9
+ PUBLISHED_CATALOG_INDEX_URL,
10
+ PUBLISHED_CATALOG_SCHEMA_URL,
11
+ PUBLISHED_CATALOG_SCHEMA_VERSION,
12
+ PUBLISHED_CATALOG_URL,
13
+ fetch_published_catalog,
14
+ published_catalog_cache_directory,
15
+ )
16
+ from .database import CATALOG_DATABASE_SCHEMA_VERSION, write_catalog_database
17
+ from .filters import CapabilityName, CatalogFilters
18
+ from .models import (
19
+ MODEL_CATALOG_SCHEMA_VERSION,
20
+ CatalogModel,
21
+ CatalogModelRecord,
22
+ ModelCatalog,
23
+ ModelCatalogSchemaVersion,
24
+ )
25
+ from .query import (
26
+ CatalogOrderBy,
27
+ CatalogOrderByField,
28
+ CatalogPredicate,
29
+ CatalogQuery,
30
+ CatalogQueryExpression,
31
+ CatalogQueryOptions,
32
+ SerializableCatalogQuery,
33
+ parse_catalog_query,
34
+ serialize_catalog_query,
35
+ )
36
+ from .search import (
37
+ CatalogSearchIndex,
38
+ CatalogSearchIndexDocument,
39
+ CatalogSearchIndexPayload,
40
+ CatalogSearchQualityScores,
41
+ CatalogSearchResult,
42
+ CatalogSearchScores,
43
+ CatalogSearchWeights,
44
+ SEARCH_WEIGHTS,
45
+ SearchMatchKind,
46
+ build_catalog_search_index,
47
+ search_catalog_records,
48
+ )
49
+
50
+ __all__ = [
51
+ "CatalogCacheDirectory",
52
+ "CATALOG_DATABASE_SCHEMA_VERSION",
53
+ "CatalogFetch",
54
+ "CatalogFilters",
55
+ "CatalogModel",
56
+ "CatalogModelRecord",
57
+ "CatalogOrderBy",
58
+ "CatalogOrderByField",
59
+ "CatalogPayloadDecoder",
60
+ "CatalogPayloadEncoding",
61
+ "CatalogPredicate",
62
+ "CatalogQuery",
63
+ "CatalogQueryExpression",
64
+ "CatalogQueryOptions",
65
+ "CatalogSearchResult",
66
+ "CatalogSearchIndex",
67
+ "CatalogSearchIndexDocument",
68
+ "CatalogSearchIndexPayload",
69
+ "CatalogSearchQualityScores",
70
+ "CatalogSearchScores",
71
+ "CatalogSearchWeights",
72
+ "CapabilityName",
73
+ "MODEL_CATALOG_SCHEMA_VERSION",
74
+ "ModelCatalog",
75
+ "ModelCatalogClient",
76
+ "ModelCatalogSchemaVersion",
77
+ "PUBLISHED_CATALOG_BASE_URL",
78
+ "PUBLISHED_CATALOG_CACHE_TTL",
79
+ "PUBLISHED_CATALOG_INDEX_URL",
80
+ "PUBLISHED_CATALOG_SCHEMA_URL",
81
+ "PUBLISHED_CATALOG_SCHEMA_VERSION",
82
+ "PUBLISHED_CATALOG_URL",
83
+ "SEARCH_WEIGHTS",
84
+ "SerializableCatalogQuery",
85
+ "SearchMatchKind",
86
+ "build_catalog_search_index",
87
+ "fetch_published_catalog",
88
+ "parse_catalog_query",
89
+ "published_catalog_cache_directory",
90
+ "serialize_catalog_query",
91
+ "search_catalog_records",
92
+ "write_catalog_database",
93
+ ]
@@ -0,0 +1,256 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Callable, Mapping
4
+ from datetime import datetime
5
+ from pathlib import Path
6
+ from typing import Literal, TypeAlias
7
+ from urllib.request import urlopen
8
+
9
+ import brotli
10
+ from diskcache import Cache
11
+ from platformdirs import user_cache_path
12
+
13
+ from .filters import CatalogFilters
14
+ from .models import MODEL_CATALOG_SCHEMA_VERSION, CatalogModelRecord, ModelCatalog
15
+ from .query import CatalogQuery, CatalogQueryOptions, query_catalog_records
16
+ from .search import (
17
+ CatalogSearchIndex,
18
+ CatalogSearchIndexPayload,
19
+ CatalogSearchResult,
20
+ )
21
+
22
+ CatalogPayloadEncoding: TypeAlias = Literal["brotli", "json"]
23
+ CatalogFetch: TypeAlias = Callable[[str], bytes]
24
+ CatalogPayloadDecoder: TypeAlias = Callable[[bytes, CatalogPayloadEncoding], str]
25
+ CatalogCacheDirectory: TypeAlias = str | Path
26
+
27
+ PUBLISHED_CATALOG_BASE_URL = (
28
+ "https://raw.githubusercontent.com/reggie-db/dbx-model-catalog/"
29
+ "main/packages/js/web"
30
+ )
31
+ PUBLISHED_CATALOG_INDEX_URL = f"{PUBLISHED_CATALOG_BASE_URL}/catalog/index.json"
32
+ PUBLISHED_CATALOG_SCHEMA_VERSION = MODEL_CATALOG_SCHEMA_VERSION
33
+ PUBLISHED_CATALOG_SCHEMA_URL = (
34
+ f"{PUBLISHED_CATALOG_BASE_URL}/catalog/v{PUBLISHED_CATALOG_SCHEMA_VERSION}"
35
+ )
36
+ PUBLISHED_CATALOG_URL = f"{PUBLISHED_CATALOG_SCHEMA_URL}/catalog.json"
37
+ PUBLISHED_CATALOG_CACHE_TTL = 3600.0
38
+
39
+
40
+ class ModelCatalogClient:
41
+ def __init__(self, catalog: ModelCatalog) -> None:
42
+ self.catalog = catalog
43
+ self._records = [
44
+ CatalogModelRecord(id=model_id, **model.model_dump())
45
+ for model_id, model in catalog.models.items()
46
+ ]
47
+ self._search_index = CatalogSearchIndex(
48
+ self._records,
49
+ reference_date=catalog.updated_at.date(),
50
+ )
51
+
52
+ @classmethod
53
+ def from_catalog(cls, value: ModelCatalog | Mapping[str, object]) -> ModelCatalogClient:
54
+ return cls(ModelCatalog.model_validate(value))
55
+
56
+ @classmethod
57
+ def from_json(cls, value: str | bytes) -> ModelCatalogClient:
58
+ return cls(ModelCatalog.model_validate_json(value))
59
+
60
+ @classmethod
61
+ def from_brotli(
62
+ cls,
63
+ value: bytes,
64
+ *,
65
+ decode: CatalogPayloadDecoder | None = None,
66
+ ) -> ModelCatalogClient:
67
+ decoder = decode or decode_catalog_payload
68
+ return cls.from_json(decoder(value, "brotli"))
69
+
70
+ @classmethod
71
+ def from_url(
72
+ cls,
73
+ url: str,
74
+ *,
75
+ fetch: CatalogFetch | None = None,
76
+ decode: CatalogPayloadDecoder | None = None,
77
+ ) -> ModelCatalogClient:
78
+ payload = (fetch or fetch_catalog)(url)
79
+ encoding: CatalogPayloadEncoding = (
80
+ "json" if _looks_like_json(payload) else "brotli"
81
+ )
82
+ return cls.from_json((decode or decode_catalog_payload)(payload, encoding))
83
+
84
+ @classmethod
85
+ def from_published(
86
+ cls,
87
+ *,
88
+ refresh: bool = False,
89
+ url: str = PUBLISHED_CATALOG_URL,
90
+ cache_directory: CatalogCacheDirectory | None = None,
91
+ cache_ttl: float = PUBLISHED_CATALOG_CACHE_TTL,
92
+ fetch: CatalogFetch | None = None,
93
+ decode: CatalogPayloadDecoder | None = None,
94
+ ) -> ModelCatalogClient:
95
+ payload = fetch_published_catalog(
96
+ url,
97
+ refresh=refresh,
98
+ cache_directory=cache_directory,
99
+ cache_ttl=cache_ttl,
100
+ fetch=fetch,
101
+ )
102
+ encoding: CatalogPayloadEncoding = (
103
+ "json" if _looks_like_json(payload) else "brotli"
104
+ )
105
+ return cls.from_json((decode or decode_catalog_payload)(payload, encoding))
106
+
107
+ @property
108
+ def schema_version(self) -> int:
109
+ return self.catalog.schema_version
110
+
111
+ @property
112
+ def updated_at(self) -> datetime:
113
+ return self.catalog.updated_at
114
+
115
+ @property
116
+ def size(self) -> int:
117
+ return len(self.catalog.models)
118
+
119
+ @property
120
+ def search_index(self) -> CatalogSearchIndexPayload:
121
+ return self._search_index.payload(
122
+ catalog_schema_version=self.catalog.schema_version,
123
+ updated_at=self.catalog.updated_at,
124
+ )
125
+
126
+ def get(self, model_id: str) -> CatalogModelRecord | None:
127
+ model = self.catalog.models.get(model_id)
128
+ if model is None:
129
+ return None
130
+ return CatalogModelRecord(id=model_id, **model.model_dump())
131
+
132
+ def all(self) -> list[CatalogModelRecord]:
133
+ return self.list()
134
+
135
+ def list(self) -> list[CatalogModelRecord]:
136
+ return list(self._records)
137
+
138
+ def query(
139
+ self,
140
+ expression: CatalogQuery | None = None,
141
+ options: CatalogQueryOptions | Mapping[str, object] | None = None,
142
+ ) -> list[CatalogModelRecord]:
143
+ return query_catalog_records(self.all(), expression, options)
144
+
145
+ def filter(
146
+ self,
147
+ filters: CatalogFilters | Mapping[str, object] | None = None,
148
+ ) -> list[CatalogModelRecord]:
149
+ parsed = CatalogFilters.model_validate(filters or {})
150
+ clauses: list[dict[str, object]] = []
151
+ if parsed.status:
152
+ clauses.append({"status": {"$in": parsed.status}})
153
+ if parsed.model_type:
154
+ clauses.append({"type": {"$in": parsed.model_type}})
155
+ if parsed.publisher:
156
+ clauses.append({"publisher": {"$in": parsed.publisher}})
157
+ for task in parsed.task:
158
+ clauses.append({"tasks": {"$contains": task}})
159
+ for capability in parsed.capability:
160
+ field = capability.replace("-", "_")
161
+ clauses.append(
162
+ {
163
+ "capabilities": {
164
+ field: (
165
+ {"$ne": None}
166
+ if capability == "reasoning"
167
+ else {"$eq": True}
168
+ )
169
+ }
170
+ }
171
+ )
172
+ expression: dict[str, object] = (
173
+ {}
174
+ if not clauses
175
+ else clauses[0]
176
+ if len(clauses) == 1
177
+ else {"$and": clauses}
178
+ )
179
+ records = self.query(expression)
180
+ if parsed.query:
181
+ return [
182
+ result.record
183
+ for result in self._search_index.search(
184
+ parsed.query,
185
+ limit=parsed.limit,
186
+ record_ids={record.id for record in records},
187
+ )
188
+ ]
189
+ records.sort(key=lambda record: (record.name.casefold(), record.id.casefold()))
190
+ return records if parsed.limit is None else records[: parsed.limit]
191
+
192
+ def search(
193
+ self,
194
+ query: str,
195
+ *,
196
+ limit: int | None = 50,
197
+ ) -> list[CatalogSearchResult]:
198
+ return self._search_index.search(query, limit=limit)
199
+
200
+
201
+ def fetch_catalog(url: str) -> bytes:
202
+ with urlopen(url) as response:
203
+ return response.read()
204
+
205
+
206
+ def fetch_published_catalog(
207
+ url: str = PUBLISHED_CATALOG_URL,
208
+ *,
209
+ refresh: bool = False,
210
+ cache_directory: CatalogCacheDirectory | None = None,
211
+ cache_ttl: float = PUBLISHED_CATALOG_CACHE_TTL,
212
+ fetch: CatalogFetch | None = None,
213
+ ) -> bytes:
214
+ loader = fetch or fetch_catalog
215
+ with Cache(published_catalog_cache_directory(cache_directory)) as cache:
216
+ cached_fetch = cache.memoize(
217
+ name="dbx-model-catalog.published-catalog",
218
+ expire=cache_ttl,
219
+ tag="published-catalog",
220
+ )(loader)
221
+ if refresh:
222
+ cache.delete(cached_fetch.__cache_key__(url), retry=True)
223
+ return cached_fetch(url)
224
+
225
+
226
+ def published_catalog_cache_directory(
227
+ directory: CatalogCacheDirectory | None = None,
228
+ ) -> Path:
229
+ if directory is not None:
230
+ return Path(directory)
231
+ return user_cache_path("dbx-model-catalog") / "published-catalog"
232
+
233
+
234
+ def decode_catalog_payload(payload: bytes, encoding: CatalogPayloadEncoding) -> str:
235
+ decoded = payload if encoding == "json" else brotli.decompress(payload)
236
+ return decoded.decode("utf-8")
237
+
238
+
239
+ def _looks_like_json(payload: bytes) -> bool:
240
+ return payload.lstrip().startswith(b"{")
241
+
242
+
243
+ __all__ = [
244
+ "CatalogCacheDirectory",
245
+ "CatalogFetch",
246
+ "CatalogPayloadDecoder",
247
+ "CatalogPayloadEncoding",
248
+ "ModelCatalogClient",
249
+ "PUBLISHED_CATALOG_BASE_URL",
250
+ "PUBLISHED_CATALOG_CACHE_TTL",
251
+ "PUBLISHED_CATALOG_URL",
252
+ "decode_catalog_payload",
253
+ "fetch_catalog",
254
+ "fetch_published_catalog",
255
+ "published_catalog_cache_directory",
256
+ ]