schematell 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anjal Antony
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: schematell
3
+ Version: 0.1.0
4
+ Summary: Understand database structures in plain English without writing SQL.
5
+ Author-email: Anjal <anjalantony1111@gmail.com>
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # schematell šŸ”
12
+
13
+ > Understand SQLite database schemas in plain English and audit relational integrity without writing SQL.
14
+
15
+ `schematell` is a lightweight Python developer tool that inspects SQLite tables, generates narrative summaries of columns and keys, audits orphaned foreign key relationships, and exports Mermaid.js ER diagrams for documentation.
16
+
17
+ ---
18
+
19
+ ## šŸš€ Installation
20
+
21
+ ```bash
22
+ git clone [https://github.com/](https://github.com/)<YOUR_GITHUB_USERNAME>/schematell.git
23
+ cd schematell
24
+ pip install -e .
@@ -0,0 +1,14 @@
1
+ # schematell šŸ”
2
+
3
+ > Understand SQLite database schemas in plain English and audit relational integrity without writing SQL.
4
+
5
+ `schematell` is a lightweight Python developer tool that inspects SQLite tables, generates narrative summaries of columns and keys, audits orphaned foreign key relationships, and exports Mermaid.js ER diagrams for documentation.
6
+
7
+ ---
8
+
9
+ ## šŸš€ Installation
10
+
11
+ ```bash
12
+ git clone [https://github.com/](https://github.com/)<YOUR_GITHUB_USERNAME>/schematell.git
13
+ cd schematell
14
+ pip install -e .
@@ -0,0 +1,14 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "schematell"
7
+ version = "0.1.0"
8
+ authors = [{ name="Anjal", email="anjalantony1111@gmail.com" }]
9
+ description = "Understand database structures in plain English without writing SQL."
10
+ readme = "README.md"
11
+ requires-python = ">=3.8"
12
+
13
+ [tool.setuptools]
14
+ py-modules = ["schematell"]
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: schematell
3
+ Version: 0.1.0
4
+ Summary: Understand database structures in plain English without writing SQL.
5
+ Author-email: Anjal <anjalantony1111@gmail.com>
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # schematell šŸ”
12
+
13
+ > Understand SQLite database schemas in plain English and audit relational integrity without writing SQL.
14
+
15
+ `schematell` is a lightweight Python developer tool that inspects SQLite tables, generates narrative summaries of columns and keys, audits orphaned foreign key relationships, and exports Mermaid.js ER diagrams for documentation.
16
+
17
+ ---
18
+
19
+ ## šŸš€ Installation
20
+
21
+ ```bash
22
+ git clone [https://github.com/](https://github.com/)<YOUR_GITHUB_USERNAME>/schematell.git
23
+ cd schematell
24
+ pip install -e .
@@ -0,0 +1,8 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ schematell.py
5
+ schematell.egg-info/PKG-INFO
6
+ schematell.egg-info/SOURCES.txt
7
+ schematell.egg-info/dependency_links.txt
8
+ schematell.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ schematell
@@ -0,0 +1,178 @@
1
+
2
+ """
3
+ schematell: Plain-English database introspection, relationship auditing, and ER diagram export.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import os
9
+ import sqlite3
10
+ from dataclasses import dataclass, field
11
+ from pathlib import Path
12
+ from typing import Any, Dict, List
13
+
14
+
15
+ @dataclass
16
+ class ColumnMeta:
17
+ cid: int
18
+ name: str
19
+ data_type: str
20
+ not_null: bool
21
+ default_value: Any
22
+ is_pk: bool
23
+
24
+
25
+ @dataclass
26
+ class ForeignKeyMeta:
27
+ target_table: str
28
+ from_col: str
29
+ to_col: str
30
+
31
+
32
+ @dataclass
33
+ class TableReport:
34
+ name: str
35
+ row_count: int
36
+ columns: List[ColumnMeta] = field(default_factory=list)
37
+ foreign_keys: List[ForeignKeyMeta] = field(default_factory=list)
38
+ orphaned_records: Dict[str, int] = field(default_factory=dict)
39
+ warnings: List[str] = field(default_factory=list)
40
+
41
+ @property
42
+ def primary_keys(self) -> List[str]:
43
+ return [c.name for c in self.columns if c.is_pk]
44
+
45
+
46
+ class Database:
47
+ """Read-only schema introspector and relational auditor for SQLite."""
48
+
49
+ def __init__(self, db_path: str | Path):
50
+ self.db_path = Path(db_path)
51
+ if not self.db_path.exists():
52
+ raise FileNotFoundError(f"Database file not found: {self.db_path}")
53
+
54
+ # Connect in strict read-only mode to prevent accidental writes
55
+ uri = f"file:{self.db_path.resolve()}?mode=ro"
56
+ self.conn = sqlite3.connect(uri, uri=True)
57
+ self.cursor = self.conn.cursor()
58
+
59
+ def _get_tables(self) -> List[str]:
60
+ query = (
61
+ "SELECT name FROM sqlite_master "
62
+ "WHERE type='table' AND name NOT LIKE 'sqlite_%' "
63
+ "ORDER BY name;"
64
+ )
65
+ self.cursor.execute(query)
66
+ return [row[0] for row in self.cursor.fetchall()]
67
+
68
+ def inspect_table(self, table_name: str) -> TableReport:
69
+ # Row count
70
+ self.cursor.execute(f'SELECT COUNT(*) FROM "{table_name}"')
71
+ row_count = self.cursor.fetchone()[0]
72
+ report = TableReport(name=table_name, row_count=row_count)
73
+
74
+ # Column metadata
75
+ self.cursor.execute(f'PRAGMA table_info("{table_name}")')
76
+ for col in self.cursor.fetchall():
77
+ report.columns.append(
78
+ ColumnMeta(
79
+ cid=col[0],
80
+ name=col[1],
81
+ data_type=col[2] or "ANY",
82
+ not_null=bool(col[3]),
83
+ default_value=col[4],
84
+ is_pk=bool(col[5]),
85
+ )
86
+ )
87
+
88
+ # Foreign Key mappings + Orphan Record Audit
89
+ self.cursor.execute(f'PRAGMA foreign_key_list("{table_name}")')
90
+ for fk in self.cursor.fetchall():
91
+ target_t, from_c, to_c = fk[2], fk[3], fk[4]
92
+ report.foreign_keys.append(
93
+ ForeignKeyMeta(target_table=target_t, from_col=from_c, to_col=to_c)
94
+ )
95
+
96
+ audit_query = f"""
97
+ SELECT COUNT(*) FROM "{table_name}"
98
+ WHERE "{from_c}" IS NOT NULL
99
+ AND "{from_c}" NOT IN (SELECT "{to_c}" FROM "{target_t}")
100
+ """
101
+ try:
102
+ self.cursor.execute(audit_query)
103
+ orphans = self.cursor.fetchone()[0]
104
+ if orphans > 0:
105
+ report.orphaned_records[from_c] = orphans
106
+ report.warnings.append(
107
+ f"Integrity Alert: {orphans} orphaned row(s) in '{from_c}' reference missing records in '{target_t}.{to_c}'."
108
+ )
109
+ except sqlite3.OperationalError:
110
+ report.warnings.append(f"Broken Reference: Target table '{target_t}' is inaccessible.")
111
+
112
+ if not report.primary_keys:
113
+ report.warnings.append("Design Notice: No primary key defined.")
114
+ if report.row_count == 0:
115
+ report.warnings.append("Design Notice: Table contains 0 records.")
116
+
117
+ return report
118
+
119
+ def inspect(self) -> None:
120
+ """Prints formatted plain-English narrative report."""
121
+ tables = self._get_tables()
122
+ size_kb = os.path.getsize(self.db_path) / 1024
123
+
124
+ print("\n" + "=" * 60)
125
+ print(f"SCHEMATELL DATABASE REPORT: {self.db_path.name} ({size_kb:.1f} KB)")
126
+ print(f"Identified {len(tables)} active table(s)")
127
+ print("=" * 60)
128
+
129
+ for table in tables:
130
+ rep = self.inspect_table(table)
131
+ print(f"\nšŸ“¦ Table: '{rep.name}' (Records: {rep.row_count:,})")
132
+
133
+ pk_desc = ", ".join(rep.primary_keys) if rep.primary_keys else "None"
134
+ print(f" • Primary Key: {pk_desc}")
135
+
136
+ col_list = [f"{c.name} ({c.data_type})" for c in rep.columns]
137
+ print(f" • Attributes: {', '.join(col_list)}")
138
+
139
+ for fk in rep.foreign_keys:
140
+ print(f" • Relationship: Points to '{fk.target_table}' via `{fk.from_col}` → `{fk.to_col}`")
141
+
142
+ for w in rep.warnings:
143
+ print(f" āš ļø {w}")
144
+
145
+ print("\n" + "=" * 60 + "\n")
146
+
147
+ def export_mermaid(self, output_file: str = "schema.md") -> None:
148
+ """Exports GitHub-ready Mermaid ER diagram."""
149
+ lines = ["```mermaid", "erDiagram"]
150
+ tables = self._get_tables()
151
+
152
+ for t in tables:
153
+ rep = self.inspect_table(t)
154
+ lines.append(f" {rep.name} {{")
155
+ for col in rep.columns:
156
+ pk_tag = "PK" if col.is_pk else ""
157
+ lines.append(f" {col.data_type} {col.name} {pk_tag}".strip())
158
+ lines.append(" }")
159
+
160
+ for t in tables:
161
+ rep = self.inspect_table(t)
162
+ for fk in rep.foreign_keys:
163
+ lines.append(f' {fk.target_table} ||--o{{ {rep.name} : "{fk.from_col}"')
164
+
165
+ lines.append("```\n")
166
+
167
+ with open(output_file, "w", encoding="utf-8") as f:
168
+ f.write("\n".join(lines))
169
+ print(f"Mermaid ER diagram saved to {output_file}")
170
+
171
+ def close(self):
172
+ self.conn.close()
173
+
174
+ def __enter__(self):
175
+ return self
176
+
177
+ def __exit__(self, exc_type, exc_val, exc_tb):
178
+ self.close()
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+