pyblade 0.2.0__tar.gz → 0.3.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.
Files changed (152) hide show
  1. pyblade-0.3.0/LICENSE +28 -0
  2. pyblade-0.3.0/PKG-INFO +199 -0
  3. pyblade-0.3.0/README.md +166 -0
  4. pyblade-0.3.0/pyblade/__init__.py +82 -0
  5. pyblade-0.3.0/pyblade/backends/__init__.py +30 -0
  6. pyblade-0.3.0/pyblade/backends/base.py +92 -0
  7. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/backends/django.py +22 -6
  8. pyblade-0.3.0/pyblade/backends/fastapi.py +9 -0
  9. pyblade-0.3.0/pyblade/backends/flask.py +23 -0
  10. pyblade-0.3.0/pyblade/backends/litestar.py +15 -0
  11. pyblade-0.3.0/pyblade/backends/quart.py +27 -0
  12. pyblade-0.3.0/pyblade/backends/sanic.py +12 -0
  13. pyblade-0.3.0/pyblade/backends/starlette.py +12 -0
  14. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/base.py +88 -25
  15. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/commands/convert.py +19 -7
  16. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/commands/deploy.py +1 -2
  17. pyblade-0.3.0/pyblade/cli/commands/dev.py +172 -0
  18. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/commands/docs.py +1 -1
  19. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/commands/example.py +0 -2
  20. pyblade-0.3.0/pyblade/cli/commands/init.py +375 -0
  21. pyblade-0.3.0/pyblade/cli/commands/live:stubs.py +56 -0
  22. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/commands/login.py +0 -2
  23. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/commands/logout.py +0 -2
  24. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/commands/make:command.py +3 -4
  25. pyblade-0.3.0/pyblade/cli/commands/make:component.py +74 -0
  26. pyblade-0.2.0/pyblade/cli/commands/make:liveblade.py → pyblade-0.3.0/pyblade/cli/commands/make:live.py +34 -22
  27. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/commands/make:template.py +13 -7
  28. pyblade-0.3.0/pyblade/cli/commands/messages:compile.py +176 -0
  29. pyblade-0.3.0/pyblade/cli/commands/messages:make.py +452 -0
  30. pyblade-0.3.0/pyblade/cli/commands/tailwind:config.py +60 -0
  31. pyblade-0.3.0/pyblade/cli/commands/upgrade.py +43 -0
  32. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/django_base.py +14 -40
  33. pyblade-0.3.0/pyblade/cli/exceptions.py +4 -0
  34. pyblade-0.3.0/pyblade/cli/locations.py +83 -0
  35. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/main.py +47 -29
  36. pyblade-0.3.0/pyblade/cli/packages.py +331 -0
  37. pyblade-0.3.0/pyblade/cli/stubs/fastapi/main.py.stub +12 -0
  38. pyblade-0.3.0/pyblade/cli/stubs/flask/app.py.stub +12 -0
  39. pyblade-0.3.0/pyblade/cli/stubs/live/component.py.stub +8 -0
  40. pyblade-0.3.0/pyblade/cli/stubs/live/confirm_dialogue.html.stub +29 -0
  41. {pyblade-0.2.0/pyblade/cli/stubs/liveblade → pyblade-0.3.0/pyblade/cli/stubs/live}/inline_component.py.stub +3 -3
  42. pyblade-0.3.0/pyblade/cli/stubs/live/template.html.stub +3 -0
  43. pyblade-0.3.0/pyblade/cli/stubs/pagination/tailwind.html.stub +67 -0
  44. pyblade-0.3.0/pyblade/cli/stubs/templates/layout.html.stub +13 -0
  45. {pyblade-0.2.0/pyblade/cli/stubs → pyblade-0.3.0/pyblade/cli/stubs/templates}/tailwind_layout.html.stub +5 -5
  46. pyblade-0.3.0/pyblade/cli/stubs/templates/welcome.html.stub +14 -0
  47. pyblade-0.3.0/pyblade/cli/stubs/welcome.html +323 -0
  48. pyblade-0.3.0/pyblade/cli/tailwind.py +111 -0
  49. pyblade-0.3.0/pyblade/config.py +644 -0
  50. pyblade-0.3.0/pyblade/django.py +10 -0
  51. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/engine/cache.py +2 -3
  52. pyblade-0.3.0/pyblade/engine/contexts.py +354 -0
  53. pyblade-0.3.0/pyblade/engine/exceptions.py +115 -0
  54. pyblade-0.3.0/pyblade/engine/filters.py +145 -0
  55. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/engine/lexer.py +86 -11
  56. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/engine/loader.py +40 -14
  57. pyblade-0.3.0/pyblade/engine/nodes.py +2600 -0
  58. pyblade-0.3.0/pyblade/engine/parser.py +1708 -0
  59. pyblade-0.3.0/pyblade/engine/processor.py +349 -0
  60. pyblade-0.3.0/pyblade/engine/registry.py +20 -0
  61. pyblade-0.3.0/pyblade/engine/renderer.py +189 -0
  62. pyblade-0.3.0/pyblade/engine/roots.py +76 -0
  63. pyblade-0.3.0/pyblade/engine/sandbox.py +277 -0
  64. pyblade-0.3.0/pyblade/engine/stacks.py +142 -0
  65. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/engine/template.py +31 -11
  66. pyblade-0.3.0/pyblade/engine/templates/error.html +210 -0
  67. pyblade-0.3.0/pyblade/fastapi.py +10 -0
  68. pyblade-0.3.0/pyblade/flask.py +10 -0
  69. pyblade-0.3.0/pyblade/i18n.py +178 -0
  70. pyblade-0.3.0/pyblade/litestar.py +10 -0
  71. pyblade-0.3.0/pyblade/live/__init__.py +15 -0
  72. pyblade-0.3.0/pyblade/live/apps.py +6 -0
  73. pyblade-0.3.0/pyblade/live/base.py +1589 -0
  74. pyblade-0.3.0/pyblade/live/decorators.py +200 -0
  75. pyblade-0.3.0/pyblade/live/mixins.py +36 -0
  76. pyblade-0.3.0/pyblade/live/pagination.py +470 -0
  77. pyblade-0.3.0/pyblade/live/registry.py +60 -0
  78. pyblade-0.3.0/pyblade/live/security.py +39 -0
  79. pyblade-0.3.0/pyblade/live/skeleton.py +72 -0
  80. pyblade-0.3.0/pyblade/live/static/pyblade.css +475 -0
  81. pyblade-0.3.0/pyblade/live/static/pyblade.min.js +13 -0
  82. pyblade-0.3.0/pyblade/live/static/vendor/idiomorph.esm.js +1385 -0
  83. pyblade-0.3.0/pyblade/live/testing.py +250 -0
  84. pyblade-0.3.0/pyblade/live/throttle.py +223 -0
  85. pyblade-0.3.0/pyblade/live/uploads.py +325 -0
  86. pyblade-0.3.0/pyblade/live/urls.py +10 -0
  87. pyblade-0.3.0/pyblade/live/views.py +477 -0
  88. pyblade-0.3.0/pyblade/quart.py +10 -0
  89. pyblade-0.3.0/pyblade/sanic.py +10 -0
  90. pyblade-0.3.0/pyblade/starlette.py +10 -0
  91. pyblade-0.3.0/pyblade/utils.py +114 -0
  92. pyblade-0.3.0/pyproject.toml +83 -0
  93. pyblade-0.3.0/pyproject.toml.orig +68 -0
  94. pyblade-0.2.0/LICENSE +0 -21
  95. pyblade-0.2.0/PKG-INFO +0 -148
  96. pyblade-0.2.0/README.md +0 -125
  97. pyblade-0.2.0/pyblade/.gitignore +0 -1
  98. pyblade-0.2.0/pyblade/__init__.py +0 -5
  99. pyblade-0.2.0/pyblade/backends/__init__.py +0 -5
  100. pyblade-0.2.0/pyblade/backends/fastapi.py +0 -10
  101. pyblade-0.2.0/pyblade/backends/flask.py +0 -10
  102. pyblade-0.2.0/pyblade/cli/commands/init.py +0 -250
  103. pyblade-0.2.0/pyblade/cli/commands/make:component.py +0 -53
  104. pyblade-0.2.0/pyblade/cli/commands/serve.py +0 -87
  105. pyblade-0.2.0/pyblade/cli/commands/tailwind:config.py +0 -64
  106. pyblade-0.2.0/pyblade/cli/commands/upgrade.py +0 -31
  107. pyblade-0.2.0/pyblade/cli/exceptions.py +0 -6
  108. pyblade-0.2.0/pyblade/cli/stubs/bootstrap_layout.html.stub +0 -17
  109. pyblade-0.2.0/pyblade/cli/stubs/liveblade/component.py.stub +0 -8
  110. pyblade-0.2.0/pyblade/cli/stubs/liveblade/template.html.stub +0 -3
  111. pyblade-0.2.0/pyblade/cli/stubs/pagination/bootstrap.html.stub +0 -0
  112. pyblade-0.2.0/pyblade/cli/stubs/pagination/tailwind.html.stub +0 -0
  113. pyblade-0.2.0/pyblade/cli/stubs/welcome.html.stub +0 -219
  114. pyblade-0.2.0/pyblade/config.py +0 -86
  115. pyblade-0.2.0/pyblade/engine/contexts.py +0 -245
  116. pyblade-0.2.0/pyblade/engine/directives.py +0 -1775
  117. pyblade-0.2.0/pyblade/engine/evaluator.py +0 -201
  118. pyblade-0.2.0/pyblade/engine/exceptions.py +0 -69
  119. pyblade-0.2.0/pyblade/engine/nodes.py +0 -466
  120. pyblade-0.2.0/pyblade/engine/parser.py +0 -758
  121. pyblade-0.2.0/pyblade/engine/processor.py +0 -1119
  122. pyblade-0.2.0/pyblade/engine/renderer.py +0 -215
  123. pyblade-0.2.0/pyblade/engine/templates/error.html +0 -187
  124. pyblade-0.2.0/pyblade/engine/templates/error_prod.html +0 -84
  125. pyblade-0.2.0/pyblade/engine/templates/welcome.html +0 -319
  126. pyblade-0.2.0/pyblade/engine/wrappers/__init__.py +0 -7
  127. pyblade-0.2.0/pyblade/engine/wrappers/base.py +0 -41
  128. pyblade-0.2.0/pyblade/engine/wrappers/collection.py +0 -68
  129. pyblade-0.2.0/pyblade/engine/wrappers/datetime.py +0 -70
  130. pyblade-0.2.0/pyblade/engine/wrappers/number.py +0 -88
  131. pyblade-0.2.0/pyblade/engine/wrappers/string.py +0 -54
  132. pyblade-0.2.0/pyblade/liveblade/README.md +0 -330
  133. pyblade-0.2.0/pyblade/liveblade/__init__.py +0 -3
  134. pyblade-0.2.0/pyblade/liveblade/apps.py +0 -7
  135. pyblade-0.2.0/pyblade/liveblade/base.py +0 -174
  136. pyblade-0.2.0/pyblade/liveblade/cache.py +0 -115
  137. pyblade-0.2.0/pyblade/liveblade/component_loader.py +0 -9
  138. pyblade-0.2.0/pyblade/liveblade/liveBlade.py +0 -258
  139. pyblade-0.2.0/pyblade/liveblade/middleware.py +0 -17
  140. pyblade-0.2.0/pyblade/liveblade/state.py +0 -122
  141. pyblade-0.2.0/pyblade/liveblade/static/liveblade/js/advanced-directives.js +0 -122
  142. pyblade-0.2.0/pyblade/liveblade/static/liveblade/js/scripts.js +0 -1190
  143. pyblade-0.2.0/pyblade/liveblade/static/liveblade/vendor/morphdom.min.js +0 -1
  144. pyblade-0.2.0/pyblade/liveblade/urls.py +0 -16
  145. pyblade-0.2.0/pyblade/utils.py +0 -64
  146. pyblade-0.2.0/pyproject.toml +0 -33
  147. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/__init__.py +0 -0
  148. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/commands/__init__.py +0 -0
  149. {pyblade-0.2.0 → pyblade-0.3.0}/pyblade/cli/stubs/commands/command.py.stub +0 -0
  150. {pyblade-0.2.0/pyblade/cli/stubs → pyblade-0.3.0/pyblade/cli/stubs/templates}/component.html.stub +0 -0
  151. {pyblade-0.2.0/pyblade/cli/stubs → pyblade-0.3.0/pyblade/cli/stubs/templates}/default_urlconf.html.stub +0 -0
  152. {pyblade-0.2.0/pyblade/cli/stubs → pyblade-0.3.0/pyblade/cli/stubs/templates}/template.html.stub +0 -0
