sqlnbfmt 0.3.2__tar.gz → 0.4.1__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.
@@ -1,17 +1,24 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlnbfmt
3
- Version: 0.3.2
4
- Summary: A tool to format SQL code in Jupyter notebooks.
3
+ Version: 0.4.1
4
+ Summary: A tool to format SQL code in Jupyter notebooks and Marimo notebooks.
5
5
  Author-email: Qing <qingye779@gmail.com>
6
6
  License: MIT
7
7
  Project-URL: Homepage, https://github.com/flyersworder/sqlnbfmt
8
8
  Project-URL: Repository, https://github.com/flyersworder/sqlnbfmt
9
9
  Project-URL: Changelog, https://github.com/flyersworder/sqlnbfmt/blob/main/CHANGELOG.md
10
10
  Project-URL: Issues, https://github.com/flyersworder/sqlnbfmt/issues
11
- Keywords: sql,jupyter,notebook,formatter,sqlglot,pre-commit
11
+ Keywords: sql,jupyter,marimo,notebook,formatter,sqlglot,pre-commit
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
12
16
  Classifier: Programming Language :: Python :: 3
13
17
  Classifier: Programming Language :: Python :: 3.12
14
18
  Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Quality Assurance
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Framework :: Jupyter
15
22
  Requires-Python: >=3.12
16
23
  Description-Content-Type: text/markdown
17
24
  License-File: LICENSE
@@ -23,22 +30,25 @@ Dynamic: license-file
23
30
  # sqlnbfmt
24
31
 
