sqlnbfmt 0.1.0__tar.gz → 0.1.2__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,157 @@
1
+ Metadata-Version: 2.1
2
+ Name: sqlnbfmt
3
+ Version: 0.1.2
4
+ Summary: A tool to format SQL code in Jupyter notebooks.
5
+ Author-email: Qing <qingye779@gmail.com>
6
+ License: MIT
7
+ Requires-Python: >=3.12
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: astor>=0.8.1
11
+ Requires-Dist: nbformat>=5.10.4
12
+ Requires-Dist: pyyaml>=6.0.2
13
+ Requires-Dist: sqlglot>=25.27.0
14
+
15
+ # sqlnbfmt
16
+
17
+ [![PyPI](https://img.shields.io/pypi/v/sqlnbfmt.svg)](https://pypi.org/project/sqlnbfmt/)
18
+ [![License](https://img.shields.io/pypi/l/sqlnbfmt.svg)](https://github.com/flyersworder/sqlnbfmt/blob/main/LICENSE)
19
+ [![Python Versions](https://img.shields.io/pypi/pyversions/sqlnbfmt.svg)](https://pypi.org/project/sqlnbfmt/)
20
+
21
+ 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.
22
+
23
+ ## Features
24
+
25
+ - 🎯 **Smart SQL Detection**: Automatically identifies and formats SQL queries in code cells and magic SQL cells
26
+ - 🌳 **AST-Powered**: Uses Abstract Syntax Tree parsing for accurate SQL string identification
27
+ - 🔒 **Safe Formatting**: Preserves query parameters (e.g., `%s`, `?`) and SQL comments
28
+ - ⚙️ **Highly Configurable**: Customize formatting through YAML configuration
29
+ - 🔄 **Pre-commit Ready**: Seamlessly integrates with pre-commit hooks
30
+ - 📦 **Zero Dependencies**: Minimal installation footprint
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install sqlnbfmt
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ### Command Line
41
+
42
+ Format a single notebook:
43
+ ```bash
44
+ sqlnbfmt path/to/your_notebook.ipynb
45
+ ```
46
+
47
+ Format all notebooks in a directory:
48
+ ```bash
49
+ sqlnbfmt path/to/notebooks/
50
+ ```
51
+
52
+ ### Pre-commit Integration
53
+
54
+ 1. Install pre-commit:
55
+ ```bash
56
+ pip install pre-commit
57
+ ```
58
+
59
+ 2. Add to `.pre-commit-config.yaml`:
60
+ ```yaml
61
+ repos:
62
+ - repo: local
63
+ hooks:
64
+ - id: sqlnbfmt
65
+ name: sqlnbfmt
66
+ entry: sqlnbfmt
67
+ language: system
68
+ types: [jupyter]
69
+ args: [--config, config.yaml, --dialect, mysql]
70
+ ```
71
+ Please fun the following command in your CMD for help:
72
+
73
+ ```bash
74
+ sqlnbfmt -h
75
+ ```
76
+
77
+ 3. Install the hook:
78
+ ```bash
79
+ pre-commit install
80
+ ```
81
+
82
+ 4. (Optional) Run on all files:
83
+ ```bash
84
+ pre-commit run --all-files
85
+ ```
86
+
87
+ ## Configuration
88
+
89
+ Create a `config.yaml` file to customize formatting behavior. [Here](https://github.com/flyersworder/sqlnbfmt/blob/main/config.yaml) is a template.
90
+
91
+ ### Configuration Options
92
+
93
+ | Option | Description | Default |
94
+ |--------|-------------|---------|
95
+ | `sql_keywords` | SQL keywords to recognize and format | Common SQL keywords |
96
+ | `function_names` | Python functions containing SQL code | `[]` |
97
+ | `sql_decorators` | Decorators indicating SQL code | `[]` |
98
+ | `single_line_threshold` | Maximum length before splitting SQL | 80 |
99
+ | `indent_width` | Number of spaces for indentation | 4 |
100
+
101
+ ## Example
102
+
103
+ Before formatting:
104
+ ```python
105
+ execute_sql("""SELECT a.col1, b.col2 FROM table_a a JOIN table_b b ON a.id = b.a_id WHERE a.status = 'active' ORDER BY a.created_at DESC""")
106
+ ```
107
+
108
+ After formatting:
109
+ ```python
110
+ execute_sql("""
111
+ SELECT
112
+ a.col1,
113
+ b.col2
114
+ FROM
115
+ table_a AS a
116
+ JOIN
117
+ table_b AS b
118
+ ON a.id = b.a_id
119
+ WHERE
120
+ a.status = 'active'
121
+ ORDER BY
122
+ a.created_at DESC
123
+ """)
124
+ ```
125
+
126
+ ## Contributing
127
+
128
+ We welcome contributions! Here's how to get started:
129
+
130
+ 1. Clone the repository:
131
+ ```bash
132
+ git clone https://github.com/flyersworder/sqlnbfmt.git
133
+ cd sqlnbfmt
134
+ ```
135
+
136
+ 2. Use `uv` to sync the environment:
137
+ ```bash
138
+ uv sync
139
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
140
+ ```
141
+
142
+ 3. Run tests:
143
+ ```bash
144
+ pytest
145
+ ```
146
+
147
+ ## License
148
+
149
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
150
+
151
+ ## Acknowledgments
152
+
153
+ - [sqlglot](https://github.com/tobymao/sqlglot) - SQL parsing and formatting engine
154
+ - All contributors and early adopters who helped shape this tool
155
+
156
+ ---
157
+ Made with ♥️ by the sqlnbfmt team
@@ -0,0 +1,143 @@
1
+ # sqlnbfmt
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/sqlnbfmt.svg)](https://pypi.org/project/sqlnbfmt/)
4
+ [![License](https://img.shields.io/pypi/l/sqlnbfmt.svg)](https://github.com/flyersworder/sqlnbfmt/blob/main/LICENSE)
5
+ [![Python Versions](https://img.shields.io/pypi/pyversions/sqlnbfmt.svg)](https://pypi.org/project/sqlnbfmt/)
6
+
7
+ 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.
8
+
9
+ ## Features
10
+
11
+ - 🎯 **Smart SQL Detection**: Automatically identifies and formats SQL queries in code cells and magic SQL cells
12
+ - 🌳 **AST-Powered**: Uses Abstract Syntax Tree parsing for accurate SQL string identification
13
+ - 🔒 **Safe Formatting**: Preserves query parameters (e.g., `%s`, `?`) and SQL comments
14
+ - ⚙️ **Highly Configurable**: Customize formatting through YAML configuration
15
+ - 🔄 **Pre-commit Ready**: Seamlessly integrates with pre-commit hooks
16
+ - 📦 **Zero Dependencies**: Minimal installation footprint
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install sqlnbfmt
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Command Line
27
+
28
+ Format a single notebook:
29
+ ```bash
30
+ sqlnbfmt path/to/your_notebook.ipynb
31
+ ```
32
+
33
+ Format all notebooks in a directory:
34
+ ```bash
35
+ sqlnbfmt path/to/notebooks/
36
+ ```
37
+
38
+ ### Pre-commit Integration
39
+
40
+ 1. Install pre-commit:
41
+ ```bash
42
+ pip install pre-commit
43
+ ```
44
+
45
+ 2. Add to `.pre-commit-config.yaml`:
46
+ ```yaml
47
+ repos:
48
+ - repo: local
49
+ hooks:
50
+ - id: sqlnbfmt
51
+ name: sqlnbfmt
52
+ entry: sqlnbfmt
53
+ language: system
54
+ types: [jupyter]
55
+ args: [--config, config.yaml, --dialect, mysql]
56
+ ```
57
+ Please fun the following command in your CMD for help:
58
+
59
+ ```bash
60
+ sqlnbfmt -h
61
+ ```
62
+
63
+ 3. Install the hook:
64
+ ```bash
65
+ pre-commit install
66
+ ```
67
+
68
+ 4. (Optional) Run on all files:
69
+ ```bash
70
+ pre-commit run --all-files
71
+ ```
72
+
73
+ ## Configuration
74
+
75
+ Create a `config.yaml` file to customize formatting behavior. [Here](https://github.com/flyersworder/sqlnbfmt/blob/main/config.yaml) is a template.
76
+
77
+ ### Configuration Options
78
+
79
+ | Option | Description | Default |
80
+ |--------|-------------|---------|
81
+ | `sql_keywords` | SQL keywords to recognize and format | Common SQL keywords |
82
+ | `function_names` | Python functions containing SQL code | `[]` |
83
+ | `sql_decorators` | Decorators indicating SQL code | `[]` |
84
+ | `single_line_threshold` | Maximum length before splitting SQL | 80 |
85
+ | `indent_width` | Number of spaces for indentation | 4 |
86
+
87
+ ## Example
88
+
89
+ Before formatting:
90
+ ```python
91
+ execute_sql("""SELECT a.col1, b.col2 FROM table_a a JOIN table_b b ON a.id = b.a_id WHERE a.status = 'active' ORDER BY a.created_at DESC""")
92
+ ```
93
+
94
+ After formatting:
95
+ ```python
96
+ execute_sql("""
97
+ SELECT
98
+ a.col1,
99
+ b.col2
100
+ FROM
101
+ table_a AS a
102
+ JOIN
103
+ table_b AS b
104
+ ON a.id = b.a_id
105
+ WHERE
106
+ a.status = 'active'
107
+ ORDER BY
108
+ a.created_at DESC
109
+ """)
110
+ ```
111
+
112
+ ## Contributing
113
+
114
+ We welcome contributions! Here's how to get started:
115
+
116
+ 1. Clone the repository:
117
+ ```bash
118
+ git clone https://github.com/flyersworder/sqlnbfmt.git
119
+ cd sqlnbfmt
120
+ ```
121
+
122
+ 2. Use `uv` to sync the environment:
123
+ ```bash
124
+ uv sync
125
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
126
+ ```
127
+
128
+ 3. Run tests:
129
+ ```bash
130
+ pytest
131
+ ```
132
+
133
+ ## License
134
+
135
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
136
+
137
+ ## Acknowledgments
138
+
139
+ - [sqlglot](https://github.com/tobymao/sqlglot) - SQL parsing and formatting engine
140
+ - All contributors and early adopters who helped shape this tool
141
+
142
+ ---
143
+ Made with ♥️ by the sqlnbfmt team
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sqlnbfmt"
3
- version = "0.1.0"
3
+ version = "0.1.2"
4
4
  description = "A tool to format SQL code in Jupyter notebooks."
5
5
  authors = [
6
6
  { name = "Qing", email = "qingye779@gmail.com" }