Skip to content

Commit beddaa1

Browse files
feat(phase5): add py.typed, [all] extra, and SQLite/LangChain example
1 parent c450195 commit beddaa1

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎examples/sqlite_guard_example.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
DBShield SQL Guardrail & Cursor Wrapper Example (SQLite + LangChain Wrapper)
3+
Run: python examples/sqlite_guard_example.py
4+
"""
5+
6+
import sqlite3
7+
8+
from dbshield.guard import DBShieldGuard, DBShieldSecurityViolation
9+
from dbshield.integrations.langchain import DBShieldSQLDatabase
10+
from dbshield.middleware import DBShieldCursorWrapper
11+
12+
13+
class _SqliteAdapter:
14+
def __init__(self, conn: sqlite3.Connection) -> None:
15+
self._conn = conn
16+
17+
def run(self, command: str) -> list:
18+
return self._conn.execute(command).fetchall()
19+
20+
21+
def main() -> None:
22+
conn = sqlite3.connect(":memory:")
23+
conn.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT)")
24+
conn.execute("INSERT INTO users (id, email) VALUES (1, 'alice@example.com')")
25+
26+
guard = DBShieldGuard(safety_tier="BALANCED")
27+
cursor = DBShieldCursorWrapper(conn.cursor(), guard)
28+
print("Allowed SELECT:", cursor.execute("SELECT id, email FROM users WHERE id = 1").fetchall())
29+
30+
wrapped_db = DBShieldSQLDatabase(_SqliteAdapter(conn), safety_tier="STRICT")
31+
try:
32+
wrapped_db.run("DROP TABLE users")
33+
except DBShieldSecurityViolation as err:
34+
print("Blocked dangerous DDL:", err)
35+
36+
37+
if __name__ == "__main__":
38+
main()

‎pyproject.toml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ classifiers = [
3535
"Programming Language :: Python :: 3.13",
3636
"Topic :: Security",
3737
"Topic :: Database",
38-
"Topic :: Scientific/Engineering :: Artificial Intelligence"
38+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
39+
"Typing :: Typed"
3940
]
4041
requires-python = ">=3.10"
4142
dependencies = []
@@ -58,6 +59,9 @@ llamaindex = [
5859
sqlalchemy = [
5960
"sqlalchemy>=2.0.57"
6061
]
62+
all = [
63+
"dbshield-defense[langchain,crewai,llamaindex,sqlalchemy]"
64+
]
6165

6266
[project.urls]
6367
Homepage = "https://ritualdev.in/dbshield"
@@ -68,3 +72,6 @@ Issues = "https://github.com/RitualDev-Lab/dbshield-python/issues"
6872

6973
[tool.setuptools.packages.find]
7074
where = ["src"]
75+
76+
[tool.setuptools.package-data]
77+
dbshield = ["py.typed"]

‎src/dbshield/py.typed‎

Whitespace-only changes.

0 commit comments

Comments
 (0)