sqlmesh-dag-generator 0.1.0__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.
- sqlmesh_dag_generator-0.1.0/LICENSE +22 -0
- sqlmesh_dag_generator-0.1.0/PKG-INFO +308 -0
- sqlmesh_dag_generator-0.1.0/README.md +261 -0
- sqlmesh_dag_generator-0.1.0/pyproject.toml +74 -0
- sqlmesh_dag_generator-0.1.0/setup.cfg +4 -0
- sqlmesh_dag_generator-0.1.0/setup.py +66 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator/__init__.py +14 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator/cli.py +202 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator/config.py +116 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator/dag_builder.py +449 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator/generator.py +421 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator/models.py +135 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator/utils.py +170 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator.egg-info/PKG-INFO +308 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator.egg-info/SOURCES.txt +21 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator.egg-info/dependency_links.txt +1 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator.egg-info/entry_points.txt +2 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator.egg-info/requires.txt +10 -0
- sqlmesh_dag_generator-0.1.0/sqlmesh_dag_generator.egg-info/top_level.txt +1 -0
- sqlmesh_dag_generator-0.1.0/tests/test_config.py +106 -0
- sqlmesh_dag_generator-0.1.0/tests/test_generator.py +371 -0
- sqlmesh_dag_generator-0.1.0/tests/test_models.py +113 -0
- sqlmesh_dag_generator-0.1.0/tests/test_utils.py +70 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 SQLMesh DAG Generator Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sqlmesh-dag-generator
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Open-source Airflow DAG generator for SQLMesh projects
|
|
5
|
+
Home-page: https://github.com/kubolko/sqlmesh-dag-generator
|
|
6
|
+
Author: Jakub Sumionka
|
|
7
|
+
Author-email: jakub.sumionka@gmail.com
|
|
8
|
+
Project-URL: Bug Reports, https://github.com/kubolko/sqlmesh-dag-generator/issues
|
|
9
|
+
Project-URL: Source, https://github.com/kubolko/sqlmesh-dag-generator
|
|
10
|
+
Project-URL: Documentation, https://github.com/kubolko/sqlmesh-dag-generator/docs
|
|
11
|
+
Keywords: sqlmesh airflow dag generator etl data-engineering
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: sqlmesh>=0.20.0
|
|
26
|
+
Requires-Dist: apache-airflow>=2.0.0
|
|
27
|
+
Requires-Dist: pyyaml>=5.4.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
33
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
34
|
+
Dynamic: author
|
|
35
|
+
Dynamic: author-email
|
|
36
|
+
Dynamic: classifier
|
|
37
|
+
Dynamic: description
|
|
38
|
+
Dynamic: description-content-type
|
|
39
|
+
Dynamic: home-page
|
|
40
|
+
Dynamic: keywords
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
Dynamic: project-url
|
|
43
|
+
Dynamic: provides-extra
|
|
44
|
+
Dynamic: requires-dist
|
|
45
|
+
Dynamic: requires-python
|
|
46
|
+
Dynamic: summary
|
|
47
|
+
|
|
48
|
+
# SQLMesh DAG Generator
|
|
49
|
+
|
|
50
|
+
Generate Apache Airflow DAGs from SQLMesh projects - **no cloud dependencies required**.
|
|
51
|
+
|
|
52
|
+
Transform your SQLMesh models into production-ready Airflow DAGs with **full data lineage**, automatically!
|
|
53
|
+
|
|
54
|
+
## ✨ Key Features
|
|
55
|
+
|
|
56
|
+
- 🔥 **Dynamic DAG Generation (Default)**: Fire-and-forget - place DAG once, auto-discovers models at runtime
|
|
57
|
+
- ✅ **Full Lineage in Airflow**: Each SQLMesh model = One Airflow task with proper dependencies
|
|
58
|
+
- 🌍 **Multi-Environment Support**: Use Airflow Variables for dev/staging/prod
|
|
59
|
+
- ⚡ **Incremental Models**: Proper handling with `data_interval_start/end`
|
|
60
|
+
- 🎯 **Enhanced Error Handling**: SQLMesh-specific error messages in Airflow logs
|
|
61
|
+
- 🛠️ **Dual Mode**: Dynamic (auto-discovery, default) or Static (full control)
|
|
62
|
+
- 🚫 **No Vendor Lock-in**: Open source, no cloud dependencies
|
|
63
|
+
|
|
64
|
+
## 🚀 Quick Start (3 Steps)
|
|
65
|
+
|
|
66
|
+
### 1. Install
|
|
67
|
+
```bash
|
|
68
|
+
pip install sqlmesh-dag-generator # (when published)
|
|
69
|
+
# OR
|
|
70
|
+
git clone <repo> && cd SQLMeshDAGGenerator && pip install -e .
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 2. Generate DAG (Dynamic Mode - Default!)
|
|
74
|
+
```python
|
|
75
|
+
from sqlmesh_dag_generator import SQLMeshDAGGenerator
|
|
76
|
+
|
|
77
|
+
# Point to your SQLMesh project
|
|
78
|
+
generator = SQLMeshDAGGenerator(
|
|
79
|
+
sqlmesh_project_path="/path/to/your/sqlmesh/project",
|
|
80
|
+
dag_id="my_pipeline",
|
|
81
|
+
schedule_interval="@daily"
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
# Generate dynamic DAG (default - fire and forget!)
|
|
85
|
+
dag_code = generator.generate_dynamic_dag()
|
|
86
|
+
|
|
87
|
+
# Save it
|
|
88
|
+
with open("my_pipeline.py", "w") as f:
|
|
89
|
+
f.write(dag_code)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 3. Deploy to Airflow
|
|
93
|
+
```bash
|
|
94
|
+
cp my_pipeline.py /opt/airflow/dags/
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**That's it! 🎉** Your SQLMesh models are now orchestrated by Airflow. The DAG will auto-discover models at runtime - no regeneration needed when models change!
|
|
98
|
+
|
|
99
|
+
## 💡 What You Get
|
|
100
|
+
|
|
101
|
+
### Your SQLMesh Project:
|
|
102
|
+
```
|
|
103
|
+
my_project/
|
|
104
|
+
└── models/
|
|
105
|
+
├── raw_orders.sql
|
|
106
|
+
├── stg_orders.sql # depends on raw_orders
|
|
107
|
+
└── orders_summary.sql # depends on stg_orders
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Generated Airflow DAG:
|
|
111
|
+
```
|
|
112
|
+
Airflow Graph View:
|
|
113
|
+
[raw_orders] → [stg_orders] → [orders_summary]
|
|
114
|
+
|
|
115
|
+
✅ Each model = separate task
|
|
116
|
+
✅ SQLMesh dependencies = Airflow dependencies
|
|
117
|
+
✅ Full lineage visible in Airflow UI
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## 📚 Documentation
|
|
121
|
+
|
|
122
|
+
- **[Quick Start Guide](docs/QUICKSTART.md)** - Step-by-step tutorial (start here!)
|
|
123
|
+
- **[Usage Guide](docs/USAGE.md)** - Complete reference
|
|
124
|
+
- **[Dynamic DAGs](docs/DYNAMIC_DAGS.md)** - Fire-and-forget mode explained
|
|
125
|
+
- **[Examples](examples/)** - Code examples
|
|
126
|
+
- **[Architecture](docs/ARCHITECTURE.md)** - Technical details
|
|
127
|
+
|
|
128
|
+
## 🔥 Why Dynamic Mode (Default)?
|
|
129
|
+
|
|
130
|
+
**Dynamic mode** auto-discovers SQLMesh models at runtime:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
dag_code = generator.generate_dynamic_dag() # Default behavior!
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Benefits:**
|
|
137
|
+
- ✅ **No regeneration needed** when SQLMesh models change
|
|
138
|
+
- ✅ **Always in sync** - DAG updates automatically
|
|
139
|
+
- ✅ **Multi-environment** - Uses Airflow Variables
|
|
140
|
+
- ✅ **Production-ready** - Enhanced error handling
|
|
141
|
+
|
|
142
|
+
Want static mode instead? Just use `generator.generate_dag()` - see [Usage Guide](docs/USAGE.md).
|
|
143
|
+
|
|
144
|
+
## 🎯 Simple Example
|
|
145
|
+
|
|
146
|
+
The simplest possible usage - just 3 lines of code:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from sqlmesh_dag_generator import SQLMeshDAGGenerator
|
|
150
|
+
|
|
151
|
+
generator = SQLMeshDAGGenerator(
|
|
152
|
+
sqlmesh_project_path="/path/to/your/sqlmesh/project",
|
|
153
|
+
dag_id="my_pipeline"
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
dag_code = generator.generate_dynamic_dag()
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
See [examples/simple_generate.py](examples/simple_generate.py) for a complete runnable example.
|
|
160
|
+
|
|
161
|
+
## 🤝 Contributing
|
|
162
|
+
|
|
163
|
+
Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
164
|
+
|
|
165
|
+
## 📄 License
|
|
166
|
+
|
|
167
|
+
[Your License Here]
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
**Built with ❤️ for the data engineering community**
|
|
172
|
+
|
|
173
|
+
### Configuration File
|
|
174
|
+
|
|
175
|
+
Create a `dag_generator_config.yaml`:
|
|
176
|
+
|
|
177
|
+
```yaml
|
|
178
|
+
sqlmesh:
|
|
179
|
+
project_path: "/path/to/sqlmesh/project"
|
|
180
|
+
environment: "prod"
|
|
181
|
+
gateway: "local"
|
|
182
|
+
|
|
183
|
+
airflow:
|
|
184
|
+
dag_id: "sqlmesh_pipeline"
|
|
185
|
+
schedule_interval: "0 0 * * *"
|
|
186
|
+
default_args:
|
|
187
|
+
owner: "data-team"
|
|
188
|
+
retries: 3
|
|
189
|
+
retry_delay_minutes: 5
|
|
190
|
+
tags:
|
|
191
|
+
- sqlmesh
|
|
192
|
+
- analytics
|
|
193
|
+
|
|
194
|
+
generation:
|
|
195
|
+
output_dir: "/path/to/airflow/dags"
|
|
196
|
+
operator_type: "python" # or "bash"
|
|
197
|
+
include_tests: true
|
|
198
|
+
parallel_tasks: true
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## How It Works
|
|
202
|
+
|
|
203
|
+
1. **Load SQLMesh Project**: Reads your SQLMesh project configuration and models
|
|
204
|
+
2. **Extract Dependencies**: Analyzes SQL queries to build dependency graph
|
|
205
|
+
3. **Generate Tasks**: Creates Airflow tasks for each SQLMesh model
|
|
206
|
+
4. **Set Dependencies**: Connects tasks based on model dependencies
|
|
207
|
+
5. **Apply Schedules**: Preserves cron schedules and execution logic
|
|
208
|
+
6. **Output DAG**: Generates Python file ready for Airflow
|
|
209
|
+
|
|
210
|
+
## Architecture
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
SQLMesh Project
|
|
214
|
+
↓
|
|
215
|
+
SQLMeshDAGGenerator
|
|
216
|
+
├── Context Loader (loads SQLMesh context)
|
|
217
|
+
├── Model Parser (extracts model metadata)
|
|
218
|
+
├── Dependency Resolver (builds dependency graph)
|
|
219
|
+
└── DAG Builder (generates Airflow DAG)
|
|
220
|
+
↓
|
|
221
|
+
Airflow DAG File
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Advanced Features
|
|
225
|
+
|
|
226
|
+
### Custom Operators
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
from sqlmesh_dag_generator import SQLMeshDAGGenerator
|
|
230
|
+
from airflow.operators.python import PythonOperator
|
|
231
|
+
|
|
232
|
+
generator = SQLMeshDAGGenerator(
|
|
233
|
+
sqlmesh_project_path="/path/to/project",
|
|
234
|
+
custom_operator_class=PythonOperator,
|
|
235
|
+
operator_kwargs={"provide_context": True}
|
|
236
|
+
)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Model Filtering
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
# Generate DAG for specific models only
|
|
243
|
+
generator = SQLMeshDAGGenerator(
|
|
244
|
+
sqlmesh_project_path="/path/to/project",
|
|
245
|
+
include_models=["model1", "model2"],
|
|
246
|
+
exclude_models=["test_*"]
|
|
247
|
+
)
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Dynamic Task Generation
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
# Generate tasks with dynamic parallelism
|
|
254
|
+
generator = SQLMeshDAGGenerator(
|
|
255
|
+
sqlmesh_project_path="/path/to/project",
|
|
256
|
+
enable_dynamic_tasks=True,
|
|
257
|
+
max_parallel_tasks=10
|
|
258
|
+
)
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Requirements
|
|
262
|
+
|
|
263
|
+
- Python >= 3.8
|
|
264
|
+
- Apache Airflow >= 2.0
|
|
265
|
+
- SQLMesh >= 0.20.0
|
|
266
|
+
|
|
267
|
+
## Development
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
# Clone the repository
|
|
271
|
+
git clone https://github.com/yourusername/sqlmesh-dag-generator.git
|
|
272
|
+
cd sqlmesh-dag-generator
|
|
273
|
+
|
|
274
|
+
# Install in development mode
|
|
275
|
+
pip install -e ".[dev]"
|
|
276
|
+
|
|
277
|
+
# Run tests
|
|
278
|
+
pytest
|
|
279
|
+
|
|
280
|
+
# Run linter
|
|
281
|
+
black .
|
|
282
|
+
ruff check .
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Contributing
|
|
286
|
+
|
|
287
|
+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
288
|
+
|
|
289
|
+
## License
|
|
290
|
+
|
|
291
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
292
|
+
|
|
293
|
+
## Comparison with Tobiko Cloud
|
|
294
|
+
|
|
295
|
+
| Feature | Tobiko Cloud | SQLMesh DAG Generator |
|
|
296
|
+
|---------|-------------|----------------------|
|
|
297
|
+
| Cost | Paid | **Free & Open Source** |
|
|
298
|
+
| Deployment | Cloud-based | **Self-hosted** |
|
|
299
|
+
| Customization | Limited | **Fully Customizable** |
|
|
300
|
+
| Privacy | External | **On-premise** |
|
|
301
|
+
| Dependencies | Cloud connection | **None** |
|
|
302
|
+
|
|
303
|
+
## Support
|
|
304
|
+
|
|
305
|
+
- 📖 [Documentation](https://github.com/yourusername/sqlmesh-dag-generator/docs)
|
|
306
|
+
- 🐛 [Issue Tracker](https://github.com/yourusername/sqlmesh-dag-generator/issues)
|
|
307
|
+
- 💬 [Discussions](https://github.com/yourusername/sqlmesh-dag-generator/discussions)
|
|
308
|
+
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# SQLMesh DAG Generator
|
|
2
|
+
|
|
3
|
+
Generate Apache Airflow DAGs from SQLMesh projects - **no cloud dependencies required**.
|
|
4
|
+
|
|
5
|
+
Transform your SQLMesh models into production-ready Airflow DAGs with **full data lineage**, automatically!
|
|
6
|
+
|
|
7
|
+
## ✨ Key Features
|
|
8
|
+
|
|
9
|
+
- 🔥 **Dynamic DAG Generation (Default)**: Fire-and-forget - place DAG once, auto-discovers models at runtime
|
|
10
|
+
- ✅ **Full Lineage in Airflow**: Each SQLMesh model = One Airflow task with proper dependencies
|
|
11
|
+
- 🌍 **Multi-Environment Support**: Use Airflow Variables for dev/staging/prod
|
|
12
|
+
- ⚡ **Incremental Models**: Proper handling with `data_interval_start/end`
|
|
13
|
+
- 🎯 **Enhanced Error Handling**: SQLMesh-specific error messages in Airflow logs
|
|
14
|
+
- 🛠️ **Dual Mode**: Dynamic (auto-discovery, default) or Static (full control)
|
|
15
|
+
- 🚫 **No Vendor Lock-in**: Open source, no cloud dependencies
|
|
16
|
+
|
|
17
|
+
## 🚀 Quick Start (3 Steps)
|
|
18
|
+
|
|
19
|
+
### 1. Install
|
|
20
|
+
```bash
|
|
21
|
+
pip install sqlmesh-dag-generator # (when published)
|
|
22
|
+
# OR
|
|
23
|
+
git clone <repo> && cd SQLMeshDAGGenerator && pip install -e .
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. Generate DAG (Dynamic Mode - Default!)
|
|
27
|
+
```python
|
|
28
|
+
from sqlmesh_dag_generator import SQLMeshDAGGenerator
|
|
29
|
+
|
|
30
|
+
# Point to your SQLMesh project
|
|
31
|
+
generator = SQLMeshDAGGenerator(
|
|
32
|
+
sqlmesh_project_path="/path/to/your/sqlmesh/project",
|
|
33
|
+
dag_id="my_pipeline",
|
|
34
|
+
schedule_interval="@daily"
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
# Generate dynamic DAG (default - fire and forget!)
|
|
38
|
+
dag_code = generator.generate_dynamic_dag()
|
|
39
|
+
|
|
40
|
+
# Save it
|
|
41
|
+
with open("my_pipeline.py", "w") as f:
|
|
42
|
+
f.write(dag_code)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 3. Deploy to Airflow
|
|
46
|
+
```bash
|
|
47
|
+
cp my_pipeline.py /opt/airflow/dags/
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**That's it! 🎉** Your SQLMesh models are now orchestrated by Airflow. The DAG will auto-discover models at runtime - no regeneration needed when models change!
|
|
51
|
+
|
|
52
|
+
## 💡 What You Get
|
|
53
|
+
|
|
54
|
+
### Your SQLMesh Project:
|
|
55
|
+
```
|
|
56
|
+
my_project/
|
|
57
|
+
└── models/
|
|
58
|
+
├── raw_orders.sql
|
|
59
|
+
├── stg_orders.sql # depends on raw_orders
|
|
60
|
+
└── orders_summary.sql # depends on stg_orders
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Generated Airflow DAG:
|
|
64
|
+
```
|
|
65
|
+
Airflow Graph View:
|
|
66
|
+
[raw_orders] → [stg_orders] → [orders_summary]
|
|
67
|
+
|
|
68
|
+
✅ Each model = separate task
|
|
69
|
+
✅ SQLMesh dependencies = Airflow dependencies
|
|
70
|
+
✅ Full lineage visible in Airflow UI
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 📚 Documentation
|
|
74
|
+
|
|
75
|
+
- **[Quick Start Guide](docs/QUICKSTART.md)** - Step-by-step tutorial (start here!)
|
|
76
|
+
- **[Usage Guide](docs/USAGE.md)** - Complete reference
|
|
77
|
+
- **[Dynamic DAGs](docs/DYNAMIC_DAGS.md)** - Fire-and-forget mode explained
|
|
78
|
+
- **[Examples](examples/)** - Code examples
|
|
79
|
+
- **[Architecture](docs/ARCHITECTURE.md)** - Technical details
|
|
80
|
+
|
|
81
|
+
## 🔥 Why Dynamic Mode (Default)?
|
|
82
|
+
|
|
83
|
+
**Dynamic mode** auto-discovers SQLMesh models at runtime:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
dag_code = generator.generate_dynamic_dag() # Default behavior!
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Benefits:**
|
|
90
|
+
- ✅ **No regeneration needed** when SQLMesh models change
|
|
91
|
+
- ✅ **Always in sync** - DAG updates automatically
|
|
92
|
+
- ✅ **Multi-environment** - Uses Airflow Variables
|
|
93
|
+
- ✅ **Production-ready** - Enhanced error handling
|
|
94
|
+
|
|
95
|
+
Want static mode instead? Just use `generator.generate_dag()` - see [Usage Guide](docs/USAGE.md).
|
|
96
|
+
|
|
97
|
+
## 🎯 Simple Example
|
|
98
|
+
|
|
99
|
+
The simplest possible usage - just 3 lines of code:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from sqlmesh_dag_generator import SQLMeshDAGGenerator
|
|
103
|
+
|
|
104
|
+
generator = SQLMeshDAGGenerator(
|
|
105
|
+
sqlmesh_project_path="/path/to/your/sqlmesh/project",
|
|
106
|
+
dag_id="my_pipeline"
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
dag_code = generator.generate_dynamic_dag()
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
See [examples/simple_generate.py](examples/simple_generate.py) for a complete runnable example.
|
|
113
|
+
|
|
114
|
+
## 🤝 Contributing
|
|
115
|
+
|
|
116
|
+
Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
117
|
+
|
|
118
|
+
## 📄 License
|
|
119
|
+
|
|
120
|
+
[Your License Here]
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
**Built with ❤️ for the data engineering community**
|
|
125
|
+
|
|
126
|
+
### Configuration File
|
|
127
|
+
|
|
128
|
+
Create a `dag_generator_config.yaml`:
|
|
129
|
+
|
|
130
|
+
```yaml
|
|
131
|
+
sqlmesh:
|
|
132
|
+
project_path: "/path/to/sqlmesh/project"
|
|
133
|
+
environment: "prod"
|
|
134
|
+
gateway: "local"
|
|
135
|
+
|
|
136
|
+
airflow:
|
|
137
|
+
dag_id: "sqlmesh_pipeline"
|
|
138
|
+
schedule_interval: "0 0 * * *"
|
|
139
|
+
default_args:
|
|
140
|
+
owner: "data-team"
|
|
141
|
+
retries: 3
|
|
142
|
+
retry_delay_minutes: 5
|
|
143
|
+
tags:
|
|
144
|
+
- sqlmesh
|
|
145
|
+
- analytics
|
|
146
|
+
|
|
147
|
+
generation:
|
|
148
|
+
output_dir: "/path/to/airflow/dags"
|
|
149
|
+
operator_type: "python" # or "bash"
|
|
150
|
+
include_tests: true
|
|
151
|
+
parallel_tasks: true
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## How It Works
|
|
155
|
+
|
|
156
|
+
1. **Load SQLMesh Project**: Reads your SQLMesh project configuration and models
|
|
157
|
+
2. **Extract Dependencies**: Analyzes SQL queries to build dependency graph
|
|
158
|
+
3. **Generate Tasks**: Creates Airflow tasks for each SQLMesh model
|
|
159
|
+
4. **Set Dependencies**: Connects tasks based on model dependencies
|
|
160
|
+
5. **Apply Schedules**: Preserves cron schedules and execution logic
|
|
161
|
+
6. **Output DAG**: Generates Python file ready for Airflow
|
|
162
|
+
|
|
163
|
+
## Architecture
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
SQLMesh Project
|
|
167
|
+
↓
|
|
168
|
+
SQLMeshDAGGenerator
|
|
169
|
+
├── Context Loader (loads SQLMesh context)
|
|
170
|
+
├── Model Parser (extracts model metadata)
|
|
171
|
+
├── Dependency Resolver (builds dependency graph)
|
|
172
|
+
└── DAG Builder (generates Airflow DAG)
|
|
173
|
+
↓
|
|
174
|
+
Airflow DAG File
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Advanced Features
|
|
178
|
+
|
|
179
|
+
### Custom Operators
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
from sqlmesh_dag_generator import SQLMeshDAGGenerator
|
|
183
|
+
from airflow.operators.python import PythonOperator
|
|
184
|
+
|
|
185
|
+
generator = SQLMeshDAGGenerator(
|
|
186
|
+
sqlmesh_project_path="/path/to/project",
|
|
187
|
+
custom_operator_class=PythonOperator,
|
|
188
|
+
operator_kwargs={"provide_context": True}
|
|
189
|
+
)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Model Filtering
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
# Generate DAG for specific models only
|
|
196
|
+
generator = SQLMeshDAGGenerator(
|
|
197
|
+
sqlmesh_project_path="/path/to/project",
|
|
198
|
+
include_models=["model1", "model2"],
|
|
199
|
+
exclude_models=["test_*"]
|
|
200
|
+
)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Dynamic Task Generation
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
# Generate tasks with dynamic parallelism
|
|
207
|
+
generator = SQLMeshDAGGenerator(
|
|
208
|
+
sqlmesh_project_path="/path/to/project",
|
|
209
|
+
enable_dynamic_tasks=True,
|
|
210
|
+
max_parallel_tasks=10
|
|
211
|
+
)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Requirements
|
|
215
|
+
|
|
216
|
+
- Python >= 3.8
|
|
217
|
+
- Apache Airflow >= 2.0
|
|
218
|
+
- SQLMesh >= 0.20.0
|
|
219
|
+
|
|
220
|
+
## Development
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
# Clone the repository
|
|
224
|
+
git clone https://github.com/yourusername/sqlmesh-dag-generator.git
|
|
225
|
+
cd sqlmesh-dag-generator
|
|
226
|
+
|
|
227
|
+
# Install in development mode
|
|
228
|
+
pip install -e ".[dev]"
|
|
229
|
+
|
|
230
|
+
# Run tests
|
|
231
|
+
pytest
|
|
232
|
+
|
|
233
|
+
# Run linter
|
|
234
|
+
black .
|
|
235
|
+
ruff check .
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Contributing
|
|
239
|
+
|
|
240
|
+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
245
|
+
|
|
246
|
+
## Comparison with Tobiko Cloud
|
|
247
|
+
|
|
248
|
+
| Feature | Tobiko Cloud | SQLMesh DAG Generator |
|
|
249
|
+
|---------|-------------|----------------------|
|
|
250
|
+
| Cost | Paid | **Free & Open Source** |
|
|
251
|
+
| Deployment | Cloud-based | **Self-hosted** |
|
|
252
|
+
| Customization | Limited | **Fully Customizable** |
|
|
253
|
+
| Privacy | External | **On-premise** |
|
|
254
|
+
| Dependencies | Cloud connection | **None** |
|
|
255
|
+
|
|
256
|
+
## Support
|
|
257
|
+
|
|
258
|
+
- 📖 [Documentation](https://github.com/yourusername/sqlmesh-dag-generator/docs)
|
|
259
|
+
- 🐛 [Issue Tracker](https://github.com/yourusername/sqlmesh-dag-generator/issues)
|
|
260
|
+
- 💬 [Discussions](https://github.com/yourusername/sqlmesh-dag-generator/discussions)
|
|
261
|
+
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[tool.pytest.ini_options]
|
|
2
|
+
testpaths = ["tests"]
|
|
3
|
+
python_files = ["test_*.py"]
|
|
4
|
+
python_classes = ["Test*"]
|
|
5
|
+
python_functions = ["test_*"]
|
|
6
|
+
addopts = [
|
|
7
|
+
"-v",
|
|
8
|
+
"--strict-markers",
|
|
9
|
+
"--tb=short",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[tool.coverage.run]
|
|
13
|
+
source = ["sqlmesh_dag_generator"]
|
|
14
|
+
omit = [
|
|
15
|
+
"*/tests/*",
|
|
16
|
+
"*/test_*.py",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[tool.coverage.report]
|
|
20
|
+
exclude_lines = [
|
|
21
|
+
"pragma: no cover",
|
|
22
|
+
"def __repr__",
|
|
23
|
+
"raise AssertionError",
|
|
24
|
+
"raise NotImplementedError",
|
|
25
|
+
"if __name__ == .__main__.:",
|
|
26
|
+
"if TYPE_CHECKING:",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[tool.black]
|
|
30
|
+
line-length = 100
|
|
31
|
+
target-version = ['py38', 'py39', 'py310', 'py311']
|
|
32
|
+
include = '\.pyi?$'
|
|
33
|
+
extend-exclude = '''
|
|
34
|
+
/(
|
|
35
|
+
# directories
|
|
36
|
+
\.eggs
|
|
37
|
+
| \.git
|
|
38
|
+
| \.mypy_cache
|
|
39
|
+
| \.venv
|
|
40
|
+
| build
|
|
41
|
+
| dist
|
|
42
|
+
)/
|
|
43
|
+
'''
|
|
44
|
+
|
|
45
|
+
[tool.ruff]
|
|
46
|
+
line-length = 100
|
|
47
|
+
target-version = "py38"
|
|
48
|
+
select = [
|
|
49
|
+
"E", # pycodestyle errors
|
|
50
|
+
"W", # pycodestyle warnings
|
|
51
|
+
"F", # pyflakes
|
|
52
|
+
"I", # isort
|
|
53
|
+
"B", # flake8-bugbear
|
|
54
|
+
"C4", # flake8-comprehensions
|
|
55
|
+
"UP", # pyupgrade
|
|
56
|
+
]
|
|
57
|
+
ignore = [
|
|
58
|
+
"E501", # line too long, handled by black
|
|
59
|
+
"B008", # do not perform function calls in argument defaults
|
|
60
|
+
"C901", # too complex
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
[tool.mypy]
|
|
64
|
+
python_version = "3.8"
|
|
65
|
+
warn_return_any = true
|
|
66
|
+
warn_unused_configs = true
|
|
67
|
+
disallow_untyped_defs = false
|
|
68
|
+
disallow_incomplete_defs = false
|
|
69
|
+
check_untyped_defs = true
|
|
70
|
+
no_implicit_optional = true
|
|
71
|
+
warn_redundant_casts = true
|
|
72
|
+
warn_unused_ignores = true
|
|
73
|
+
warn_no_return = true
|
|
74
|
+
|