trellis-datamodel 0.3.3__py3-none-any.whl

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 (52) hide show
  1. trellis_datamodel/__init__.py +8 -0
  2. trellis_datamodel/adapters/__init__.py +41 -0
  3. trellis_datamodel/adapters/base.py +147 -0
  4. trellis_datamodel/adapters/dbt_core.py +975 -0
  5. trellis_datamodel/cli.py +292 -0
  6. trellis_datamodel/config.py +239 -0
  7. trellis_datamodel/models/__init__.py +13 -0
  8. trellis_datamodel/models/schemas.py +28 -0
  9. trellis_datamodel/routes/__init__.py +11 -0
  10. trellis_datamodel/routes/data_model.py +221 -0
  11. trellis_datamodel/routes/manifest.py +110 -0
  12. trellis_datamodel/routes/schema.py +183 -0
  13. trellis_datamodel/server.py +101 -0
  14. trellis_datamodel/static/_app/env.js +1 -0
  15. trellis_datamodel/static/_app/immutable/assets/0.ByDwyx3a.css +1 -0
  16. trellis_datamodel/static/_app/immutable/assets/2.DLAp_5AW.css +1 -0
  17. trellis_datamodel/static/_app/immutable/assets/trellis_squared.CTOnsdDx.svg +127 -0
  18. trellis_datamodel/static/_app/immutable/chunks/8ZaN1sxc.js +1 -0
  19. trellis_datamodel/static/_app/immutable/chunks/BfBfOTnK.js +1 -0
  20. trellis_datamodel/static/_app/immutable/chunks/C3yhlRfZ.js +2 -0
  21. trellis_datamodel/static/_app/immutable/chunks/CK3bXPEX.js +1 -0
  22. trellis_datamodel/static/_app/immutable/chunks/CXDUumOQ.js +1 -0
  23. trellis_datamodel/static/_app/immutable/chunks/DDNfEvut.js +1 -0
  24. trellis_datamodel/static/_app/immutable/chunks/DUdVct7e.js +1 -0
  25. trellis_datamodel/static/_app/immutable/chunks/QRltG_J6.js +2 -0
  26. trellis_datamodel/static/_app/immutable/chunks/zXDdy2c_.js +1 -0
  27. trellis_datamodel/static/_app/immutable/entry/app.abCkWeAJ.js +2 -0
  28. trellis_datamodel/static/_app/immutable/entry/start.B7CjH6Z7.js +1 -0
  29. trellis_datamodel/static/_app/immutable/nodes/0.bFI_DI3G.js +1 -0
  30. trellis_datamodel/static/_app/immutable/nodes/1.J_r941Qf.js +1 -0
  31. trellis_datamodel/static/_app/immutable/nodes/2.WqbMkq6o.js +27 -0
  32. trellis_datamodel/static/_app/version.json +1 -0
  33. trellis_datamodel/static/index.html +40 -0
  34. trellis_datamodel/static/robots.txt +3 -0
  35. trellis_datamodel/static/trellis_squared.svg +127 -0
  36. trellis_datamodel/tests/__init__.py +2 -0
  37. trellis_datamodel/tests/conftest.py +132 -0
  38. trellis_datamodel/tests/test_cli.py +526 -0
  39. trellis_datamodel/tests/test_data_model.py +151 -0
  40. trellis_datamodel/tests/test_dbt_schema.py +892 -0
  41. trellis_datamodel/tests/test_manifest.py +72 -0
  42. trellis_datamodel/tests/test_server_static.py +44 -0
  43. trellis_datamodel/tests/test_yaml_handler.py +228 -0
  44. trellis_datamodel/utils/__init__.py +2 -0
  45. trellis_datamodel/utils/yaml_handler.py +365 -0
  46. trellis_datamodel-0.3.3.dist-info/METADATA +333 -0
  47. trellis_datamodel-0.3.3.dist-info/RECORD +52 -0
  48. trellis_datamodel-0.3.3.dist-info/WHEEL +5 -0
  49. trellis_datamodel-0.3.3.dist-info/entry_points.txt +2 -0
  50. trellis_datamodel-0.3.3.dist-info/licenses/LICENSE +661 -0
  51. trellis_datamodel-0.3.3.dist-info/licenses/NOTICE +6 -0
  52. trellis_datamodel-0.3.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,8 @@
