nbtemplate-py 0.1.0__py3-none-any.whl

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MakPr016
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 OR ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,522 @@
1
+ Metadata-Version: 2.1
2
+ Name: nbtemplate-py
3
+ Version: 0.1.0
4
+ Summary: CLI tool to manage and populate Jupyter notebook templates
5
+ Home-page: https://github.com/MakPr016/nbtemplate
6
+ Author: MakPr016
7
+ Author-email: makcode31sk@gmail.com
8
+ License: MIT
9
+ Project-URL: Bug Reports, https://github.com/MakPr016/nbtemplate/issues
10
+ Project-URL: Source, https://github.com/MakPr016/nbtemplate
11
+ Project-URL: Documentation, https://github.com/MakPr016/nbtemplate#readme
12
+ Keywords: jupyter notebook template colab automation
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Topic :: Scientific/Engineering
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Classifier: License :: OSI Approved :: MIT License
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.7
21
+ Classifier: Programming Language :: Python :: 3.8
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Requires-Python: >=3.7
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: click >=7.0
29
+
30
+ # NBTemplate
31
+
32
+ **A CLI tool to manage and auto-fill Jupyter Notebook templates** - Create reusable notebook templates and quickly generate new notebooks with your custom code blocks.
33
+
34
+ ## Features
35
+
36
+ - **Create Templates** - Mark code blocks in your notebooks as template placeholders
37
+ - **Interactive CLI** - Get prompted for each template block when creating notebooks
38
+ - **Easy Distribution** - Share templates as `.ipynb` files
39
+ - **Flexible Syntax** - Use `###TEMPLATE:block_name###` or `{{block_name}}` to mark blocks
40
+ - **Customizable** - Define block descriptions in your templates
41
+ - **Pre-loaded Templates** - Comes with built-in example templates
42
+ - **Template Management** - Organize templates in folders, add new ones easily
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install nbtemplate-py
48
+ ```
49
+
50
+ ## Quick Start
51
+
52
+ ### 1. See available templates
53
+
54
+ ```bash
55
+ nbtemplate list
56
+ ```
57
+
58
+ You'll see bundled templates like `ml_template` that come with the package!
59
+
60
+ ### 2. Create a notebook from a template
61
+
62
+ ```bash
63
+ nbtemplate create --output my_notebook.ipynb
64
+ ```
65
+
66
+ The CLI will:
67
+
68
+ 1. Show available templates (bundled + your custom ones)
69
+ 2. Let you select one
70
+ 3. Prompt for each template block
71
+ 4. Create and save your notebook
72
+
73
+ ### 3. Add your own templates
74
+
75
+ Create a Jupyter notebook with template markers and save it:
76
+
77
+ ```bash
78
+ nbtemplate add /path/to/your/template.ipynb
79
+ ```
80
+
81
+ Your custom templates are saved to: `~/.nbtemplate/templates/`
82
+
83
+ #### Example template structure
84
+
85
+ **Cell 1 - Configuration:**
86
+
87
+ ```python
88
+ TEMPLATE_CONFIG = {
89
+ "imports": "Import libraries and dependencies",
90
+ "data_loading": "Load and explore your dataset",
91
+ "analysis": "Main analysis code",
92
+ "visualization": "Create plots and visualizations",
93
+ }
94
+ ```
95
+
96
+ **Cell 2 - Imports Block:**
97
+
98
+ ```python
99
+ ###TEMPLATE:imports###
100
+ # Your imports will be inserted here
101
+ ```
102
+
103
+ **Cell 3 - Data Loading Block:**
104
+
105
+ ```python
106
+ ###TEMPLATE:data_loading###
107
+ # Your data loading code will go here
108
+ ```
109
+
110
+ **Cell 4 - Analysis Block:**
111
+
112
+ ```python
113
+ ###TEMPLATE:analysis###
114
+ # Your analysis code will go here
115
+ ```
116
+
117
+ **Cell 5 - Visualization Block:**
118
+
119
+ ```python
120
+ ###TEMPLATE:visualization###
121
+ # Your visualization code will go here
122
+ ```
123
+
124
+ Save as `my_template.ipynb` and add it:
125
+
126
+ ```bash
127
+ nbtemplate add my_template.ipynb
128
+ ```
129
+
130
+ ## Commands
131
+
132
+ ### `nbtemplate list`
133
+
134
+ List all available templates (bundled + user templates).
135
+
136
+ ```bash
137
+ nbtemplate list
138
+ nbtemplate list --templates-dir ./my_templates
139
+ ```
140
+
141
+ ### `nbtemplate create`
142
+
143
+ Create a new notebook by filling a template interactively.
144
+
145
+ ```bash
146
+ nbtemplate create
147
+ nbtemplate create --output my_notebook.ipynb
148
+ nbtemplate create --templates-dir ./my_templates
149
+ ```
150
+
151
+ **Options:**
152
+
153
+ - `-o, --output`: Output notebook path (default: `notebook.ipynb`)
154
+ - `--templates-dir`: Use a custom templates directory
155
+
156
+ ### `nbtemplate add`
157
+
158
+ Add a template notebook to your templates directory.
159
+
160
+ ```bash
161
+ nbtemplate add path/to/template.ipynb
162
+ nbtemplate add path/to/template.ipynb --templates-dir ./my_templates
163
+ ```
164
+
165
+ ### `nbtemplate init`
166
+
167
+ Initialize a new templates directory with an example template.
168
+
169
+ ```bash
170
+ nbtemplate init
171
+ nbtemplate init --templates-dir ./my_templates
172
+ ```
173
+
174
+ ## Template Organization
175
+
176
+ ### Bundled Templates
177
+
178
+ When you install nbtemplate, you get built-in templates:
179
+
180
+ - `ml_template` - Machine learning workflow with 6 stages
181
+
182
+ These are included in the package and work out of the box!
183
+
184
+ ### User Templates
185
+
186
+ Your custom templates are stored in: `~/.nbtemplate/templates/`
187
+
188
+ Just add `.ipynb` files there and they'll automatically appear in `nbtemplate list`!
189
+
190
+ **Folder structure:**
191
+
192
+ ```
193
+ ~/.nbtemplate/
194
+ └── templates/
195
+ ├── data_analysis.ipynb
196
+ ├── research_notebook.ipynb
197
+ └── my_custom_template.ipynb
198
+ ```
199
+
200
+ ## Quick Start
201
+
202
+ ### 1. Initialize templates directory
203
+
204
+ ```bash
205
+ nbtemplate init
206
+ ```
207
+
208
+ This creates `~/.nbtemplate/templates/` with an example template.
209
+
210
+ ### 2. Create your first template
211
+
212
+ Create a Jupyter notebook with template markers:
213
+
214
+ ```python
215
+ # Cell 1 - Configuration
216
+ TEMPLATE_CONFIG = {
217
+ "imports": "Import libraries and dependencies",
218
+ "data_loading": "Load and explore your dataset",
219
+ "analysis": "Main analysis code",
220
+ "visualization": "Create plots and visualizations",
221
+ }
222
+
223
+ # Cell 2 - Imports block
224
+ ###TEMPLATE:imports###
225
+ # Your imports will go here
226
+
227
+ # Cell 3 - Data Loading block
228
+ ###TEMPLATE:data_loading###
229
+ # Your data loading code will go here
230
+
231
+ # Cell 4 - Analysis block
232
+ ###TEMPLATE:analysis###
233
+ # Your analysis code will go here
234
+
235
+ # Cell 5 - Visualization block
236
+ ###TEMPLATE:visualization###
237
+ # Your visualization code will go here
238
+ ```
239
+
240
+ Save as `my_template.ipynb` and add it:
241
+
242
+ ```bash
243
+ nbtemplate add my_template.ipynb
244
+ ```
245
+
246
+ ### 3. Create notebooks from templates
247
+
248
+ ```bash
249
+ nbtemplate create
250
+ ```
251
+
252
+ The CLI will:
253
+
254
+ 1. Show available templates
255
+ 2. Let you select one
256
+ 3. Prompt for each template block
257
+ 4. Create and save your notebook
258
+
259
+ Specify output path:
260
+
261
+ ```bash
262
+ nbtemplate create --output my_analysis.ipynb
263
+ ```
264
+
265
+ ## Commands
266
+
267
+ ### `nbtemplate init`
268
+
269
+ Initialize a new templates directory with an example template.
270
+
271
+ ```bash
272
+ nbtemplate init
273
+ nbtemplate init --templates-dir ./my_templates
274
+ ```
275
+
276
+ ### `nbtemplate list`
277
+
278
+ List all available templates.
279
+
280
+ ```bash
281
+ nbtemplate list
282
+ nbtemplate list --templates-dir ./my_templates
283
+ ```
284
+
285
+ ### `nbtemplate add`
286
+
287
+ Add a template notebook to the templates directory.
288
+
289
+ ```bash
290
+ nbtemplate add path/to/template.ipynb
291
+ nbtemplate add path/to/template.ipynb --templates-dir ./my_templates
292
+ ```
293
+
294
+ ### `nbtemplate create`
295
+
296
+ Create a new notebook by filling a template interactively.
297
+
298
+ ```bash
299
+ nbtemplate create
300
+ nbtemplate create --output my_notebook.ipynb
301
+ nbtemplate create --templates-dir ./my_templates
302
+ ```
303
+
304
+ ## Template Syntax
305
+
306
+ Mark placeholder blocks in your template using either syntax:
307
+
308
+ ### Syntax 1: Comment markers
309
+
310
+ ```python
311
+ ###TEMPLATE:block_name###
312
+ # placeholder code
313
+ ```
314
+
315
+ ### Syntax 2: Mustache-style
316
+
317
+ ```python
318
+ {{block_name}}
319
+ # placeholder code
320
+ ```
321
+
322
+ ## Configuration
323
+
324
+ ### Custom templates directory
325
+
326
+ Set the `NBTEMPLATE_DIR` environment variable:
327
+
328
+ ```bash
329
+ # Linux/Mac
330
+ export NBTEMPLATE_DIR=/path/to/my/templates
331
+ nbtemplate create
332
+
333
+ # Windows (PowerShell)
334
+ $env:NBTEMPLATE_DIR="C:\path\to\templates"
335
+ nbtemplate create
336
+ ```
337
+
338
+ Or use `--templates-dir` with any command:
339
+
340
+ ```bash
341
+ nbtemplate create --templates-dir /path/to/my/templates
342
+ ```
343
+
344
+ ### Template block descriptions
345
+
346
+ Add a `TEMPLATE_CONFIG` dict in the first code cell to provide descriptions:
347
+
348
+ ```python
349
+ TEMPLATE_CONFIG = {
350
+ "imports": "Import necessary libraries",
351
+ "data_loading": "Load and explore data",
352
+ "preprocessing": "Data cleaning and preprocessing",
353
+ }
354
+ ```
355
+
356
+ Descriptions are shown when filling templates for context.
357
+
358
+ ## Example Workflows
359
+
360
+ ### Machine Learning Pipeline
361
+
362
+ ```python
363
+ TEMPLATE_CONFIG = {
364
+ 'imports': 'Import ML libraries (pandas, scikit-learn, numpy)',
365
+ 'data_loading': 'Load and explore your dataset',
366
+ 'preprocessing': 'Data preprocessing and feature engineering',
367
+ 'model_training': 'Train your machine learning model',
368
+ 'evaluation': 'Evaluate model performance with metrics',
369
+ 'visualization': 'Create visualizations and plots',
370
+ }
371
+ ```
372
+
373
+ ### Data Analysis
374
+
375
+ ```python
376
+ TEMPLATE_CONFIG = {
377
+ "imports": "Import pandas, numpy, matplotlib",
378
+ "data_loading": "Load your CSV or dataset",
379
+ "exploration": "Exploratory data analysis",
380
+ "insights": "Key findings and conclusions",
381
+ }
382
+ ```
383
+
384
+ ### Research Notebook
385
+
386
+ ```python
387
+ TEMPLATE_CONFIG = {
388
+ "literature": "Related work and background",
389
+ "hypothesis": "Research hypothesis and approach",
390
+ "implementation": "Implementation of the approach",
391
+ "experiments": "Experimental setup and execution",
392
+ "results": "Results and analysis",
393
+ "conclusion": "Conclusions and future work",
394
+ }
395
+ ```
396
+
397
+ ## Google Colab Support
398
+
399
+ NBTemplate works great with Google Colab!
400
+
401
+ ```bash
402
+ # In Colab cell
403
+ !pip install nbtemplate
404
+ !nbtemplate init
405
+ !nbtemplate create --output my_notebook.ipynb
406
+ ```
407
+
408
+ Or download templates from GitHub:
409
+
410
+ ```bash
411
+ !nbtemplate add https://raw.githubusercontent.com/user/repo/main/templates/ml_template.ipynb
412
+ !nbtemplate create
413
+ ```
414
+
415
+ ## Sharing Templates
416
+
417
+ ### Share via GitHub
418
+
419
+ 1. Create a repository for your templates
420
+ 2. Add your `.ipynb` template files
421
+ 3. Share the repository URL
422
+ 4. Others can clone and add templates
423
+
424
+ ### Use Cases
425
+
426
+ - **Data Analysis** - Template with data loading, EDA, and visualization blocks
427
+ - **Machine Learning** - Standardized ML pipeline (preprocessing, training, evaluation)
428
+ - **Reports** - Consistent report structure across projects
429
+ - **Experiments** - Reproducible experiment setup
430
+ - **Education** - Structured assignment templates for students
431
+ - **Team Projects** - Standardized notebooks for team collaboration
432
+
433
+ ## Python API
434
+
435
+ You can also use NBTemplate programmatically:
436
+
437
+ ```python
438
+ from nbtemplate.template import TemplateManager, TemplateBlockCollector
439
+
440
+ # Load templates
441
+ tm = TemplateManager("~/.nbtemplate/templates")
442
+ templates = tm.get_available_templates()
443
+
444
+ # Fill template
445
+ blocks = {
446
+ "imports": "import pandas as pd",
447
+ "data_loading": "df = pd.read_csv('data.csv')",
448
+ "analysis": "print(df.describe())",
449
+ }
450
+
451
+ notebook = tm.fill_template("my_template", blocks)
452
+ tm.save_notebook(notebook, "output.ipynb")
453
+ ```
454
+
455
+ ## Project Structure
456
+
457
+ ```
458
+ nbtemplate/
459
+ ├── __init__.py # Package metadata
460
+ ├── template.py # Core logic (TemplateManager, TemplateBlockCollector)
461
+ ├── cli.py # CLI commands
462
+ ├── templates/ # Built-in templates
463
+ │ ├── ml_template.ipynb # Example ML template
464
+ │ └── __init__.py
465
+ ├── setup.py # Package configuration
466
+ ├── README.md # This file
467
+ └── LICENSE # MIT License
468
+ ```
469
+
470
+ ## Troubleshooting
471
+
472
+ ### Templates not found
473
+
474
+ ```bash
475
+ # Check templates directory
476
+ nbtemplate list
477
+
478
+ # Initialize templates
479
+ nbtemplate init
480
+
481
+ # Set custom directory
482
+ export NBTEMPLATE_DIR=/your/path
483
+ nbtemplate list
484
+ ```
485
+
486
+ ### Template block not recognized
487
+
488
+ Check that block markers use the correct syntax:
489
+
490
+ - `###TEMPLATE:block_name###` (triple hashes)
491
+ - `{{block_name}}` (double braces)
492
+
493
+ Block names must be alphanumeric with underscores.
494
+
495
+ ## Requirements
496
+
497
+ - Python 3.7+
498
+ - click (installed automatically)
499
+
500
+ ## License
501
+
502
+ MIT License - see LICENSE file for details
503
+
504
+ ## Contributing
505
+
506
+ Contributions welcome! Please feel free to:
507
+
508
+ - Report issues
509
+ - Submit pull requests
510
+ - Share template ideas
511
+ - Suggest improvements
512
+
513
+ Visit the repository: <https://github.com/MakPr016/nbtemplate>
514
+
515
+ ## Support
516
+
517
+ For issues, questions, or feature requests, please visit:
518
+ <https://github.com/MakPr016/nbtemplate/issues>
519
+
520
+ ---
521
+
522
+ Made with ❤️ by MakPr016
@@ -0,0 +1,7 @@
1
+ templates/__init__.py,sha256=Tl16tsoR1Sey1twFEXyjo0qscPU3wUk6ekNFFokXtqM,85
2
+ nbtemplate_py-0.1.0.dist-info/LICENSE,sha256=F0vyyskstkPohIUSD7REJMXTCcedkC6rveCwFLLtD4M,1067
3
+ nbtemplate_py-0.1.0.dist-info/METADATA,sha256=FecJ8C6wg-HrD_CocBQnsAdrfRr4iDcb-9eXkZLjgY4,12346
4
+ nbtemplate_py-0.1.0.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
5
+ nbtemplate_py-0.1.0.dist-info/entry_points.txt,sha256=D0DB7IyBwh1Gu993khNhdundPIbuhlSFG9boc7VoUts,51
6
+ nbtemplate_py-0.1.0.dist-info/top_level.txt,sha256=Fm_uifOIeZdeTkA7g1vBrg8_icDP_XC7Gw4TPobfX0s,10
7
+ nbtemplate_py-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (70.2.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ nbtemplate = nbtemplate.cli:main
@@ -0,0 +1 @@
1
+ templates
templates/__init__.py ADDED
@@ -0,0 +1 @@
1
+ # This file ensures the templates directory is included in the package distribution