dbgraph 0.1.0__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 (42) hide show
  1. dbgraph/__init__.py +21 -0
  2. dbgraph/application.py +70 -0
  3. dbgraph/builder/__init__.py +0 -0
  4. dbgraph/builder/graph_builder.py +22 -0
  5. dbgraph/builder/sql_graph_builder.py +245 -0
  6. dbgraph/descriptor/__init__.py +0 -0
  7. dbgraph/descriptor/graph_descriptor.py +68 -0
  8. dbgraph/descriptor/langchain_graph_descriptor.py +74 -0
  9. dbgraph/descriptor/prompt_templates.py +80 -0
  10. dbgraph/entity/__init__.py +0 -0
  11. dbgraph/entity/aspect.py +153 -0
  12. dbgraph/entity/asset.py +26 -0
  13. dbgraph/entity/asset_type.py +13 -0
  14. dbgraph/entity/dbgraph.py +152 -0
  15. dbgraph/entity/link.py +37 -0
  16. dbgraph/entity/link_type.py +13 -0
  17. dbgraph/entity/rdbgraph.py +76 -0
  18. dbgraph/event/__init__.py +0 -0
  19. dbgraph/event/event.py +20 -0
  20. dbgraph/event/event_bus.py +61 -0
  21. dbgraph/event/event_handler.py +11 -0
  22. dbgraph/io/__init__.py +0 -0
  23. dbgraph/io/graph_loader.py +11 -0
  24. dbgraph/io/graph_writer.py +11 -0
  25. dbgraph/io/json_graph_loader.py +160 -0
  26. dbgraph/io/json_graph_writer.py +17 -0
  27. dbgraph/persistent/__init__.py +0 -0
  28. dbgraph/persistent/graph_persistent.py +98 -0
  29. dbgraph/persistent/models.py +222 -0
  30. dbgraph/persistent/sql_graph_persistent.py +388 -0
  31. dbgraph/render/__init__.py +0 -0
  32. dbgraph/render/graph_renderer.py +11 -0
  33. dbgraph/render/markdown_renderer.py +111 -0
  34. dbgraph/render/text_renderer.py +11 -0
  35. dbgraph/search/__init__.py +0 -0
  36. dbgraph/search/bm25_search_engine.py +33 -0
  37. dbgraph/search/search_engine.py +15 -0
  38. dbgraph/utils/__init__.py +0 -0
  39. dbgraph/utils/singleton.py +37 -0
  40. dbgraph-0.1.0.dist-info/METADATA +165 -0
  41. dbgraph-0.1.0.dist-info/RECORD +42 -0
  42. dbgraph-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,165 @@