1
+ """Trellis Data - Visual data model editor for dbt projects."""
2
+
3
+ from importlib.metadata import version, PackageNotFoundError
4
+
5
+ try:
6
+ __version__ = version("trellis-datamodel")
7
+ except PackageNotFoundError:
8
+ __version__ = "0.0.0"
@@ -0,0 +1,41 @@
1
+ """
2
+ Adapter factory for transformation framework integrations.
3
+
4
+ Provides get_adapter() to instantiate the appropriate adapter based on config.
5
+ """
6
+
7
+ from typing import Union
8
+
9
+ from trellis_datamodel import config as cfg
10
+ from .base import TransformationAdapter
11
+ from .dbt_core import DbtCoreAdapter
12
+
13
+
14
+ def get_adapter() -> Union[DbtCoreAdapter, TransformationAdapter]:
15
+ """
16
+ Get the appropriate adapter based on the configured framework.
17
+
18
+ Returns:
19
+ An adapter instance implementing TransformationAdapter.
20
+
21
+ Raises:
22
+ ValueError: If the configured framework is not supported.
23
+ """
24
+ # Always read from the live config module (cfg) to respect load_config()
25
+ if cfg.FRAMEWORK == "dbt-core":
26
+ return DbtCoreAdapter(
27
+ manifest_path=cfg.MANIFEST_PATH,
28
+ catalog_path=cfg.CATALOG_PATH,
29
+ project_path=cfg.DBT_PROJECT_PATH,
30
+ data_model_path=cfg.DATA_MODEL_PATH,
31
+ model_paths=cfg.DBT_MODEL_PATHS,
32
+ )
33
+
34
+ raise ValueError(
35
+ f"Unknown framework: {cfg.FRAMEWORK}. "
36
+ f"Supported frameworks: dbt-core"
37
+ )
38
+
39
+
40
+ __all__ = ["get_adapter", "TransformationAdapter", "DbtCoreAdapter"]
41
+
@@ -0,0 +1,147 @@
1
+ """
2
+ Base adapter protocol for transformation framework integrations.
3
+
4
+ This module defines the contract that all framework adapters must implement,
5
+ enabling support for dbt-core, SQLMesh, Bruin, etc.
6
+ """
7
+
8
+ from pathlib import Path
9
+ from typing import Protocol, TypedDict, Optional, Any
10
+
11
+
12
+ class ColumnInfo(TypedDict):
13
+ """Column metadata from a transformation framework."""
14
+
15
+ name: str
16
+ type: Optional[str]
17
+
18
+
19
+ class ModelInfo(TypedDict):
20
+ """Model metadata returned by get_models()."""
21
+
22
+ unique_id: str
23
+ name: str
24
+ version: Optional[int]
25
+ schema: str
26
+ table: str
27
+ columns: list[ColumnInfo]
28
+ description: Optional[str]
29
+ materialization: str
30
+ file_path: str
31
+ tags: list[str]
32
+
33
+
34
+ class ColumnSchema(TypedDict, total=False):
35
+ """Column schema for reading/writing model definitions."""
36
+
37
+ name: str
38
+ data_type: Optional[str]
39
+ description: Optional[str]
40
+ data_tests: Optional[list[dict[str, Any]]]
41
+
42
+
43
+ class ModelSchema(TypedDict, total=False):
44
+ """Model schema for reading/writing model definitions."""
45
+
46
+ model_name: str
47
+ description: str
48
+ columns: list[ColumnSchema]
49
+ tags: list[str]
50
+ file_path: str
51
+
52
+
53
+ class Relationship(TypedDict):
54
+ """Relationship inferred from framework metadata."""
55
+
56
+ source: str
57
+ target: str
58
+ label: str
59
+ type: str # e.g., "one_to_many"
60
+ source_field: str
61
+ target_field: str
62
+
63
+
64
+ class TransformationAdapter(Protocol):
65
+ """
66
+ Protocol defining the interface for transformation framework adapters.
67
+
68
+ Implementations should handle framework-specific parsing and schema generation.
69
+ """
70
+
71
+ def get_models(self) -> list[ModelInfo]:
72
+ """
73
+ Parse framework metadata and return available models.
74
+
75
+ Returns:
76
+ List of model metadata dictionaries.
77
+ """
78
+ ...
79
+
80
+ def get_model_schema(self, model_name: str, version: Optional[int] = None) -> ModelSchema:
81
+ """
82
+ Get the current schema definition for a specific model.
83
+
84
+ Args:
85
+ model_name: Name of the model to retrieve.
86
+ version: Optional version number to disambiguate versioned models.
87
+
88
+ Returns:
89
+ Model schema including columns and metadata.
90
+ """
91
+ ...
92
+
93
+ def save_model_schema(
94
+ self,
95
+ model_name: str,
96
+ columns: list[ColumnSchema],
97
+ description: Optional[str] = None,
98
+ tags: Optional[list[str]] = None,
99
+ version: Optional[int] = None,
100
+ ) -> Path:
101
+ """
102
+ Save/update the schema definition for a model.
103
+
104
+ Args:
105
+ model_name: Name of the model to update.
106
+ version: Optional version number to target for versioned models.
107
+ columns: Column definitions to save.
108
+ description: Optional model description.
109
+ tags: Optional list of tags.
110
+
111
+ Returns:
112
+ Path to the saved schema file.
113
+ """
114
+ ...
115
+
116
+ def infer_relationships(self, include_unbound: bool = False) -> list[Relationship]:
117
+ """
118
+ Scan framework schema files and infer entity relationships.
119
+
120
+ Args:
121
+ include_unbound: When True, also include relationships for entities
122
+ that exist in the data model but are not yet bound to a dbt
123
+ model. Useful for frontends that want immediate inference right
124
+ after a bind action, before the data model file is persisted.
125
+
126
+ Returns:
127
+ List of inferred relationships.
128
+ """
129
+ ...
130
+
131
+ def sync_relationships(
132
+ self,
133
+ entities: list[dict[str, Any]],
134
+ relationships: list[dict[str, Any]],
135
+ ) -> list[Path]:
136
+ """
137
+ Sync relationship definitions from data model to framework schema files.
138
+
139
+ Args:
140
+ entities: List of entity definitions from the data model.
141
+ relationships: List of relationship definitions to sync.
142
+
143
+ Returns:
144
+ List of paths to updated schema files.
145
+ """
146
+ ...
147
+