From beddaa16de838146675eed027ab95324bfcf0e3b Mon Sep 17 00:00:00 2001 From: divyanshujethi Date: Wed, 25 Nov 2026 14:14:02 +0530 Subject: [PATCH] feat(phase5): add py.typed, [all] extra, and SQLite/LangChain example --- examples/sqlite_guard_example.py | 38 ++++++++++++++++++++++++++++++++ pyproject.toml | 9 +++++++- src/dbshield/py.typed | 0 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 examples/sqlite_guard_example.py create mode 100644 src/dbshield/py.typed diff --git a/examples/sqlite_guard_example.py b/examples/sqlite_guard_example.py new file mode 100644 index 0000000..d81baf0 --- /dev/null +++ b/examples/sqlite_guard_example.py @@ -0,0 +1,38 @@ +""" +DBShield SQL Guardrail & Cursor Wrapper Example (SQLite + LangChain Wrapper) +Run: python examples/sqlite_guard_example.py +""" + +import sqlite3 + +from dbshield.guard import DBShieldGuard, DBShieldSecurityViolation +from dbshield.integrations.langchain import DBShieldSQLDatabase +from dbshield.middleware import DBShieldCursorWrapper + + +class _SqliteAdapter: + def __init__(self, conn: sqlite3.Connection) -> None: + self._conn = conn + + def run(self, command: str) -> list: + return self._conn.execute(command).fetchall() + + +def main() -> None: + conn = sqlite3.connect(":memory:") + conn.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT)") + conn.execute("INSERT INTO users (id, email) VALUES (1, 'alice@example.com')") + + guard = DBShieldGuard(safety_tier="BALANCED") + cursor = DBShieldCursorWrapper(conn.cursor(), guard) + print("Allowed SELECT:", cursor.execute("SELECT id, email FROM users WHERE id = 1").fetchall()) + + wrapped_db = DBShieldSQLDatabase(_SqliteAdapter(conn), safety_tier="STRICT") + try: + wrapped_db.run("DROP TABLE users") + except DBShieldSecurityViolation as err: + print("Blocked dangerous DDL:", err) + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml index 3243f8b..c4ac3bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,8 @@ classifiers = [ "Programming Language :: Python :: 3.13", "Topic :: Security", "Topic :: Database", - "Topic :: Scientific/Engineering :: Artificial Intelligence" + "Topic :: Scientific/Engineering :: Artificial Intelligence", + "Typing :: Typed" ] requires-python = ">=3.10" dependencies = [] @@ -58,6 +59,9 @@ llamaindex = [ sqlalchemy = [ "sqlalchemy>=2.0.57" ] +all = [ + "dbshield-defense[langchain,crewai,llamaindex,sqlalchemy]" +] [project.urls] Homepage = "https://ritualdev.in/dbshield" @@ -68,3 +72,6 @@ Issues = "https://github.com/RitualDev-Lab/dbshield-python/issues" [tool.setuptools.packages.find] where = ["src"] + +[tool.setuptools.package-data] +dbshield = ["py.typed"] diff --git a/src/dbshield/py.typed b/src/dbshield/py.typed new file mode 100644 index 0000000..e69de29