Skip to content

Commit 6b47458

Browse files
committed
Added notebook and binder
1 parent 2ac79e3 commit 6b47458

File tree

3 files changed

+59
-59
lines changed

3 files changed

+59
-59
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Python version](https://img.shields.io/pypi/pyversions/crdb-sql-audit)](https://pypi.org/project/crdb-sql-audit/)
33
[![License](https://img.shields.io/pypi/l/crdb-sql-audit)](https://pypi.org/project/crdb-sql-audit/)
44
[![Build status](https://github.com/viragtripathi/crdb-sql-audit/actions/workflows/python-ci.yml/badge.svg)](https://github.com/viragtripathi/crdb-sql-audit/actions)
5-
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/viragtripathi/crdb-sql-audit/HEAD?filepath=notebooks%2Fdemo_crdb_sql_audit.ipynb)
5+
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/viragtripathi/crdb-sql-audit/HEAD?filepath=notebooks%2Fdemo_crdb_sql_audit_binder.ipynb)
66

77
# crdb-sql-audit
88

@@ -223,4 +223,4 @@ python tests/test_runner.py
223223

224224
---
225225

226-
📓 [Try it in a Jupyter notebook](notebooks/demo_crdb_sql_audit.ipynb)
226+
📓 [Try it in a Jupyter notebook](notebooks/demo_crdb_sql_audit_binder.ipynb)

notebooks/demo_crdb_sql_audit.ipynb

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": "# \ud83e\uddea crdb-sql-audit Demo Notebook (Binder Friendly)\n\nThis notebook demonstrates how to use `crdb-sql-audit` interactively using remote resources."
7+
},
8+
{
9+
"cell_type": "code",
10+
"metadata": {},
11+
"execution_count": null,
12+
"outputs": [],
13+
"source": "# Install crdb-sql-audit (if not already installed)\n!pip install crdb-sql-audit"
14+
},
15+
{
16+
"cell_type": "code",
17+
"metadata": {},
18+
"execution_count": null,
19+
"outputs": [],
20+
"source": "# Step 1: Load rules from GitHub\nimport yaml\nimport requests\n\nurl = \"https://raw.githubusercontent.com/viragtripathi/crdb-sql-audit/main/tests/rules/test_rules.yaml\"\nyaml_text = requests.get(url).text\nrules = yaml.safe_load(yaml_text)\n\nprint(f\"\u2705 Loaded {len(rules)} rules\")"
21+
},
22+
{
23+
"cell_type": "code",
24+
"metadata": {},
25+
"execution_count": null,
26+
"outputs": [],
27+
"source": "# Step 2: Load SQL log lines from GitHub\nsql_url = \"https://raw.githubusercontent.com/viragtripathi/crdb-sql-audit/main/tests/sample_logs/basic_pg_chunk.log\"\nlog_text = requests.get(sql_url).text\nraw_lines = [line.strip() for line in log_text.splitlines() if line.strip()]\n\nprint(f\"\u2705 Loaded {len(raw_lines)} SQL lines\")"
28+
},
29+
{
30+
"cell_type": "code",
31+
"metadata": {},
32+
"execution_count": null,
33+
"outputs": [],
34+
"source": "# Step 3: Apply rules\nfrom crdb_sql_audit.rules_engine import apply_rules\n\nall_matches = []\nfor line in raw_lines:\n matches = apply_rules(line, rules)\n all_matches.extend(matches)\n\nprint(f\"\ud83d\udea8 Total matches: {len(all_matches)}\")"
35+
},
36+
{
37+
"cell_type": "code",
38+
"metadata": {},
39+
"execution_count": null,
40+
"outputs": [],
41+
"source": "# Step 4: Display matches\nimport pandas as pd\n\nif all_matches:\n df = pd.DataFrame(all_matches)\n df[['Rule_ID', 'SQL_Type', 'Issue', 'Example']].head(10)\nelse:\n print(\"No matches found.\")"
42+
}
43+
],
44+
"metadata": {
45+
"kernelspec": {
46+
"display_name": "Python 3",
47+
"language": "python",
48+
"name": "python3"
49+
},
50+
"language_info": {
51+
"name": "python",
52+
"version": "3.x"
53+
}
54+
},
55+
"nbformat": 4,
56+
"nbformat_minor": 5
57+
}

0 commit comments

Comments
 (0)