1
+ Metadata-Version: 2.5
2
+ Name: dbgraph
3
+ Version: 0.1.0
4
+ Summary: dbgraph is a database profiling tool which model the database as a graph
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: bm25s[all]>=0.3.9
7
+ Requires-Dist: build>=1.6.0
8
+ Requires-Dist: grip>=4.6.2
9
+ Requires-Dist: langchain-openai>=1.6.0
10
+ Requires-Dist: langchain>=1.3.16
11
+ Requires-Dist: matplotlib>=3.11.0
12
+ Requires-Dist: mkdocs-gen-files>=0.6.1
13
+ Requires-Dist: mkdocs-material>=9.7.7
14
+ Requires-Dist: mkdocs>=1.6.1
15
+ Requires-Dist: mkdocstrings[python]>=1.0.6
16
+ Requires-Dist: openai>=2.45.0
17
+ Requires-Dist: psutil>=7.2.2
18
+ Requires-Dist: pydantic>=2.13.4
19
+ Requires-Dist: pydot>=4.0.1
20
+ Requires-Dist: pympler>=1.1
21
+ Requires-Dist: pystemmer>=3.1.0
22
+ Requires-Dist: pytest>=9.1.1
23
+ Requires-Dist: python-dotenv>=1.2.2
24
+ Requires-Dist: rustworkx>=0.18.0
25
+ Requires-Dist: sqlalchemy>=2.0.52
26
+ Requires-Dist: tqdm>=4.68.4
27
+ Requires-Dist: trino>=0.339.0
28
+ Description-Content-Type: text/markdown
29
+
30
+ # DBGraph - Building schema graph with LLM Assistance
31
+
32
+ **DBGraph** aims to help data scientist with exploring and finding relevant data assets in a huge and complex database.
33
+
34
+ ## Quick Start
35
+
36
+ Here is a quick example of how to build and query a schema graph with DBGraph:
37
+
38
+ ```python
39
+ # imports
40
+ from dbgraph.builder.sqlite.sqlite_graph_builder import SQLiteGraphBuilder
41
+ from dbgraph.io.json_graph_writer import JSONGraphWriter
42
+ from dbgraph.io.json_graph_loader import JSONGraphLoader
43
+ from dbgraph.search.bm25_search_engine import BM25SearchEngine
44
+
45
+ # initiate GraphBuilder on an SQLite database
46
+ graph_builder = SQLiteGraphBuilder(Path("data/northwind.db"))
47
+
48
+ # build the schema graph (include profiling databases)
49
+ graph = graph_builder.build_graph()
50
+
51
+ # generate descriptions for assets
52
+ graph_descriptor = GraphDescriptorV1(
53
+ llm=OAICompatibleLLM(
54
+ model=...,
55
+ base_url=...,
56
+ api_key=...,
57
+ ),
58
+ system_prompt=...,
59
+ formating_prompt=...,
60
+ target_prompt=...
61
+ )
62
+ graph = graph_descriptor.rfill_semantic_aspects(graph)
63
+
64
+ # save the graph
65
+ graph_writer = JSONGraphWriter(
66
+ json_path=Path("data/northwind-graph.json"), indent=2
67
+ )
68
+ graph_writer.write()
69
+
70
+ # load the graph
71
+ graph_loader = JSONGraphLoader(json_path=Path("data/northwind-graph.json"))
72
+ graph = self.graph_loader.load()
73
+
74
+ # index the graph using BM25
75
+ search_engine = BM25SearchEngine(Path("data/northwind-index"))
76
+ semantic_aspects = {
77
+ a.asset_id: cast(SemanticAspect, a.aspects["semantic_properties"])
78
+ for a in graph.assets
79
+ }
80
+ search_engine.index(semantic_aspects)
81
+
82
+ # retrieve assets using BM25
83
+ assets_ids = search_engine.search(
84
+ "Give me the total count of orders in each categories"
85
+ )
86
+ ```
87
+
88
+ For visualization purpose, this is the graph saved in JSON:
89
+
90
+ ```json
91
+ {
92
+ "assets": [
93
+ {
94
+ "asset_id": "8ab5a624-0596-497e-a0ee-3996d95dbe63",
95
+ "name": "Categories",
96
+ "type": "table",
97
+ "aspects": {
98
+ "schema_properties": {
99
+ "name": "Categories_table_schema",
100
+ "pks": ["CategoryID"],
101
+ "indices": {}
102
+ },
103
+ "statistical_properties": {
104
+ "name": "Categories_table_stats",
105
+ "num_columns": 4,
106
+ "num_rows": 8
107
+ },
108
+ "semantic_properties": {
109
+ "name": "Categories_semantic",
110
+ "description": "Stores product category definitions and metadata, serving as a lookup table for classifying products in the inventory system.",
111
+ "keywords": [
112
+ "categories",
113
+ "product classification",
114
+ "category definitions",
115
+ "inventory groups",
116
+ "product types"
117
+ ]
118
+ }
119
+ }
120
+ },
121
+ ...
122
+ ],
123
+ "links": [
124
+ {
125
+ "link_id": "db6bea93-a02c-4426-a2db-449e4a7bba8f",
126
+ "name": "Categories_CategoryID",
127
+ "type": "contain",
128
+ "source_id": "8ab5a624-0596-497e-a0ee-3996d95dbe63",
129
+ "destination_id": "04c20046-2808-4021-bbf1-99876e0eea6e",
130
+ "aspects": {}
131
+ },
132
+ ...
133
+ ]
134
+ }
135
+ ```
136
+
137
+ ## Usecases
138
+
139
+ ![Usecases of DBGraph](diagrams/usecase.png)
140
+ There are 4 main groups of usecases where DBGraph is applicable:
141
+
142
+ - **Manipulating database schema**: Build the schema graph, store it, and use it to traverse around the database, find JOIN path, get references tables, ...
143
+ - **Profiling database**: Use the concept of `Aspect` to represent different types of properties attached to a single data asset.
144
+ Each data asset can have a statistics aspects, semantical aspects, ...
145
+ - **Render graph**: Output schema graph to Markdown or text as context for LLM
146
+ - **LLM Assistance**: Leverage LLM to generate data assets' descriptions and tags. Furthermore, LLM could also be used in the process of SQL generation.
147
+ - **Search for data assets**: Search for wanted data assets based on their descriptions. The descriptions are indexed and retrieved with BM25 algorithms.
148
+
149
+ ## Architecture
150
+
151
+ ![Class diagram of DBGraph](diagrams/entity.png)
152
+
153
+ To encourage open-ness and extension, DBGraph is designed in a way that is very easy to extend.
154
+
155
+ 1. **The core classes** (_entities_) define the shared business logic of database graphs (traversal, neighborhoods, ...) and core operations
156
+ within the application (building graphs, profiling databases, ...). The prefix _"R..."_ stands for _"Relational"_, as the class is dedicated
157
+ Relational databases only. The same stands for _"D.."_ (Document), _"V..."_ (Vector), _"G..."_ (Graph). However, at this point, the only supported
158
+ paradigm is Relational database.
159
+ 2. **The interfaces** (_extensions_) define a part of the system that should be **pluggable**. For example:
160
+
161
+ - `RProfiler` and `RGraphBuilder` should works on multiple types of RDBMS, not just SQLite. Hence the abstraction of `RDataGateway`.
162
+ - We want to support multiple LLM providers. Hence the abstraction of `LLM`.
163
+ - There are many ways to render a graph into Markdown or text. Hence the abstraction of `RGraphRenderer`.
164
+ - To store and load the graph's data from some storages, we have multiple options. Hence the abstraction of `GraphGateway`.
165
+ - To index and retrieve graph's data from some search engines, we also have multiple options. Hence the abstraction of `SearchEngine`
@@ -0,0 +1,42 @@
1
+ dbgraph/__init__.py,sha256=_4z_ceG0sw9nMyaxMxzdcenmtVjwiAgpDDYacYLfp48,716
2
+ dbgraph/application.py,sha256=53L9KYLAfS9LkNY8OPZqMZuJ54RWWSreZRu2otrDkh8,2748
3
+ dbgraph/builder/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ dbgraph/builder/graph_builder.py,sha256=QlR_LB_WIYELX4y1IuztdbjWr3BeO_TgTielqAGNiDo,586
5
+ dbgraph/builder/sql_graph_builder.py,sha256=vxXbLQ5G_etbQ-vc8Q4_Ot0EuMua3AoGRJZPRG3tnwc,9034
6
+ dbgraph/descriptor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ dbgraph/descriptor/graph_descriptor.py,sha256=pz8ED3mhJcr_zCY8wm2-S8mAU_-PWoO_0rl_Xy5BX0c,2635
8
+ dbgraph/descriptor/langchain_graph_descriptor.py,sha256=UxiYIj-k5yGgvMMNPviy-Vn1IY0xVP5OtaOGCRnDjXA,2810
9
+ dbgraph/descriptor/prompt_templates.py,sha256=rMMgdquBnIy93qjgbK-X2t6h-b0dyM_Wuh0OUJ-D6wo,4000
10
+ dbgraph/entity/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ dbgraph/entity/aspect.py,sha256=U2ytORdxGo7D9UmtxCkAQmudUupylmgsVQEytdOK5gY,3904
12
+ dbgraph/entity/asset.py,sha256=5fu7aSAbIuiqWEcwb07D3YiwGUmVLrPCfWmaIuyEJdc,627
13
+ dbgraph/entity/asset_type.py,sha256=kXoNXkOY0PQ64EgVFvJSzrgBFnkBIH_cSXQT3lNLRbk,238
14
+ dbgraph/entity/dbgraph.py,sha256=f8iKvBQCrDeBMddLzMe5iAPFDLGGgJl3Jjv8oB3FTQQ,5356
15
+ dbgraph/entity/link.py,sha256=Op8IKqqFUAGtinXV8u8DN0Zo_x6hoQ8XoB-YwTJxnp8,1185
16
+ dbgraph/entity/link_type.py,sha256=VYWI2ImncHi39Dm8vZqp3yiAnshTSuZVnyaCt3BJ42o,272
17
+ dbgraph/entity/rdbgraph.py,sha256=fl717kbMdvFVsby5Kbk9mq9u8ZCS3G-8-vNhbxU0fZ8,2759
18
+ dbgraph/event/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ dbgraph/event/event.py,sha256=xELHK_r7qZzigX_dB4B8YKzLXd8ZuDOz9PB8RRzSCCg,386
20
+ dbgraph/event/event_bus.py,sha256=Aj4_drzpHT6DW9AbsJvcLF5BZu-8uvQV6wCFj337tYo,2087
21
+ dbgraph/event/event_handler.py,sha256=x5R5BFfJ8Qon1aZusyKdJ79imlY7xLCXJ5tp5VltpDw,239
22
+ dbgraph/io/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
+ dbgraph/io/graph_loader.py,sha256=53ROOIZYoSIuWy1ALzsMUySm-WeahumqxdfrhWVS7I0,253
24
+ dbgraph/io/graph_writer.py,sha256=nWJ3xe97LXKOJm763R7h-lreiCGGrSIudhsgbLCGNBQ,257
25
+ dbgraph/io/json_graph_loader.py,sha256=GoV_ziCpPCIO_TAK68_iMUcI180O8Mv1Ad2iqwciQSQ,6270
26
+ dbgraph/io/json_graph_writer.py,sha256=kmKMHfOA8ieJZgJck3gkJ1F2YCjVXEfUNojwIw4dD8k,473
27
+ dbgraph/persistent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
+ dbgraph/persistent/graph_persistent.py,sha256=9itKwW-OSWtfx7TXdWtl-CrfCaKphMVkjfxkh7VX2Vc,3298
29
+ dbgraph/persistent/models.py,sha256=wjXnPDbQqMtMO_uhASfGFBRkjzIsQ8QXQd5FBOPn7F4,4900
30
+ dbgraph/persistent/sql_graph_persistent.py,sha256=rrLCEKN0jzseC_iPG2nPHeBHv6ib0Ihyx2DbgUswbQ8,15151
31
+ dbgraph/render/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
+ dbgraph/render/graph_renderer.py,sha256=SJvf0IZGDnEjy9n2uXD5mUq7FIm5nL_Gw8k2cn15i5E,294
33
+ dbgraph/render/markdown_renderer.py,sha256=oJKRf7JNZUEEeiS-IUrxq6mbkWq3PAXXgzBSqe-yOR0,4846
34
+ dbgraph/render/text_renderer.py,sha256=l0Q8zh-tN09UVqSpNNrS9XJ9MRPqmryYS3eixdM1eZ4,289
35
+ dbgraph/search/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
+ dbgraph/search/bm25_search_engine.py,sha256=xayZSIMSgGjbSkI1jsT7tC6S2wvQ4mkOd39OA36bdHk,1168
37
+ dbgraph/search/search_engine.py,sha256=sXnA6VOmd_pKuBwhXrBw38Tx7c10lFJi2NQdLnNCCa0,414
38
+ dbgraph/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
+ dbgraph/utils/singleton.py,sha256=9sYBaQt3ILqoMgovYVusMqSzmi60yA6VbMFRiw78LLs,1498
40
+ dbgraph-0.1.0.dist-info/METADATA,sha256=DqCWa8dQp23myPTy9po9Qh-r9xQzor5ZhfZHe_Q2jQo,6073
41
+ dbgraph-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
42
+ dbgraph-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any