25
32
  [![PyPI](https://img.shields.io/pypi/v/sqlnbfmt.svg)](https://pypi.org/project/sqlnbfmt/)
33
+ [![Tests](https://github.com/flyersworder/sqlnbfmt/actions/workflows/ci-and-publish.yml/badge.svg)](https://github.com/flyersworder/sqlnbfmt/actions/workflows/ci-and-publish.yml)
26
34
  [![License](https://img.shields.io/pypi/l/sqlnbfmt.svg)](https://github.com/flyersworder/sqlnbfmt/blob/main/LICENSE)
27
35
  [![Python Versions](https://img.shields.io/pypi/pyversions/sqlnbfmt.svg)](https://pypi.org/project/sqlnbfmt/)
28
36
 
29
37
  > **Quick start:** `pip install sqlnbfmt && sqlnbfmt notebook.ipynb`
30
38
 
31
- A SQL formatter designed specifically for Jupyter Notebooks. `sqlnbfmt` automatically formats SQL queries embedded in code cells, including both Python strings and SQL magic cells (`%%sql`), helping you maintain clean and consistent code.
39
+ A SQL formatter for Jupyter Notebooks and Marimo notebooks. `sqlnbfmt` automatically formats SQL queries embedded in notebook cells — Python strings, SQL magic cells (`%%sql`), and Marimo `mo.sql()` calls — helping you maintain clean and consistent code.
32
40
 
33
41
  ## Features
34
42
 
35
43
  - **Zero-config**: Works out of the box with sensible defaults — no config file needed
36
- - **Smart SQL Detection**: Automatically identifies and formats SQL queries in code cells and magic SQL cells
44
+ - **Jupyter + Marimo**: Formats SQL in `.ipynb` notebooks and Marimo `.py` notebooks
45
+ - **Smart SQL Detection**: Automatically identifies and formats SQL queries in code cells, magic SQL cells, and `mo.sql()` calls
37
46
  - **AST-Powered**: Uses Abstract Syntax Tree parsing for accurate SQL string identification
38
- - **Safe Formatting**: Preserves Python comments, query parameters (e.g., `%s`, `?`), and SQL comments
47
+ - **Safe Formatting**: Preserves Python comments, query parameters (e.g., `%s`, `?`), f-string placeholders, and SQL comments
39
48
  - **CI-Friendly**: `--check` mode exits non-zero when formatting is needed; `--diff` shows what would change
40
49
  - **Skip Hints**: Add `# sqlnbfmt: skip` to any cell to exclude it from formatting
41
50
  - **Pre-commit Ready**: Seamlessly integrates with pre-commit hooks
51
+ - **JupyterLab Plugin**: Works with `jupyterlab-code-formatter` for interactive format-on-save
42
52
  - **Lightweight**: Only three runtime dependencies (sqlglot, nbformat, pyyaml)
43
53
 
44
54
  ## Installation
@@ -51,14 +61,24 @@ pip install sqlnbfmt
51
61
 
52
62
  ### Command Line
53
63
 
54
- Format a single notebook:
64
+ Format Jupyter notebooks:
55
65
  ```bash
56
66
  sqlnbfmt path/to/your_notebook.ipynb
57
67
  ```
58
68
 
69
+ Format Marimo notebooks (or any Python file with SQL strings):
70
+ ```bash
71
+ sqlnbfmt path/to/your_notebook.py
72
+ ```
73
+
74
+ Mix both in a single invocation:
75
+ ```bash
76
+ sqlnbfmt *.ipynb marimo_app.py
77
+ ```
78
+
59
79
  Check formatting without modifying files (useful in CI):
60
80
  ```bash
61
- sqlnbfmt --check path/to/your_notebook.ipynb
81
+ sqlnbfmt --check path/to/your_notebook.ipynb path/to/marimo_app.py
62
82
  ```
63
83
 
64
84
  Show a diff of what would change:
@@ -68,13 +88,30 @@ sqlnbfmt --diff path/to/your_notebook.ipynb
68
88
 
69
89
  ### Skipping Cells
70
90
 
71
- Add a `# sqlnbfmt: skip` comment anywhere in a cell to skip formatting:
91
+ Add a `# sqlnbfmt: skip` comment to skip formatting. In Jupyter notebooks this applies per-cell; in Python files it applies to the entire file.
72
92
 
73
93
  ```python
74
94
  # sqlnbfmt: skip
75
95
  query = "select * from my_special_table where id = 1"
76
96
  ```
77
97
 
98
+ ### JupyterLab Integration
99
+
100
+ Format SQL cells interactively with [jupyterlab-code-formatter](https://github.com/jupyterlab-contrib/jupyterlab_code_formatter):
101
+
102
+ 1. Install both packages:
103
+ ```bash
104
+ pip install sqlnbfmt jupyterlab-code-formatter
105
+ ```
106
+
107
+ 2. Register the formatter in `~/.jupyter/jupyter_notebook_config.py`:
108
+ ```python
109
+ from sqlnbfmt.jupyterlab_integration import register
110
+ register() # or: register(dialect="postgres")
111
+ ```
112
+
113
+ 3. In JupyterLab, use **Edit > Format Cell** or configure format-on-save in Settings > Code Formatter.
114
+
78
115
  ### Pre-commit Integration
79
116
 
80
117
  1. Install pre-commit:
@@ -86,12 +123,18 @@ pip install pre-commit
86
123
  ```yaml
87
124
  repos:
88
125
  - repo: https://github.com/flyersworder/sqlnbfmt
89
- rev: v0.3.0
126
+ rev: v0.4.0
90
127
  hooks:
91
128
  - id: sqlnbfmt
92
129
  types: [jupyter]
93
130
  ```
94
131
 
132
+ To also format Marimo notebooks (Python files), add the Python hook:
133
+ ```yaml
134
+ - id: sqlnbfmt-py
135
+ files: '\.py$' # optionally narrow with: files: 'marimo_.*\.py$'
136
+ ```
137
+
95
138
  All arguments are optional. To specify a dialect or custom config:
96
139
  ```yaml
97
140
  args: [--dialect, postgres, --config, config.yaml]
@@ -116,6 +159,7 @@ Use `--check` in GitHub Actions to enforce formatting:
116
159
  run: |
117
160
  pip install sqlnbfmt
118
161
  sqlnbfmt --check **/*.ipynb
162
+ sqlnbfmt --check marimo_*.py # if using Marimo
119
163
  ```
120
164
 
121
165
  ## Configuration
@@ -134,7 +178,9 @@ Create a `config.yaml` file to customize formatting behavior. [Here](https://git
134
178
  | `single_line_threshold` | Maximum length before splitting SQL | 80 |
135
179
  | `indent_width` | Number of spaces for indentation | 4 |
136
180
 
137
- ## Example
181
+ ## Examples
182
+
183
+ ### Jupyter Notebook
138
184
 
139
185
  Before formatting:
140
186
  ```python
@@ -159,6 +205,35 @@ ORDER BY
159
205
  """)
160
206
  ```
161
207
 
208
+ ### Marimo Notebook
209
+
210
+ Before formatting:
211
+ ```python
212
+ @app.cell
213
+ def _(mo):
214
+ _df = mo.sql(f"select id, name from users where active = 1 order by name")
215
+ return
216
+ ```
217
+
218
+ After formatting:
219
+ ```python
220
+ @app.cell
221
+ def _(mo):
222
+ _df = mo.sql(
223
+ f"""
224
+ SELECT
225
+ id,
226
+ name
227
+ FROM users
228
+ WHERE
229
+ active = 1
230
+ ORDER BY
231
+ name
232
+ """
233
+ )
234
+ return
235
+ ```
236
+
162
237
  ## Troubleshooting
163
238
 
164
239
  **SQL not being formatted?**
@@ -1,44 +1,25 @@
1
- Metadata-Version: 2.4
2
- Name: sqlnbfmt
3
- Version: 0.3.2
4
- Summary: A tool to format SQL code in Jupyter notebooks.
5
- Author-email: Qing <qingye779@gmail.com>
6
- License: MIT
7
- Project-URL: Homepage, https://github.com/flyersworder/sqlnbfmt
8
- Project-URL: Repository, https://github.com/flyersworder/sqlnbfmt
9
- Project-URL: Changelog, https://github.com/flyersworder/sqlnbfmt/blob/main/CHANGELOG.md
10
- Project-URL: Issues, https://github.com/flyersworder/sqlnbfmt/issues
11
- Keywords: sql,jupyter,notebook,formatter,sqlglot,pre-commit
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: Programming Language :: Python :: 3.12
14
- Classifier: Programming Language :: Python :: 3.13
15
- Requires-Python: >=3.12
16
- Description-Content-Type: text/markdown
17
- License-File: LICENSE
18
- Requires-Dist: nbformat>=5.10.4
19
- Requires-Dist: pyyaml>=6.0.2
20
- Requires-Dist: sqlglot>=25.27.0
21
- Dynamic: license-file
22
-
23
1
  # sqlnbfmt
24
2
 
25
3
  [![PyPI](https://img.shields.io/pypi/v/sqlnbfmt.svg)](https://pypi.org/project/sqlnbfmt/)
4
+ [![Tests](https://github.com/flyersworder/sqlnbfmt/actions/workflows/ci-and-publish.yml/badge.svg)](https://github.com/flyersworder/sqlnbfmt/actions/workflows/ci-and-publish.yml)
26
5
  [![License](https://img.shields.io/pypi/l/sqlnbfmt.svg)](https://github.com/flyersworder/sqlnbfmt/blob/main/LICENSE)
27
6
  [![Python Versions](https://img.shields.io/pypi/pyversions/sqlnbfmt.svg)](https://pypi.org/project/sqlnbfmt/)
28
7
 
29
8
  > **Quick start:** `pip install sqlnbfmt && sqlnbfmt notebook.ipynb`
30
9
 
31
- A SQL formatter designed specifically for Jupyter Notebooks. `sqlnbfmt` automatically formats SQL queries embedded in code cells, including both Python strings and SQL magic cells (`%%sql`), helping you maintain clean and consistent code.
10
+ A SQL formatter for Jupyter Notebooks and Marimo notebooks. `sqlnbfmt` automatically formats SQL queries embedded in notebook cells — Python strings, SQL magic cells (`%%sql`), and Marimo `mo.sql()` calls — helping you maintain clean and consistent code.
32
11
 
33
12
  ## Features
34
13
 
35
14
  - **Zero-config**: Works out of the box with sensible defaults — no config file needed
36
- - **Smart SQL Detection**: Automatically identifies and formats SQL queries in code cells and magic SQL cells
15
+ - **Jupyter + Marimo**: Formats SQL in `.ipynb` notebooks and Marimo `.py` notebooks
16
+ - **Smart SQL Detection**: Automatically identifies and formats SQL queries in code cells, magic SQL cells, and `mo.sql()` calls
37
17
  - **AST-Powered**: Uses Abstract Syntax Tree parsing for accurate SQL string identification
38
- - **Safe Formatting**: Preserves Python comments, query parameters (e.g., `%s`, `?`), and SQL comments
18
+ - **Safe Formatting**: Preserves Python comments, query parameters (e.g., `%s`, `?`), f-string placeholders, and SQL comments
39
19
  - **CI-Friendly**: `--check` mode exits non-zero when formatting is needed; `--diff` shows what would change
40
20
  - **Skip Hints**: Add `# sqlnbfmt: skip` to any cell to exclude it from formatting
41
21
  - **Pre-commit Ready**: Seamlessly integrates with pre-commit hooks
22
+ - **JupyterLab Plugin**: Works with `jupyterlab-code-formatter` for interactive format-on-save
42
23
  - **Lightweight**: Only three runtime dependencies (sqlglot, nbformat, pyyaml)
43
24
 
44
25
  ## Installation
@@ -51,14 +32,24 @@ pip install sqlnbfmt
51
32
 
52
33
  ### Command Line
53
34
 
54
- Format a single notebook:
35
+ Format Jupyter notebooks:
55
36
  ```bash
56
37
  sqlnbfmt path/to/your_notebook.ipynb
57
38
  ```
58
39
 
40
+ Format Marimo notebooks (or any Python file with SQL strings):
41
+ ```bash
42
+ sqlnbfmt path/to/your_notebook.py
43
+ ```
44
+
45
+ Mix both in a single invocation:
46
+ ```bash
47
+ sqlnbfmt *.ipynb marimo_app.py
48
+ ```
49
+
59
50
  Check formatting without modifying files (useful in CI):
60
51
  ```bash
61
- sqlnbfmt --check path/to/your_notebook.ipynb
52
+ sqlnbfmt --check path/to/your_notebook.ipynb path/to/marimo_app.py
62
53
  ```
63
54
 
64
55
  Show a diff of what would change:
@@ -68,13 +59,30 @@ sqlnbfmt --diff path/to/your_notebook.ipynb
68
59
 
69
60
  ### Skipping Cells
70
61
 
71
- Add a `# sqlnbfmt: skip` comment anywhere in a cell to skip formatting:
62
+ Add a `# sqlnbfmt: skip` comment to skip formatting. In Jupyter notebooks this applies per-cell; in Python files it applies to the entire file.
72
63
 
73
64
  ```python
74
65
  # sqlnbfmt: skip
75
66
  query = "select * from my_special_table where id = 1"
76
67
  ```
77
68
 
69
+ ### JupyterLab Integration
70
+
71
+ Format SQL cells interactively with [jupyterlab-code-formatter](https://github.com/jupyterlab-contrib/jupyterlab_code_formatter):
72
+
73
+ 1. Install both packages:
74
+ ```bash
75
+ pip install sqlnbfmt jupyterlab-code-formatter
76
+ ```
77
+
78
+ 2. Register the formatter in `~/.jupyter/jupyter_notebook_config.py`:
79
+ ```python
80
+ from sqlnbfmt.jupyterlab_integration import register
81
+ register() # or: register(dialect="postgres")
82
+ ```
83
+
84
+ 3. In JupyterLab, use **Edit > Format Cell** or configure format-on-save in Settings > Code Formatter.
85
+
78
86
  ### Pre-commit Integration
79
87
 
80
88
  1. Install pre-commit:
@@ -86,12 +94,18 @@ pip install pre-commit
86
94
  ```yaml
87
95
  repos:
88
96
  - repo: https://github.com/flyersworder/sqlnbfmt
89
- rev: v0.3.0
97
+ rev: v0.4.0
90
98
  hooks:
91
99
  - id: sqlnbfmt
92
100
  types: [jupyter]
93
101
  ```
94
102
 
103
+ To also format Marimo notebooks (Python files), add the Python hook:
104
+ ```yaml
105
+ - id: sqlnbfmt-py
106
+ files: '\.py$' # optionally narrow with: files: 'marimo_.*\.py$'
107
+ ```
108
+
95
109
  All arguments are optional. To specify a dialect or custom config:
96
110
  ```yaml
97
111
  args: [--dialect, postgres, --config, config.yaml]
@@ -116,6 +130,7 @@ Use `--check` in GitHub Actions to enforce formatting:
116
130
  run: |
117
131
  pip install sqlnbfmt
118
132
  sqlnbfmt --check **/*.ipynb
133
+ sqlnbfmt --check marimo_*.py # if using Marimo
119
134
  ```
120
135
 
121
136
  ## Configuration
@@ -134,7 +149,9 @@ Create a `config.yaml` file to customize formatting behavior. [Here](https://git
134
149
  | `single_line_threshold` | Maximum length before splitting SQL | 80 |
135
150
  | `indent_width` | Number of spaces for indentation | 4 |
136
151
 
137
- ## Example
152
+ ## Examples
153
+
154
+ ### Jupyter Notebook
138
155
 
139
156
  Before formatting:
140
157
  ```python
@@ -159,6 +176,35 @@ ORDER BY
159
176
  """)
160
177
  ```
161
178
 
179
+ ### Marimo Notebook
180
+
181
+ Before formatting:
182
+ ```python
183
+ @app.cell
184
+ def _(mo):
185
+ _df = mo.sql(f"select id, name from users where active = 1 order by name")
186
+ return
187
+ ```
188
+
189
+ After formatting:
190
+ ```python
191
+ @app.cell
192
+ def _(mo):
193
+ _df = mo.sql(
194
+ f"""
195
+ SELECT
196
+ id,
197
+ name
198
+ FROM users
199
+ WHERE
200
+ active = 1
201
+ ORDER BY
202
+ name
203
+ """
204
+ )
205
+ return
206
+ ```
207
+
162
208
  ## Troubleshooting
163
209
 
164
210
  **SQL not being formatted?**
@@ -1,18 +1,25 @@
1
1
  [project]
2
2
  name = "sqlnbfmt"
3
- version = "0.3.2"
4
- description = "A tool to format SQL code in Jupyter notebooks."
3
+ version = "0.4.1"
4
+ description = "A tool to format SQL code in Jupyter notebooks and Marimo notebooks."
5
5
  authors = [
6
6
  { name = "Qing", email = "qingye779@gmail.com" }
7
7
  ]
8
8
  license = { text = "MIT" }
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
11
- keywords = ["sql", "jupyter", "notebook", "formatter", "sqlglot", "pre-commit"]
11
+ keywords = ["sql", "jupyter", "marimo", "notebook", "formatter", "sqlglot", "pre-commit"]
12
12
  classifiers = [
13
+ "Development Status :: 4 - Beta",
14
+ "Intended Audience :: Developers",
15
+ "Intended Audience :: Science/Research",
16
+ "License :: OSI Approved :: MIT License",
13
17
  "Programming Language :: Python :: 3",
14
18
  "Programming Language :: Python :: 3.12",
15
- "Programming Language :: Python :: 3.13"
19
+ "Programming Language :: Python :: 3.13",
20
+ "Topic :: Software Development :: Quality Assurance",
21
+ "Topic :: Software Development :: Libraries :: Python Modules",
22
+ "Framework :: Jupyter",
16
23
  ]
17
24
  dependencies = [
18
25
  "nbformat>=5.10.4",