dbook 0.1.0__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.
- dbook-0.1.0/.github/workflows/ci.yml +55 -0
- dbook-0.1.0/.github/workflows/publish.yml +28 -0
- dbook-0.1.0/.gitignore +12 -0
- dbook-0.1.0/CLAUDE.md +105 -0
- dbook-0.1.0/LICENSE +200 -0
- dbook-0.1.0/MANIFEST.in +4 -0
- dbook-0.1.0/PKG-INFO +260 -0
- dbook-0.1.0/PLAN.md +235 -0
- dbook-0.1.0/README.md +208 -0
- dbook-0.1.0/docs/architecture.html +712 -0
- dbook-0.1.0/docs/architecture.svg +160 -0
- dbook-0.1.0/docs/silver-layer.svg +133 -0
- dbook-0.1.0/pyproject.toml +64 -0
- dbook-0.1.0/skills/dbook-navigator/SKILL.md +22 -0
- dbook-0.1.0/src/dbook/__init__.py +7 -0
- dbook-0.1.0/src/dbook/async_catalog.py +77 -0
- dbook-0.1.0/src/dbook/catalog.py +359 -0
- dbook-0.1.0/src/dbook/cli.py +271 -0
- dbook-0.1.0/src/dbook/compiler.py +152 -0
- dbook-0.1.0/src/dbook/domains.py +65 -0
- dbook-0.1.0/src/dbook/embeddings.py +166 -0
- dbook-0.1.0/src/dbook/generators/__init__.py +0 -0
- dbook-0.1.0/src/dbook/generators/checksums.py +30 -0
- dbook-0.1.0/src/dbook/generators/concepts.py +163 -0
- dbook-0.1.0/src/dbook/generators/lineage.py +242 -0
- dbook-0.1.0/src/dbook/generators/manifest.py +55 -0
- dbook-0.1.0/src/dbook/generators/metrics.py +187 -0
- dbook-0.1.0/src/dbook/generators/navigation.py +276 -0
- dbook-0.1.0/src/dbook/generators/table.py +386 -0
- dbook-0.1.0/src/dbook/graph.py +218 -0
- dbook-0.1.0/src/dbook/hasher.py +70 -0
- dbook-0.1.0/src/dbook/incremental.py +180 -0
- dbook-0.1.0/src/dbook/llm/__init__.py +21 -0
- dbook-0.1.0/src/dbook/llm/enricher.py +165 -0
- dbook-0.1.0/src/dbook/llm/prompts.py +89 -0
- dbook-0.1.0/src/dbook/llm/provider.py +261 -0
- dbook-0.1.0/src/dbook/metrics.py +117 -0
- dbook-0.1.0/src/dbook/models.py +77 -0
- dbook-0.1.0/src/dbook/pii/__init__.py +7 -0
- dbook-0.1.0/src/dbook/pii/patterns.py +42 -0
- dbook-0.1.0/src/dbook/pii/scanner.py +219 -0
- dbook-0.1.0/src/dbook/serializer.py +58 -0
- dbook-0.1.0/src/dbook/validator.py +173 -0
- dbook-0.1.0/tests/__init__.py +0 -0
- dbook-0.1.0/tests/amazon_fixture.py +1069 -0
- dbook-0.1.0/tests/benchmark_helpers.py +114 -0
- dbook-0.1.0/tests/conftest.py +1056 -0
- dbook-0.1.0/tests/test_benchmark_agent_simulation.py +358 -0
- dbook-0.1.0/tests/test_benchmark_amazon_correctness.py +428 -0
- dbook-0.1.0/tests/test_benchmark_base.py +227 -0
- dbook-0.1.0/tests/test_benchmark_comprehensive.py +231 -0
- dbook-0.1.0/tests/test_benchmark_correctness.py +381 -0
- dbook-0.1.0/tests/test_benchmark_llm_real.py +362 -0
- dbook-0.1.0/tests/test_benchmark_realistic.py +709 -0
- dbook-0.1.0/tests/test_benchmark_scaled.py +343 -0
- dbook-0.1.0/tests/test_e2e_cli.py +450 -0
- dbook-0.1.0/tests/test_e2e_compile.py +173 -0
- dbook-0.1.0/tests/test_e2e_llm.py +449 -0
- dbook-0.1.0/tests/test_e2e_phase1.py +120 -0
- dbook-0.1.0/tests/test_e2e_pii.py +317 -0
- dbook-0.1.0/tests/test_graph.py +148 -0
- dbook-0.1.0/tests/test_serializer.py +78 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.11", "3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install -e ".[dev]"
|
|
28
|
+
|
|
29
|
+
- name: Run tests
|
|
30
|
+
run: |
|
|
31
|
+
pytest tests/ -q --tb=short --no-header
|
|
32
|
+
|
|
33
|
+
- name: Build package
|
|
34
|
+
run: |
|
|
35
|
+
pip install build
|
|
36
|
+
python -m build --sdist
|
|
37
|
+
|
|
38
|
+
lint:
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
steps:
|
|
41
|
+
- uses: actions/checkout@v4
|
|
42
|
+
|
|
43
|
+
- name: Set up Python
|
|
44
|
+
uses: actions/setup-python@v5
|
|
45
|
+
with:
|
|
46
|
+
python-version: "3.12"
|
|
47
|
+
|
|
48
|
+
- name: Install dependencies
|
|
49
|
+
run: |
|
|
50
|
+
python -m pip install --upgrade pip
|
|
51
|
+
pip install ruff
|
|
52
|
+
|
|
53
|
+
- name: Ruff check
|
|
54
|
+
run: |
|
|
55
|
+
ruff check src/ --output-format concise --quiet
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
environment: pypi
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write # Required for trusted publishing
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Set up Python
|
|
17
|
+
uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.12"
|
|
20
|
+
|
|
21
|
+
- name: Install build tools
|
|
22
|
+
run: pip install build
|
|
23
|
+
|
|
24
|
+
- name: Build package
|
|
25
|
+
run: python -m build
|
|
26
|
+
|
|
27
|
+
- name: Publish to PyPI
|
|
28
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
dbook-0.1.0/.gitignore
ADDED
dbook-0.1.0/CLAUDE.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# dbook — Development Rules
|
|
2
|
+
|
|
3
|
+
## What This Project Is
|
|
4
|
+
A metadata compiler that introspects databases and generates a layered directory of markdown files for AI agent consumption. The output format IS the product — agents read these files to understand databases.
|
|
5
|
+
|
|
6
|
+
## Golden Rules
|
|
7
|
+
|
|
8
|
+
### 1. Never sacrifice output quality to pass a test
|
|
9
|
+
If a test has unrealistic targets, fix the test — do NOT strip content from the output to make the number look better. The output must be genuinely useful for an AI agent. A compact but useless output is worse than a verbose but informative one.
|
|
10
|
+
|
|
11
|
+
### 2. The output format is a UX decision
|
|
12
|
+
Every markdown file an agent reads is a user interface. Treat it with the same care as a frontend component:
|
|
13
|
+
- NAVIGATION.md MUST use markdown tables for schema listings (not bullet lists)
|
|
14
|
+
- Table .md files MUST show all columns with Type, Nullable, Default, PK, and Comment
|
|
15
|
+
- Sample data MUST show 3-5 rows with ALL columns (not truncated)
|
|
16
|
+
- Foreign keys MUST show full qualified references
|
|
17
|
+
- Referenced By sections MUST use schema-qualified names
|
|
18
|
+
|
|
19
|
+
### 3. Benchmark against realistic scale
|
|
20
|
+
- The primary test fixture (13 tables) tests correctness
|
|
21
|
+
- Token savings benchmarks MUST also run against a scaled fixture (50+ tables)
|
|
22
|
+
- All 10 benchmark questions must be tested, not a subset
|
|
23
|
+
- Per-question token breakdown must be reported
|
|
24
|
+
- Baseline = tokens for ALL raw DDL; per-question cost = tokens agent actually reads
|
|
25
|
+
|
|
26
|
+
### 4. Progressive disclosure is the value proposition
|
|
27
|
+
Token savings come from the ARCHITECTURE (read 2-3 files instead of all tables), not from compacting individual files. If NAVIGATION.md is 150 tokens and a table file is 200 tokens, that's fine — the savings come from NOT reading the other 49 table files.
|
|
28
|
+
|
|
29
|
+
### 5. Don't over-filter the concept index
|
|
30
|
+
The concept index should include ALL meaningful terms extracted from table and column names. Filtering out "common" terms like "id", "name", "type" removes the most-searched terms. Only filter truly structural noise: single characters, articles.
|
|
31
|
+
|
|
32
|
+
### 6. Test what matters
|
|
33
|
+
- E2E tests: verify output structure and content completeness
|
|
34
|
+
- Benchmark tests: measure token efficiency at realistic scale AND verify agent can find correct answers
|
|
35
|
+
- No unit tests in isolation — always test the full pipeline
|
|
36
|
+
|
|
37
|
+
## Output Format Specifications
|
|
38
|
+
|
|
39
|
+
### NAVIGATION.md (L0 — must be <300 tokens)
|
|
40
|
+
```
|
|
41
|
+
# Database Book: {dialect}
|
|
42
|
+
Compiled: {timestamp} | Mode: {mode}
|
|
43
|
+
|
|
44
|
+
## Schemas
|
|
45
|
+
|
|
46
|
+
| Schema | Tables | Total Rows | Description |
|
|
47
|
+
|--------|--------|-----------|-------------|
|
|
48
|
+
| auth | 4 | 60,205 | users, sessions, roles, user_roles |
|
|
49
|
+
| billing | 6 | 138,550 | orders, invoices, payments, products, ... |
|
|
50
|
+
|
|
51
|
+
## Quick Reference
|
|
52
|
+
- User data: schemas/auth/users.md
|
|
53
|
+
- Financial: schemas/billing/_manifest.md
|
|
54
|
+
|
|
55
|
+
## How to Navigate
|
|
56
|
+
1. Read this file for overview
|
|
57
|
+
2. Check concepts.json to find specific terms
|
|
58
|
+
3. Read schemas/{name}/_manifest.md for schema details
|
|
59
|
+
4. Read schemas/{name}/{table}.md for full table metadata
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Per-Table .md (L2 — no size limit, completeness matters)
|
|
63
|
+
Must include ALL of these sections when applicable:
|
|
64
|
+
- Header with mechanical summary
|
|
65
|
+
- Columns table (ALL columns, ALL attributes)
|
|
66
|
+
- Primary Key
|
|
67
|
+
- Foreign Keys with full references
|
|
68
|
+
- Indexes
|
|
69
|
+
- Sample Data (3-5 rows, all columns)
|
|
70
|
+
- Referenced By (schema-qualified)
|
|
71
|
+
|
|
72
|
+
### concepts.json (Ls)
|
|
73
|
+
- Include all terms from splitting table/column names on underscores and camelCase
|
|
74
|
+
- Only filter: single characters, pure numbers
|
|
75
|
+
- Each term maps to tables (file paths) and columns (qualified names)
|
|
76
|
+
- aliases field present but empty in base mode (populated by LLM in Phase 5)
|
|
77
|
+
|
|
78
|
+
## Architecture
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
SQLAlchemyCatalog → BookMeta → Compiler → Markdown Directory
|
|
82
|
+
↓
|
|
83
|
+
generators/navigation.py → NAVIGATION.md
|
|
84
|
+
generators/manifest.py → _manifest.md
|
|
85
|
+
generators/table.py → {table}.md
|
|
86
|
+
generators/concepts.py → concepts.json
|
|
87
|
+
generators/checksums.py → checksums.json
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Commands
|
|
91
|
+
```bash
|
|
92
|
+
pip install -e ".[dev]" # Install in dev mode
|
|
93
|
+
pytest tests/ -q --tb=short # Run all tests
|
|
94
|
+
pytest tests/ -v -s # Run with verbose output (see benchmark reports)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Key Files
|
|
98
|
+
- src/dbook/models.py — Data models (ColumnInfo, TableMeta, BookMeta, etc.)
|
|
99
|
+
- src/dbook/catalog.py — Catalog protocol + SQLAlchemyCatalog
|
|
100
|
+
- src/dbook/hasher.py — SHA256 schema hashing
|
|
101
|
+
- src/dbook/compiler.py — Compile BookMeta → markdown directory
|
|
102
|
+
- src/dbook/generators/ — Individual markdown/json generators
|
|
103
|
+
- tests/conftest.py — SQLite test fixture (13 tables)
|
|
104
|
+
- tests/benchmark_helpers.py — AgentSimulator, token counting, BenchmarkReport
|
|
105
|
+
- PLAN.md — Full implementation plan (7 phases)
|
dbook-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. Please also get an
|
|
186
|
+
"Alarm" or "alarm.txt" file (see above).
|
|
187
|
+
|
|
188
|
+
Copyright [yyyy] [name of copyright owner]
|
|
189
|
+
|
|
190
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
191
|
+
you may not use this file except in compliance with the License.
|
|
192
|
+
You may obtain a copy of the License at
|
|
193
|
+
|
|
194
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
195
|
+
|
|
196
|
+
Unless required by applicable law or agreed to in writing, software
|
|
197
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
198
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
199
|
+
implied. See the License for the specific language governing
|
|
200
|
+
permissions and limitations under the License.
|
dbook-0.1.0/MANIFEST.in
ADDED
dbook-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dbook
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Database metadata compiler for AI agent consumption
|
|
5
|
+
Project-URL: Homepage, https://github.com/ShurikM/dbook
|
|
6
|
+
Project-URL: Repository, https://github.com/ShurikM/dbook
|
|
7
|
+
Project-URL: Issues, https://github.com/ShurikM/dbook/issues
|
|
8
|
+
Author-email: Shurik M <shurik@example.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agent,ai,database,introspection,metadata,schema,sql
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Database
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Requires-Dist: click>=8.0
|
|
22
|
+
Requires-Dist: sqlalchemy>=2.0
|
|
23
|
+
Requires-Dist: sqlglot>=20.0
|
|
24
|
+
Provides-Extra: all
|
|
25
|
+
Requires-Dist: anthropic; extra == 'all'
|
|
26
|
+
Requires-Dist: openai; extra == 'all'
|
|
27
|
+
Requires-Dist: presidio-analyzer; extra == 'all'
|
|
28
|
+
Requires-Dist: presidio-anonymizer; extra == 'all'
|
|
29
|
+
Requires-Dist: pyyaml; extra == 'all'
|
|
30
|
+
Provides-Extra: bigquery
|
|
31
|
+
Requires-Dist: sqlalchemy-bigquery; extra == 'bigquery'
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: tiktoken; extra == 'dev'
|
|
35
|
+
Provides-Extra: embeddings
|
|
36
|
+
Requires-Dist: sentence-transformers; extra == 'embeddings'
|
|
37
|
+
Provides-Extra: llm
|
|
38
|
+
Requires-Dist: anthropic; extra == 'llm'
|
|
39
|
+
Requires-Dist: openai; extra == 'llm'
|
|
40
|
+
Provides-Extra: metrics
|
|
41
|
+
Requires-Dist: pyyaml; extra == 'metrics'
|
|
42
|
+
Provides-Extra: mysql
|
|
43
|
+
Requires-Dist: pymysql; extra == 'mysql'
|
|
44
|
+
Provides-Extra: pii
|
|
45
|
+
Requires-Dist: presidio-analyzer; extra == 'pii'
|
|
46
|
+
Requires-Dist: presidio-anonymizer; extra == 'pii'
|
|
47
|
+
Provides-Extra: postgres
|
|
48
|
+
Requires-Dist: psycopg2-binary; extra == 'postgres'
|
|
49
|
+
Provides-Extra: snowflake
|
|
50
|
+
Requires-Dist: snowflake-sqlalchemy; extra == 'snowflake'
|
|
51
|
+
Description-Content-Type: text/markdown
|
|
52
|
+
|
|
53
|
+
# dbook
|
|
54
|
+
|
|
55
|
+
A database metadata compiler that makes AI agents understand your database — not just its structure, but its meaning.
|
|
56
|
+
|
|
57
|
+
> **dbook** compiles your database schema into AI-ready metadata — enum values, semantic relationships, example queries, auto-detected metrics, data lineage, and PII markers. In SQL execution benchmarks, agents with dbook produce 100% correct SQL vs 75% with raw DDL.
|
|
58
|
+
|
|
59
|
+
## The Problem
|
|
60
|
+
|
|
61
|
+
Your AI agents are **blind to your data**.
|
|
62
|
+
|
|
63
|
+
Raw DDL tells agents the structure — but not the meaning:
|
|
64
|
+
- `status VARCHAR(20)` — agents guess "active", "enabled", "1"... the real values are "pending", "shipped", "delivered"
|
|
65
|
+
- `user_id INTEGER REFERENCES users(id)` — but what IS this relationship? The customer? The assignee? The creator?
|
|
66
|
+
- Your gold layer exists because consumers couldn't read silver — but AI agents CAN, with the right metadata
|
|
67
|
+
|
|
68
|
+
**The result:**
|
|
69
|
+
- You maintain expensive gold layer ETL just for AI consumption
|
|
70
|
+
- Every agent re-discovers the schema independently (10 agents = 10x cost)
|
|
71
|
+
- Schema changes break agents silently — no one knows until production fails
|
|
72
|
+
- Agents access PII columns unknowingly — compliance risk with every query
|
|
73
|
+
- Agents guess enum values and write wrong SQL — silent data quality issues
|
|
74
|
+
|
|
75
|
+
## What dbook Does
|
|
76
|
+
|
|
77
|
+
Connects to any database, introspects the schema, and generates structured metadata that gives agents the context DDL lacks:
|
|
78
|
+
|
|
79
|
+
<p align="center">
|
|
80
|
+
<img src="docs/architecture.svg" alt="dbook Architecture" width="800">
|
|
81
|
+
</p>
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install dbook
|
|
85
|
+
dbook compile "postgresql://user:pass@host/db" --output ./my_dbook
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### What agents get:
|
|
89
|
+
|
|
90
|
+
**1. Enum value documentation** — auto-detected via `SELECT DISTINCT`
|
|
91
|
+
```
|
|
92
|
+
status: pending, confirmed, shipped, delivered, cancelled
|
|
93
|
+
method: credit_card, debit_card, paypal, bank_transfer
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**2. Semantic FK descriptions** — agents understand relationships
|
|
97
|
+
```
|
|
98
|
+
→ users via user_id — the customer who placed this order
|
|
99
|
+
← order_items.order_id — line items in this order
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**3. Example queries** — patterns agents can follow
|
|
103
|
+
```sql
|
|
104
|
+
- By status: SELECT * FROM orders WHERE status IN ('pending', 'confirmed')
|
|
105
|
+
- Revenue over time: SELECT DATE(created_at), SUM(total) FROM orders GROUP BY DATE(created_at)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**4. Auto-detected metrics** — common aggregations ready to use
|
|
109
|
+
```
|
|
110
|
+
- Total Amount: SELECT SUM(total) FROM orders
|
|
111
|
+
- Count by Status: SELECT status, COUNT(*) FROM orders GROUP BY status
|
|
112
|
+
- Amount over time: SELECT DATE(created_at), SUM(total) FROM orders GROUP BY DATE(created_at)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**5. Data lineage** — how tables connect in the data flow
|
|
116
|
+
```
|
|
117
|
+
Source tables: users, products (no dependencies)
|
|
118
|
+
Intermediate: orders → depends on users | ← used by order_items, invoices
|
|
119
|
+
Leaf: payments → depends on invoices
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**6. PII detection** — marks sensitive columns, redacts sample data
|
|
123
|
+
```
|
|
124
|
+
| email | VARCHAR(255) | EMAIL (0.90) | high |
|
|
125
|
+
| card_last_four | VARCHAR(4) | CREDIT_CARD_PARTIAL (0.70) | low |
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**7. Query validation** — SQLGlot-powered, catches errors before execution
|
|
129
|
+
```python
|
|
130
|
+
validator = QueryValidator(book)
|
|
131
|
+
result = validator.validate("SELECT * FROM orders WHERE status = 'completed'")
|
|
132
|
+
# Warning: 'completed' not in known values: pending, confirmed, shipped, delivered, cancelled
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Key Benchmark Results
|
|
136
|
+
|
|
137
|
+
### SQL Execution Benchmark: DDL vs dbook
|
|
138
|
+
|
|
139
|
+
Tested on an Amazon-like e-commerce database (34 tables, 15 business tasks, 4 agent types):
|
|
140
|
+
|
|
141
|
+
| Fact Type | Raw DDL | Base dbook | LLM dbook |
|
|
142
|
+
|-----------|---------|-----------|-----------|
|
|
143
|
+
| Structural (column names) | 100% | 100% | 100% |
|
|
144
|
+
| Value-level (enum values) | 21% | 88% | 94% |
|
|
145
|
+
| **Overall key fact coverage** | **76%** | **96%** | **98%** |
|
|
146
|
+
| **SQL execution correctness** | **75%** | **100%** | **100%** |
|
|
147
|
+
|
|
148
|
+
**In the SQL execution benchmark, dbook achieves 100% correct SQL vs 75% with raw DDL** — the difference between agents that guess enum values and agents that know them.
|
|
149
|
+
|
|
150
|
+
### On a 5-table database:
|
|
151
|
+
- DDL key fact coverage: 69% -> dbook: 93% (+24% improvement)
|
|
152
|
+
- SQL execution benchmark: DDL produces 75% correct SQL -> dbook: 100% correct SQL
|
|
153
|
+
|
|
154
|
+
### Agent Discovery (business-term search):
|
|
155
|
+
- 15 real business tasks (billing, sales, support, analytics agents)
|
|
156
|
+
- All 3 modes achieve 15/15 success with mechanical aliases
|
|
157
|
+
- Business terms like "shopping cart", "refund", "A/B test" correctly map to tables
|
|
158
|
+
|
|
159
|
+
### Token Savings (at scale):
|
|
160
|
+
- 50 tables: ~50% fewer tokens per query vs reading all DDL
|
|
161
|
+
- Scales linearly — larger databases see larger savings
|
|
162
|
+
|
|
163
|
+
## Architecture
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
SQLAlchemy Inspector → BookMeta → Compiler → Output Directory
|
|
167
|
+
↓
|
|
168
|
+
NAVIGATION.md (table overview + lineage)
|
|
169
|
+
schemas/
|
|
170
|
+
{schema}/
|
|
171
|
+
_manifest.md (schema details + relationships)
|
|
172
|
+
{table}.md (columns, values, FKs, metrics, examples)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Catalog Protocol
|
|
176
|
+
Database-agnostic via `Catalog` protocol. Default `SQLAlchemyCatalog` supports any SQLAlchemy-compatible database. DB type auto-detected from URL.
|
|
177
|
+
|
|
178
|
+
### Supported Databases
|
|
179
|
+
PostgreSQL, MySQL, SQLite, Snowflake, BigQuery — any database with a SQLAlchemy dialect.
|
|
180
|
+
|
|
181
|
+
## Usage
|
|
182
|
+
|
|
183
|
+
### Full compile
|
|
184
|
+
```bash
|
|
185
|
+
dbook compile "postgresql://user:pass@host/db" --output ./my_dbook
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### With PII detection (marks sensitive columns, redacts sample data)
|
|
189
|
+
```bash
|
|
190
|
+
pip install dbook[pii]
|
|
191
|
+
dbook compile "postgresql://..." --output ./my_dbook --pii
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### With LLM enrichment (semantic summaries, concept aliases)
|
|
195
|
+
```bash
|
|
196
|
+
pip install dbook[llm]
|
|
197
|
+
dbook compile "postgresql://..." --output ./my_dbook --llm --llm-provider anthropic --llm-key sk-...
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Check for schema changes
|
|
201
|
+
```bash
|
|
202
|
+
dbook check ./my_dbook "postgresql://user:pass@host/db"
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Incremental recompile (only changed tables)
|
|
206
|
+
```bash
|
|
207
|
+
dbook compile "postgresql://..." --output ./my_dbook --incremental
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Python API
|
|
211
|
+
```python
|
|
212
|
+
from dbook.catalog import SQLAlchemyCatalog
|
|
213
|
+
from dbook.compiler import compile_book
|
|
214
|
+
from dbook.validator import QueryValidator
|
|
215
|
+
|
|
216
|
+
# Compile
|
|
217
|
+
catalog = SQLAlchemyCatalog("postgresql://user:pass@host/db")
|
|
218
|
+
book = catalog.introspect_all()
|
|
219
|
+
compile_book(book, "./my_dbook")
|
|
220
|
+
|
|
221
|
+
# Validate agent SQL
|
|
222
|
+
validator = QueryValidator(book)
|
|
223
|
+
result = validator.validate("SELECT * FROM orders WHERE status = 'delivered'")
|
|
224
|
+
print(result.valid, result.errors, result.warnings)
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Optional Features
|
|
228
|
+
|
|
229
|
+
| Feature | Install | Flag | What it adds |
|
|
230
|
+
|---------|---------|------|-------------|
|
|
231
|
+
| PII detection | `pip install dbook[pii]` | `--pii` | Column sensitivity markers, sample data redaction |
|
|
232
|
+
| LLM enrichment | `pip install dbook[llm]` | `--llm` | Semantic summaries, concept aliases, schema narratives |
|
|
233
|
+
| Metrics | `pip install dbook[metrics]` | `--metrics` | User-defined canonical business metrics |
|
|
234
|
+
|
|
235
|
+
## The Silver Layer Insight
|
|
236
|
+
|
|
237
|
+
Traditional data pipelines create gold layers because consumers can't read raw data. With dbook, AI agents can understand silver directly — reducing the need for gold views for discovery and ad-hoc queries.
|
|
238
|
+
|
|
239
|
+
<p align="center">
|
|
240
|
+
<img src="docs/silver-layer.svg" alt="The Silver Layer Insight" width="800">
|
|
241
|
+
</p>
|
|
242
|
+
|
|
243
|
+
> **Note:** dbook reduces the need for gold views for discovery and ad-hoc queries.
|
|
244
|
+
> Gold layers still provide value for: enforced business rules, canonical metric
|
|
245
|
+
> definitions, data quality guarantees, and grain standardization. For critical metrics,
|
|
246
|
+
> define them in `metrics.yaml` — dbook includes them in its output so agents use the
|
|
247
|
+
> canonical definition, not their own interpretation.
|
|
248
|
+
|
|
249
|
+
## Development
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
pip install -e ".[dev]"
|
|
253
|
+
pytest tests/ -q --tb=short
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
118 tests covering: introspection, compilation, CLI, PII detection, LLM enrichment, query validation, and realistic agent simulation benchmarks.
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
Apache License 2.0
|