pyblade-0.3.0/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, Antares Mugisho
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
pyblade-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,199 @@
1
+ Metadata-Version: 2.4
2
+ Name: PyBlade
3
+ Version: 0.3.0
4
+ Summary: PyBlade is a lightweight, reactive template engine for Python. It brings reusable UI components and server-driven interactivity to your web apps using Python and HTML, without requiring a frontend framework.
5
+ Keywords: python,templates,engine,django,spa,ssr,cli
6
+ Author: Antares Mugisho
7
+ Author-email: Antares Mugisho <hi@antaresmugisho.com>
8
+ License-Expression: BSD-3-Clause
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Web Environment
12
+ Classifier: Framework :: Django
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
19
+ Classifier: Topic :: Security
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Topic :: Text Processing :: Markup :: HTML
22
+ Requires-Dist: questionary>=2.0.1,<3
23
+ Requires-Dist: colorama>=0.4.6,<1
24
+ Requires-Dist: rich>=13.9.4,<14
25
+ Requires-Dist: click>=8.1.8,<9
26
+ Requires-Dist: polib>=1.2.0,<2
27
+ Requires-Python: >=3.11
28
+ Project-URL: Homepage, https://www.pyblade.com
29
+ Project-URL: Documentation, https://docs.pyblade.com
30
+ Project-URL: Repository, https://github.com/antaresmugisho/pyblade
31
+ Project-URL: Issues, https://github.com/antaresmugisho/pyblade/issues
32
+ Description-Content-Type: text/markdown
33
+
34
+ <p align="center">
35
+ <a href="https://pyblade.com"><img src="https://raw.githubusercontent.com/antaresmugisho/pybladedocs/main/public/images/pyblade.png" width="280" height="280" alt="PyBlade Logo"/></a>
36
+ </p>
37
+
38
+ <h1 align="center">PyBlade</h1>
39
+
40
+ <div align="center">
41
+
42
+ **_The reactive template engine for Python web frameworks._**
43
+
44
+ </div>
45
+
46
+ <div align="center">
47
+
48
+ ![GitHub License](https://img.shields.io/github/license/antaresmugisho/pyblade)
49
+ [![PyPI](https://img.shields.io/pypi/v/pyblade.svg?color=yellow)](https://pypi.org/project/pyblade/)
50
+ [![Downloads](https://pepy.tech/badge/pyblade)](https://pepy.tech/project/pyblade)
51
+ ![GitHub Stars](https://img.shields.io/github/stars/antaresmugisho/pyblade)
52
+
53
+ </div>
54
+
55
+ PyBlade is a lightweight, reactive template engine for Python. It brings reusable UI components and server-driven interactivity to your web apps using Python and HTML, without requiring a frontend framework.
56
+
57
+ >[!WARNING]
58
+ > **Beta:** PyBlade is still experimental. APIs may change between releases and it is not yet recommended for production applications.
59
+
60
+ ## Installation
61
+
62
+ Install PyBlade from PyPI:
63
+
64
+ ```bash
65
+ pip install pyblade
66
+ ```
67
+
68
+ PyBlade integrates into your existing Python web application rather than replacing your application framework.
69
+
70
+ ## CLI
71
+
72
+ PyBlade includes a CLI for common development tasks:
73
+
74
+ ```bash
75
+ pyblade init
76
+ pyblade serve
77
+ pyblade make:template
78
+ pyblade make:component
79
+ pyblade make:livecomponent
80
+ ```
81
+
82
+ To see the available commands and options, run `pyblade --help` or `pyblade <COMMAND> --help`.
83
+
84
+ See the [CLI documentation](https://docs.pyblade.com/cli) for more details.
85
+
86
+
87
+ ## Templates
88
+
89
+ PyBlade templates are regular `.html` files with additional syntax for layouts, conditions, loops, and components.
90
+
91
+ ### Layouts
92
+
93
+ ```html
94
+ @extends('layouts.base')
95
+
96
+ @block('content')
97
+ <h1>Hello, {{ user.name }}!</h1>
98
+ @endblock
99
+ ```
100
+
101
+ ### Conditions
102
+
103
+ ```html
104
+ @if(user.is_authenticated)
105
+ <p>Welcome back, {{ user.name }}.</p>
106
+ @else
107
+ <p>Please sign in.</p>
108
+ @endif
109
+ ```
110
+
111
+ ### Loops
112
+
113
+ ```html
114
+ @for(post in posts)
115
+ <article>
116
+ <h2>{{ post.title }}</h2>
117
+ </article>
118
+ @empty
119
+ <p>No posts found.</p>
120
+ @endfor
121
+ ```
122
+
123
+ ### Components
124
+
125
+ Reusable components as well as live components can be rendered directly from templates:
126
+
127
+ ```html
128
+ <pb-user-profile :user="user" />
129
+ ```
130
+
131
+ They can also be invoked with the component directive:
132
+
133
+ ```html
134
+ @component('user-profile', {'user': user})
135
+ ```
136
+
137
+
138
+ ## Framework Integration
139
+
140
+ PyBlade is designed to work with Python web frameworks and can be introduced into an existing application.
141
+
142
+ Only django is fully supported for now, we will add other frameworks support incrementally.
143
+
144
+ <!-- Framework-specific setup, configuration, and integration details are available in the [documentation](https://docs.pyblade.com/framework-integration). -->
145
+
146
+
147
+ ## Editor Support
148
+
149
+ [PyBlade IntelliSense for VS Code](https://marketplace.visualstudio.com/items?itemName=antares.pyblade-intellisense) provides:
150
+
151
+ * Syntax highlighting
152
+ * Snippets
153
+ * Directive completion
154
+ * Component completion
155
+
156
+ Additional editor integrations are planned.
157
+
158
+
159
+ ## Project Status
160
+
161
+ PyBlade is currently in beta.
162
+
163
+ The template engine, component system, CLI, Live Components, and framework integrations are actively evolving. APIs and conventions may change before the first stable release.
164
+
165
+ If you want to follow the project, report a bug, request a feature, or share feedback, visit the [GitHub repository](https://github.com/antaresmugisho/pyblade) or [PyBlade Feedback](https://feedback.pyblade.com).
166
+
167
+ ## Contributing
168
+
169
+ Contributions are welcome, including bug reports, fixes, documentation, examples, editor tooling, and new ideas.
170
+
171
+ Before contributing, please read:
172
+
173
+ * [Contributing Guide](CONTRIBUTING.md)
174
+ * [Code of Conduct](CODE_OF_CONDUCT.md)
175
+ * [Security Policy](SECURITY.md)
176
+
177
+ You can also contribute to the wider PyBlade ecosystem:
178
+
179
+ - [PyBlade Documentation](https://github.com/AntaresMugisho/PyBladeDocs), the source for [docs.pyblade.com](https://docs.pyblade.com)
180
+
181
+ - [PyBlade IntelliSense for VS Code](https://github.com/antaresmugisho/pyblade-vscode)
182
+ - [PyBlade IntelliSense for Sublime Text](https://github.com/antaresmugisho/pyblade-sublime)
183
+ - [PyBlade IntelliSense for JetBrains IDEs](https://github.com/antaresmugisho/pyblade-jetbrains)
184
+ - [PyBlade IntelliSense for Atom](https://github.com/antaresmugisho/pyblade-atom)
185
+
186
+
187
+ If you discover a security vulnerability, please follow the [Security Policy](SECURITY.md) instead of opening a public issue.
188
+
189
+ ## Acknowledgements
190
+
191
+ PyBlade's template syntax is inspired by [Laravel Blade](https://laravel.com/docs/blade), while its Live Components are inspired by [Livewire](https://livewire.laravel.com).
192
+
193
+ PyBlade builds on ideas and work from the Python, Django, and Laravel communities.
194
+
195
+ Special thanks to [Michael Dimchuk](https://github.com/michaeldimchuk) for graciously releasing the **PyBlade** name on PyPI for this project.
196
+
197
+ ## License
198
+
199
+ PyBlade is licensed under the [BSD 3-Clause License](LICENSE).
@@ -0,0 +1,166 @@
1
+ <p align="center">
2
+ <a href="https://pyblade.com"><img src="https://raw.githubusercontent.com/antaresmugisho/pybladedocs/main/public/images/pyblade.png" width="280" height="280" alt="PyBlade Logo"/></a>
3
+ </p>
4
+
5
+ <h1 align="center">PyBlade</h1>
6
+
7
+ <div align="center">
8
+
9
+ **_The reactive template engine for Python web frameworks._**
10
+
11
+ </div>
12
+
13
+ <div align="center">
14
+
15
+ ![GitHub License](https://img.shields.io/github/license/antaresmugisho/pyblade)
16
+ [![PyPI](https://img.shields.io/pypi/v/pyblade.svg?color=yellow)](https://pypi.org/project/pyblade/)
17
+ [![Downloads](https://pepy.tech/badge/pyblade)](https://pepy.tech/project/pyblade)
18
+ ![GitHub Stars](https://img.shields.io/github/stars/antaresmugisho/pyblade)
19
+
20
+ </div>
21
+
22
+ PyBlade is a lightweight, reactive template engine for Python. It brings reusable UI components and server-driven interactivity to your web apps using Python and HTML, without requiring a frontend framework.
23
+
24
+ >[!WARNING]
25
+ > **Beta:** PyBlade is still experimental. APIs may change between releases and it is not yet recommended for production applications.
26
+
27
+ ## Installation
28
+
29
+ Install PyBlade from PyPI:
30
+
31
+ ```bash
32
+ pip install pyblade
33
+ ```
34
+
35
+ PyBlade integrates into your existing Python web application rather than replacing your application framework.
36
+
37
+ ## CLI
38
+
39
+ PyBlade includes a CLI for common development tasks:
40
+
41
+ ```bash
42
+ pyblade init
43
+ pyblade serve
44
+ pyblade make:template
45
+ pyblade make:component
46
+ pyblade make:livecomponent
47
+ ```
48
+
49
+ To see the available commands and options, run `pyblade --help` or `pyblade <COMMAND> --help`.
50
+
51
+ See the [CLI documentation](https://docs.pyblade.com/cli) for more details.
52
+
53
+
54
+ ## Templates
55
+
56
+ PyBlade templates are regular `.html` files with additional syntax for layouts, conditions, loops, and components.
57
+
58
+ ### Layouts
59
+
60
+ ```html
61
+ @extends('layouts.base')
62
+
63
+ @block('content')
64
+ <h1>Hello, {{ user.name }}!</h1>
65
+ @endblock
66
+ ```
67
+
68
+ ### Conditions
69
+
70
+ ```html
71
+ @if(user.is_authenticated)
72
+ <p>Welcome back, {{ user.name }}.</p>
73
+ @else
74
+ <p>Please sign in.</p>
75
+ @endif
76
+ ```
77
+
78
+ ### Loops
79
+
80
+ ```html
81
+ @for(post in posts)
82
+ <article>
83
+ <h2>{{ post.title }}</h2>
84
+ </article>
85
+ @empty
86
+ <p>No posts found.</p>
87
+ @endfor
88
+ ```
89
+
90
+ ### Components
91
+
92
+ Reusable components as well as live components can be rendered directly from templates:
93
+
94
+ ```html
95
+ <pb-user-profile :user="user" />
96
+ ```
97
+
98
+ They can also be invoked with the component directive:
99
+
100
+ ```html
101
+ @component('user-profile', {'user': user})
102
+ ```
103
+
104
+
105
+ ## Framework Integration
106
+
107
+ PyBlade is designed to work with Python web frameworks and can be introduced into an existing application.
108
+
109
+ Only django is fully supported for now, we will add other frameworks support incrementally.
110
+
111
+ <!-- Framework-specific setup, configuration, and integration details are available in the [documentation](https://docs.pyblade.com/framework-integration). -->
112
+
113
+
114
+ ## Editor Support
115
+
116
+ [PyBlade IntelliSense for VS Code](https://marketplace.visualstudio.com/items?itemName=antares.pyblade-intellisense) provides:
117
+
118
+ * Syntax highlighting
119
+ * Snippets
120
+ * Directive completion
121
+ * Component completion
122
+
123
+ Additional editor integrations are planned.
124
+
125
+
126
+ ## Project Status
127
+
128
+ PyBlade is currently in beta.
129
+
130
+ The template engine, component system, CLI, Live Components, and framework integrations are actively evolving. APIs and conventions may change before the first stable release.
131
+
132
+ If you want to follow the project, report a bug, request a feature, or share feedback, visit the [GitHub repository](https://github.com/antaresmugisho/pyblade) or [PyBlade Feedback](https://feedback.pyblade.com).
133
+
134
+ ## Contributing
135
+
136
+ Contributions are welcome, including bug reports, fixes, documentation, examples, editor tooling, and new ideas.
137
+
138
+ Before contributing, please read:
139
+
140
+ * [Contributing Guide](CONTRIBUTING.md)
141
+ * [Code of Conduct](CODE_OF_CONDUCT.md)
142
+ * [Security Policy](SECURITY.md)
143
+
144
+ You can also contribute to the wider PyBlade ecosystem:
145
+
146
+ - [PyBlade Documentation](https://github.com/AntaresMugisho/PyBladeDocs), the source for [docs.pyblade.com](https://docs.pyblade.com)
147
+
148
+ - [PyBlade IntelliSense for VS Code](https://github.com/antaresmugisho/pyblade-vscode)
149
+ - [PyBlade IntelliSense for Sublime Text](https://github.com/antaresmugisho/pyblade-sublime)
150
+ - [PyBlade IntelliSense for JetBrains IDEs](https://github.com/antaresmugisho/pyblade-jetbrains)
151
+ - [PyBlade IntelliSense for Atom](https://github.com/antaresmugisho/pyblade-atom)
152
+
153
+
154
+ If you discover a security vulnerability, please follow the [Security Policy](SECURITY.md) instead of opening a public issue.
155
+
156
+ ## Acknowledgements
157
+
158
+ PyBlade's template syntax is inspired by [Laravel Blade](https://laravel.com/docs/blade), while its Live Components are inspired by [Livewire](https://livewire.laravel.com).
159
+
160
+ PyBlade builds on ideas and work from the Python, Django, and Laravel communities.
161
+
162
+ Special thanks to [Michael Dimchuk](https://github.com/michaeldimchuk) for graciously releasing the **PyBlade** name on PyPI for this project.
163
+
164
+ ## License
165
+
166
+ PyBlade is licensed under the [BSD 3-Clause License](LICENSE).
@@ -0,0 +1,82 @@
1
+ """PyBlade: a template engine, and live components built on it.
2
+
3
+ Nothing here needs a web framework. `pyblade init` exists to start a project
4
+ with a framework that is not installed yet, and the CLI imports PyBlade before
5
+ it can do anything at all, so importing PyBlade must not need one.
6
+
7
+ A framework is bound by importing its own module, which is the point at which
8
+ it does have to be installed:
9
+
10
+ from pyblade import PyBlade
11
+ from pyblade.flask import render
12
+ from pyblade.starlette import render
13
+
14
+ Django is the exception: it is bound by its template backend rather than by a
15
+ render function, and a project names `pyblade.backends.PyBladeEngine` in its
16
+ TEMPLATES setting.
17
+ """
18
+
19
+ from importlib import import_module
20
+
21
+ from .cli.base import BaseCommand
22
+ from .config import config
23
+ from .engine import contexts, exceptions, loader, template
24
+ from .engine.renderer import PyBlade
25
+
26
+ #: Names that are a module of their own, imported the first time one is asked
27
+ #: for. Every one of them needs something PyBlade itself does not.
28
+ _LAZY_MODULES = {
29
+ "decorators": "pyblade.live.decorators",
30
+ "django": "pyblade.django",
31
+ "fastapi": "pyblade.fastapi",
32
+ "flask": "pyblade.flask",
33
+ "litestar": "pyblade.litestar",
34
+ "quart": "pyblade.quart",
35
+ "sanic": "pyblade.sanic",
36
+ "starlette": "pyblade.starlette",
37
+ }
38
+
39
+ #: Names that live inside a module, imported the same way and for the same reason.
40
+ _LAZY_NAMES = {
41
+ "ComponentMixin": "pyblade.live.mixins",
42
+ "LiveComponent": "pyblade.live.base",
43
+ }
44
+
45
+ __all__ = [
46
+ "BaseCommand",
47
+ "ComponentMixin",
48
+ "LiveComponent",
49
+ "PyBlade",
50
+ "config",
51
+ "contexts",
52
+ "decorators",
53
+ "django",
54
+ "exceptions",
55
+ "fastapi",
56
+ "flask",
57
+ "litestar",
58
+ "loader",
59
+ "quart",
60
+ "sanic",
61
+ "starlette",
62
+ "template",
63
+ ]
64
+
65
+
66
+ def __getattr__(name):
67
+ """Bring in a name that needs a web framework, the first time it is asked for."""
68
+ if name in _LAZY_MODULES:
69
+ value = import_module(_LAZY_MODULES[name])
70
+ elif name in _LAZY_NAMES:
71
+ value = getattr(import_module(_LAZY_NAMES[name]), name)
72
+ else:
73
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
74
+
75
+ # Kept, so the import happens once rather than on every attribute read
76
+ globals()[name] = value
77
+
78
+ return value
79
+
80
+
81
+ def __dir__():
82
+ return sorted(__all__)
@@ -0,0 +1,30 @@
1
+ """How PyBlade plugs into a web framework.
2
+
3
+ `PyBladeEngine` is Django's template backend: the class a Django project names
4
+ in its TEMPLATES setting. It is brought in when it is asked for rather than
5
+ when this package is, because importing PyBlade must not need Django.
6
+
7
+ The other frameworks have no such plugin point -- they are bound by a `render`
8
+ function, in a module of their own beside this one and reachable as
9
+ `pyblade.flask`, `pyblade.starlette` and so on.
10
+ """
11
+
12
+ from importlib import import_module
13
+
14
+ __all__ = ["PyBladeEngine"]
15
+
16
+
17
+ def __getattr__(name):
18
+ if name not in __all__:
19
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
20
+
21
+ value = getattr(import_module("pyblade.backends.django"), name)
22
+
23
+ # Kept, so the import happens once rather than on every attribute read
24
+ globals()[name] = value
25
+
26
+ return value
27
+
28
+
29
+ def __dir__():
30
+ return sorted(__all__)
@@ -0,0 +1,92 @@
1
+ """What every framework binding needs, so each one is only its own part.
2
+
3
+ Binding PyBlade to a web framework comes down to the same three things every
4
+ time: get hold of an engine, render a template by name with the request in its
5
+ context, and hand back whatever that framework calls an HTML response. Only the
6
+ last of those differs between frameworks, so only the last belongs in a
7
+ framework's own module.
8
+
9
+ Nothing here imports a web framework, and neither does importing PyBlade. A
10
+ framework module is imported by whoever uses that framework, and that is the
11
+ only point at which it has to be installed.
12
+ """
13
+
14
+ from weakref import WeakKeyDictionary
15
+
16
+ from pyblade.config import config
17
+ from pyblade.engine.renderer import PyBlade
18
+
19
+ #: The engine an application gets when it has not asked for one of its own.
20
+ _shared: PyBlade | None = None
21
+
22
+ #: An engine per application object, for the frameworks that have one.
23
+ _per_app: "WeakKeyDictionary[object, PyBlade]" = WeakKeyDictionary()
24
+
25
+
26
+ def directories(*named) -> list[str]:
27
+ """Where templates are looked for: what the caller said, or what the project says.
28
+
29
+ A framework usually knows where its own templates are and says so. One that
30
+ does not falls back to the project's own answer, which is `[paths]
31
+ templates` in its pyblade.toml, so that the same setting works whichever
32
+ framework is serving.
33
+ """
34
+ given = [str(directory) for directory in named if directory]
35
+
36
+ return given or [str(config.paths.templates)]
37
+
38
+
39
+ def configure(*named) -> PyBlade:
40
+ """Say where this application's templates are, and build its engine."""
41
+ global _shared
42
+
43
+ _shared = PyBlade(dirs=directories(*named))
44
+
45
+ return _shared
46
+
47
+
48
+ def shared_engine() -> PyBlade:
49
+ """The engine for an application that never said where its templates are."""
50
+ return _shared if _shared is not None else configure()
51
+
52
+
53
+ def engine_for(app, *named) -> PyBlade:
54
+ """The engine belonging to one application object.
55
+
56
+ Flask and Quart can run several applications in one process, each with
57
+ templates of its own, so an engine is kept per application -- weakly, so
58
+ that an application going away takes its engine with it rather than leaving
59
+ it behind in a dictionary nobody empties.
60
+ """
61
+ try:
62
+ made = _per_app.get(app)
63
+ except TypeError:
64
+ # An application that cannot be weakly referenced shares the one engine
65
+ return shared_engine()
66
+
67
+ if made is None:
68
+ made = PyBlade(dirs=directories(*named))
69
+ _per_app[app] = made
70
+
71
+ return made
72
+
73
+
74
+ def render(engine: PyBlade, template_name: str, context: dict, request=None) -> str:
75
+ """A template of this project, rendered, as a string of HTML.
76
+
77
+ `render_file` rather than `render`: the first takes the name of a template
78
+ and loads it, the second takes the template itself. Handed a name, `render`
79
+ would render the name.
80
+ """
81
+ if request is not None:
82
+ context = {**context, "request": request}
83
+
84
+ return engine.render_file(template_name, context)
85
+
86
+
87
+ def reset() -> None:
88
+ """Forget every engine, for tests that build applications and drop them."""
89
+ global _shared
90
+
91
+ _shared = None
92
+ _per_app.clear()
@@ -1,14 +1,25 @@
1
+ from django.template import TemplateDoesNotExist
1
2
  from django.template.backends.base import BaseEngine
2
3
  from django.template.backends.utils import csrf_input_lazy, csrf_token_lazy
3
4
  from django.utils.functional import cached_property
4
5
  from django.utils.module_loading import import_string
5
6
 
6
- from pyblade import PyBlade
7
+ from pyblade.config import config
8
+ from pyblade.engine.exceptions import TemplateNotFoundError
9
+ from pyblade.engine.renderer import PyBlade
10
+ from pyblade.engine.template import Template as PyBladeTemplate
7
11
 
8
12
 
9
- class PyBladeEngine(BaseEngine):
13
+ class TemplateNotFoundHere(TemplateNotFoundError, TemplateDoesNotExist):
14
+ """A template this engine has not got.
15
+
16
+ Both what PyBlade calls it and what Django calls it, so that whichever of
17
+ the two is being caught, it is caught.
18
+ """
10
19
 
11
- app_dirname = "templates"
20
+
21
+ class PyBladeEngine(BaseEngine):
22
+ app_dirname = str(config.written("paths.templates"))
12
23
 
13
24
  def __init__(self, params):
14
25
  params = params.copy()
@@ -26,8 +37,13 @@ class PyBladeEngine(BaseEngine):
26
37
 
27
38
  try:
28
39
  return Template(self.engine.get_template(template_name), self)
29
- except Exception as e:
30
- raise e
40
+ except TemplateNotFoundError as error:
41
+ # Django asks each of its engines in turn, and an engine without
42
+ # the template says so by raising TemplateDoesNotExist. Raised as
43
+ # both, so that a template held by another engine is still reached
44
+ # and Django still shows where it looked, while code catching
45
+ # PyBlade's own exception goes on working.
46
+ raise TemplateNotFoundHere(str(error)) from error
31
47
 
32
48
  @cached_property
33
49
  def template_context_processors(self):
@@ -35,7 +51,7 @@ class PyBladeEngine(BaseEngine):
35
51
 
36
52
 
37
53
  class Template:
38
- def __init__(self, pyblade_template, backend):
54
+ def __init__(self, pyblade_template: PyBladeTemplate, backend: PyBladeEngine):
39
55
  self.pyblade_template = pyblade_template
40
56
  self.pyblade_template.set_backend(backend)
41
57
  self.pyblade_template.set_engine(backend.engine)
@@ -0,0 +1,9 @@
1
+ """PyBlade in a FastAPI application.
2
+
3
+ FastAPI's responses are Starlette's, so this is that binding under the name
4
+ somebody writing FastAPI will look for.
5
+ """
6
+
7
+ from .starlette import configure, render
8
+
9
+ __all__ = ["configure", "render"]
@@ -0,0 +1,23 @@
1
+ """PyBlade in a Flask application."""
2
+
3
+ from flask import Response, current_app
4
+
5
+ from . import base
6
+
7
+ configure = base.configure
8
+
9
+
10
+ def engine():
11
+ """This application's engine, made from the template folder it declares."""
12
+ app = current_app._get_current_object()
13
+
14
+ return base.engine_for(app, app.template_folder)
15
+
16
+
17
+ def render(template_name: str, **context) -> Response:
18
+ """Render one of this application's templates as a response."""
19
+ return Response(base.render(engine(), template_name, context), mimetype="text/html")
20
+
21
+
22
+ #: What Flask developers are already familiar with.
23
+ render_template = render