pyjs 0.0.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.
Files changed (151) hide show
  1. pyjs-0.0.1/LICENSE +28 -0
  2. pyjs-0.0.1/PKG-INFO +441 -0
  3. pyjs-0.0.1/README.md +405 -0
  4. pyjs-0.0.1/pyjs/__init__.py +6 -0
  5. pyjs-0.0.1/pyjs/__main__.py +6 -0
  6. pyjs-0.0.1/pyjs/cli.py +816 -0
  7. pyjs-0.0.1/pyjs/decorators.py +170 -0
  8. pyjs-0.0.1/pyjs/docs/__init__.py +6 -0
  9. pyjs-0.0.1/pyjs/docs/builder.py +351 -0
  10. pyjs-0.0.1/pyjs/docs/cli.py +55 -0
  11. pyjs-0.0.1/pyjs/docs/config.py +45 -0
  12. pyjs-0.0.1/pyjs/docs/favicon.svg +18 -0
  13. pyjs-0.0.1/pyjs/docs/markdown.py +61 -0
  14. pyjs-0.0.1/pyjs/docs/models.py +38 -0
  15. pyjs-0.0.1/pyjs/docs/navigation.py +61 -0
  16. pyjs-0.0.1/pyjs/docs/style.css +901 -0
  17. pyjs-0.0.1/pyjs/docs/ui.py +349 -0
  18. pyjs-0.0.1/pyjs/nativescript/__init__.py +77 -0
  19. pyjs-0.0.1/pyjs/scaffolding/__init__.py +418 -0
  20. pyjs-0.0.1/pyjs/scaffolding/templates/app/README.md.template +33 -0
  21. pyjs-0.0.1/pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__PYJS_PACKAGE__.py.template +81 -0
  22. pyjs-0.0.1/pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__init__.py.template +0 -0
  23. pyjs-0.0.1/pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__main__.py.template +5 -0
  24. pyjs-0.0.1/pyjs/scaffolding/templates/app/tests/test_app.py.template +22 -0
  25. pyjs-0.0.1/pyjs/scaffolding/templates/app/tests/test_browser_app.py.template +19 -0
  26. pyjs-0.0.1/pyjs/scaffolding/templates/app_test.py.template +8 -0
  27. pyjs-0.0.1/pyjs/server.py +468 -0
  28. pyjs-0.0.1/pyjs/skills/pyjs/SKILL.md +161 -0
  29. pyjs-0.0.1/pyjs/state.py +101 -0
  30. pyjs-0.0.1/pyjs/testing/__init__.py +3 -0
  31. pyjs-0.0.1/pyjs/testing/android.py +248 -0
  32. pyjs-0.0.1/pyjs/testing/artifacts.py +37 -0
  33. pyjs-0.0.1/pyjs/testing/assertion_rewriter.py +125 -0
  34. pyjs-0.0.1/pyjs/testing/builder.py +191 -0
  35. pyjs-0.0.1/pyjs/testing/capture.py +133 -0
  36. pyjs-0.0.1/pyjs/testing/client/__init__.py +1 -0
  37. pyjs-0.0.1/pyjs/testing/client/app.py +718 -0
  38. pyjs-0.0.1/pyjs/testing/client/assertions.py +49 -0
  39. pyjs-0.0.1/pyjs/testing/client/runtime.py +123 -0
  40. pyjs-0.0.1/pyjs/testing/client/sidebar.py +377 -0
  41. pyjs-0.0.1/pyjs/testing/client/state.py +107 -0
  42. pyjs-0.0.1/pyjs/testing/client/viewer.py +361 -0
  43. pyjs-0.0.1/pyjs/testing/daemon.py +641 -0
  44. pyjs-0.0.1/pyjs/testing/helpers.py +155 -0
  45. pyjs-0.0.1/pyjs/testing/protocol.py +56 -0
  46. pyjs-0.0.1/pyjs/testing/pytest_plugin.py +797 -0
  47. pyjs-0.0.1/pyjs/testing/web.py +97 -0
  48. pyjs-0.0.1/pyjs/testing/webgpu.py +27 -0
  49. pyjs-0.0.1/pyjs/tooling/__init__.py +4 -0
  50. pyjs-0.0.1/pyjs/tooling/android.py +138 -0
  51. pyjs-0.0.1/pyjs/tooling/browser.py +676 -0
  52. pyjs-0.0.1/pyjs/tooling/command.py +75 -0
  53. pyjs-0.0.1/pyjs/tooling/nativescript.py +156 -0
  54. pyjs-0.0.1/pyjs/tooling/node.py +170 -0
  55. pyjs-0.0.1/pyjs/tooling/perf.py +163 -0
  56. pyjs-0.0.1/pyjs/transpiler/__init__.py +23 -0
  57. pyjs-0.0.1/pyjs/transpiler/_builtins.py +485 -0
  58. pyjs-0.0.1/pyjs/transpiler/analyzer.py +1495 -0
  59. pyjs-0.0.1/pyjs/transpiler/objects.py +1015 -0
  60. pyjs-0.0.1/pyjs/transpiler/source.py +189 -0
  61. pyjs-0.0.1/pyjs/transpiler/transpiler.py +748 -0
  62. pyjs-0.0.1/pyjs/transpiler/utils.py +150 -0
  63. pyjs-0.0.1/pyjs/web/__init__.py +5 -0
  64. pyjs-0.0.1/pyjs/web/console.py +16 -0
  65. pyjs-0.0.1/pyjs/web/dom.py +1529 -0
  66. pyjs-0.0.1/pyjs/web/domx.py +474 -0
  67. pyjs-0.0.1/pyjs/web/dragdrop.py +102 -0
  68. pyjs-0.0.1/pyjs/web/events.py +1306 -0
  69. pyjs-0.0.1/pyjs/web/files.py +203 -0
  70. pyjs-0.0.1/pyjs/web/geometry.py +475 -0
  71. pyjs-0.0.1/pyjs/web/html.py +927 -0
  72. pyjs-0.0.1/pyjs/web/indexeddb.py +410 -0
  73. pyjs-0.0.1/pyjs/web/javascript.py +112 -0
  74. pyjs-0.0.1/pyjs/web/network.py +193 -0
  75. pyjs-0.0.1/pyjs/web/ssr.py +70 -0
  76. pyjs-0.0.1/pyjs/web/streams.py +17 -0
  77. pyjs-0.0.1/pyjs/web/svg.py +684 -0
  78. pyjs-0.0.1/pyjs/web/timers.py +29 -0
  79. pyjs-0.0.1/pyjs/web/ui/__init__.py +18 -0
  80. pyjs-0.0.1/pyjs/web/ui/accordion.py +166 -0
  81. pyjs-0.0.1/pyjs/web/ui/alert.py +52 -0
  82. pyjs-0.0.1/pyjs/web/ui/alert_dialog.py +102 -0
  83. pyjs-0.0.1/pyjs/web/ui/aspect_ratio.py +12 -0
  84. pyjs-0.0.1/pyjs/web/ui/attachment.py +80 -0
  85. pyjs-0.0.1/pyjs/web/ui/avatar.py +105 -0
  86. pyjs-0.0.1/pyjs/web/ui/badge.py +48 -0
  87. pyjs-0.0.1/pyjs/web/ui/breadcrumb.py +85 -0
  88. pyjs-0.0.1/pyjs/web/ui/bubble.py +38 -0
  89. pyjs-0.0.1/pyjs/web/ui/button.py +86 -0
  90. pyjs-0.0.1/pyjs/web/ui/calendar.py +124 -0
  91. pyjs-0.0.1/pyjs/web/ui/card.py +58 -0
  92. pyjs-0.0.1/pyjs/web/ui/carousel.py +99 -0
  93. pyjs-0.0.1/pyjs/web/ui/chart.py +56 -0
  94. pyjs-0.0.1/pyjs/web/ui/checkbox.py +31 -0
  95. pyjs-0.0.1/pyjs/web/ui/collapsible.py +71 -0
  96. pyjs-0.0.1/pyjs/web/ui/combobox.py +36 -0
  97. pyjs-0.0.1/pyjs/web/ui/command.py +118 -0
  98. pyjs-0.0.1/pyjs/web/ui/context_menu.py +65 -0
  99. pyjs-0.0.1/pyjs/web/ui/date_picker.py +24 -0
  100. pyjs-0.0.1/pyjs/web/ui/dialog.py +289 -0
  101. pyjs-0.0.1/pyjs/web/ui/direction.py +9 -0
  102. pyjs-0.0.1/pyjs/web/ui/drawer.py +72 -0
  103. pyjs-0.0.1/pyjs/web/ui/dropdown_menu.py +239 -0
  104. pyjs-0.0.1/pyjs/web/ui/empty.py +69 -0
  105. pyjs-0.0.1/pyjs/web/ui/field.py +96 -0
  106. pyjs-0.0.1/pyjs/web/ui/floating.py +90 -0
  107. pyjs-0.0.1/pyjs/web/ui/hover_card.py +128 -0
  108. pyjs-0.0.1/pyjs/web/ui/input.py +48 -0
  109. pyjs-0.0.1/pyjs/web/ui/input_group.py +77 -0
  110. pyjs-0.0.1/pyjs/web/ui/input_otp.py +76 -0
  111. pyjs-0.0.1/pyjs/web/ui/item.py +78 -0
  112. pyjs-0.0.1/pyjs/web/ui/kbd.py +26 -0
  113. pyjs-0.0.1/pyjs/web/ui/label.py +14 -0
  114. pyjs-0.0.1/pyjs/web/ui/marker.py +29 -0
  115. pyjs-0.0.1/pyjs/web/ui/menubar.py +52 -0
  116. pyjs-0.0.1/pyjs/web/ui/message.py +57 -0
  117. pyjs-0.0.1/pyjs/web/ui/message_scroller.py +45 -0
  118. pyjs-0.0.1/pyjs/web/ui/native_select.py +47 -0
  119. pyjs-0.0.1/pyjs/web/ui/navigation_menu.py +110 -0
  120. pyjs-0.0.1/pyjs/web/ui/pagination.py +63 -0
  121. pyjs-0.0.1/pyjs/web/ui/popover.py +217 -0
  122. pyjs-0.0.1/pyjs/web/ui/progress.py +44 -0
  123. pyjs-0.0.1/pyjs/web/ui/radio_group.py +129 -0
  124. pyjs-0.0.1/pyjs/web/ui/resizable.py +194 -0
  125. pyjs-0.0.1/pyjs/web/ui/scroll_area.py +29 -0
  126. pyjs-0.0.1/pyjs/web/ui/select.py +83 -0
  127. pyjs-0.0.1/pyjs/web/ui/separator.py +24 -0
  128. pyjs-0.0.1/pyjs/web/ui/sheet.py +77 -0
  129. pyjs-0.0.1/pyjs/web/ui/sidebar.py +162 -0
  130. pyjs-0.0.1/pyjs/web/ui/skeleton.py +15 -0
  131. pyjs-0.0.1/pyjs/web/ui/slider.py +46 -0
  132. pyjs-0.0.1/pyjs/web/ui/sonner.py +70 -0
  133. pyjs-0.0.1/pyjs/web/ui/spinner.py +14 -0
  134. pyjs-0.0.1/pyjs/web/ui/switch.py +35 -0
  135. pyjs-0.0.1/pyjs/web/ui/table.py +84 -0
  136. pyjs-0.0.1/pyjs/web/ui/tabs.py +167 -0
  137. pyjs-0.0.1/pyjs/web/ui/text.py +15 -0
  138. pyjs-0.0.1/pyjs/web/ui/textarea.py +28 -0
  139. pyjs-0.0.1/pyjs/web/ui/toggle.py +109 -0
  140. pyjs-0.0.1/pyjs/web/ui/tooltip.py +164 -0
  141. pyjs-0.0.1/pyjs/web/ui/typography.py +79 -0
  142. pyjs-0.0.1/pyjs/web/url.py +76 -0
  143. pyjs-0.0.1/pyjs/web/webgpu.py +496 -0
  144. pyjs-0.0.1/pyjs.egg-info/PKG-INFO +441 -0
  145. pyjs-0.0.1/pyjs.egg-info/SOURCES.txt +149 -0
  146. pyjs-0.0.1/pyjs.egg-info/dependency_links.txt +1 -0
  147. pyjs-0.0.1/pyjs.egg-info/entry_points.txt +5 -0
  148. pyjs-0.0.1/pyjs.egg-info/requires.txt +8 -0
  149. pyjs-0.0.1/pyjs.egg-info/top_level.txt +1 -0
  150. pyjs-0.0.1/pyproject.toml +81 -0
  151. pyjs-0.0.1/setup.cfg +4 -0
pyjs-0.0.1/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025, Lex Berezhny
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.
pyjs-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,441 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyjs
3
+ Version: 0.0.1
4
+ Summary: Python to JavaScript transpiler.
5
+ Author-email: Lex Berezhny <lex@damoti.com>
6
+ License: BSD-3-Clause
7
+ Project-URL: Homepage, https://pyjs.org
8
+ Project-URL: Documentation, https://pyjs.org/docs/
9
+ Project-URL: Release notes, https://github.com/pyjs/pyjs/releases
10
+ Project-URL: Source, https://github.com/pyjs/pyjs
11
+ Project-URL: Tracker, https://github.com/pyjs/pyjs/issues
12
+ Classifier: Development Status :: 2 - Pre-Alpha
13
+ Classifier: Environment :: Web Environment
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: BSD License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Internet :: WWW/HTTP
22
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
23
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Requires-Python: >=3.14
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: markdown>=3.8
29
+ Requires-Dist: pillow
30
+ Requires-Dist: pyyaml>=6.0
31
+ Requires-Dist: pytest
32
+ Requires-Dist: websockets
33
+ Provides-Extra: examples
34
+ Requires-Dist: pyjs-examples==0.0.1; extra == "examples"
35
+ Dynamic: license-file
36
+
37
+ # PyJS: Python to JavaScript
38
+
39
+ > Pre-alpha: useful applications and tests work today, but APIs may change before the first
40
+ > release.
41
+
42
+ PyJS is a statically analyzed Python-to-JavaScript compiler. It turns reachable, typed Python code
43
+ into readable, tree-shaken JavaScript without shipping a Python runtime. Its current libraries make
44
+ it especially useful for server-rendered web applications and browser-native custom elements:
45
+ application code can render on the server, hydrate as native custom elements, and continue running
46
+ in the browser. Public APIs and values whose types cannot be inferred need type annotations.
47
+
48
+ Coding agents can run `pyjs skill` for version-matched instructions, then use `pyjs template` and
49
+ `pyjs template NAME` to discover installed examples and inspect their complete source. The
50
+ [installable PyJS skill](https://github.com/pyjs/pyjs/tree/main/pyjs/skills/pyjs) is also available
51
+ directly from the public repository.
52
+
53
+ ## Goals
54
+
55
+ - No Python runtime in generated JavaScript
56
+ - Readable, performant JavaScript comparable to handwritten output
57
+ - Server rendering and browser behavior expressed with the same typed Python objects
58
+ - Browser-native custom elements as the application framework
59
+ - Enough well-defined Python semantics to build productive applications
60
+
61
+ ## Non-goals
62
+
63
+ - Reimplement every Python feature or the complete standard library in JavaScript
64
+ - Preserve highly dynamic behavior such as runtime monkey-patching, `eval()`, or arbitrary imports
65
+ - Infer types when the source contains no usable type information
66
+ - Replace a production web server or a general-purpose Python test runner
67
+
68
+ ## Getting started
69
+
70
+ Install PyJS and create a project:
71
+
72
+ ```bash
73
+ python -m pip install pyjs
74
+ pyjs create hello_pyjs
75
+ cd hello_pyjs
76
+ python -m pip install -e ".[test]"
77
+ python -m hello_pyjs
78
+ ```
79
+
80
+ Open <http://127.0.0.1:8000/>. The generated project has no Node.js configuration or JavaScript
81
+ source: it contains a custom element, server entry point, Python tests, and a browser test.
82
+
83
+ Run its test suite on either target:
84
+
85
+ ```bash
86
+ python -m pytest -q
87
+ python -m pytest -q --pyjs-target=web
88
+ ```
89
+
90
+ To work on PyJS from a source checkout:
91
+
92
+ ```bash
93
+ python -m pip install -e .
94
+ ```
95
+
96
+ Install the separate examples distribution when working on the examples:
97
+
98
+ ```bash
99
+ python -m pip install -e examples
100
+ ```
101
+
102
+ ## Start from an example
103
+
104
+ PyJS distinguishes complete applications from small, focused samples:
105
+
106
+ ```bash
107
+ python -m pip install "pyjs[examples]"
108
+ python -m pyjs_examples.calculator
109
+ pyjs template
110
+ pyjs template pyjs_examples.calculator
111
+ pyjs template pyjs_examples.calculator --src
112
+ pyjs create my_calculator --template pyjs_examples.calculator
113
+ pyjs create counter_demo --template pyjs_examples.counter
114
+ pyjs create my_counter --single-file --template pyjs_examples.counter
115
+ pyjs create state_counter_demo --template pyjs_examples.samples.state_counter
116
+ pyjs create dialog_demo --template pyjs_examples.samples.ui_dialog
117
+ ```
118
+
119
+ `pyjs create NAME` creates a project in `NAME/`, with application code in
120
+ `NAME/NAME/NAME.py` and tests in `NAME/tests/`. Pass a destination as the second positional argument
121
+ to populate another directory, such as `pyjs create routine .`. Add `--src-layout` to put the
122
+ package under `src/`. After installation, `python -m NAME` starts either package layout.
123
+ `--single-file` explicitly requests one standalone Python file and requires a file template when
124
+ combined with `--template`. The `pyjs-examples` distribution registers both file and directory
125
+ templates and contains the source copied by `pyjs create`; templates are not embedded in the
126
+ scaffolding implementation.
127
+
128
+ ## Run or inspect Python as JavaScript
129
+
130
+ For Node-compatible code, PyJS can compile and run a file, module, or command string directly with
131
+ its managed Node runtime:
132
+
133
+ ```bash
134
+ pyjs app.py
135
+ pyjs -m package.module
136
+ pyjs -c 'print(6 * 7)'
137
+ pyjs -v -c 'print(6 * 7)' # generated JavaScript followed by Node output
138
+ pyjs --src app.py # generated source only
139
+ pyjs --src-all app.py # entry source and tree-shaken dependencies
140
+ pyjs --perf -c 'print(sum(range(10)))'
141
+ ```
142
+
143
+ Use `--json` for structured results or `--perf` to compare Python and generated-JavaScript timing.
144
+ DOM, WebGPU, and other browser APIs still run through an application or browser test.
145
+
146
+ ## Build an entry point
147
+
148
+ The application server builds and serves browser assets automatically. To write the generated
149
+ JavaScript, CSS, and HTML explicitly:
150
+
151
+ ```bash
152
+ pyjs build hello_pyjs.hello_pyjs:main
153
+ ```
154
+
155
+ Use `--only-js` when only the browser bundle is needed.
156
+
157
+ ## Application model
158
+
159
+ An application entry point returns a server-rendered DOM tree. Classes decorated with `@js` are
160
+ available to the browser compiler, and reachable methods are included in the generated bundle.
161
+ `CustomElement` subclasses render on the server and hydrate as browser-native custom elements.
162
+ `ref()` reconnects Python attributes to existing server-rendered nodes rather than recreating them.
163
+
164
+ Values that must survive rendering and hydration can live on the custom element as DOM attributes.
165
+ The `state()` descriptor and `@effect(...)` provide a small typed reactive layer for updating the
166
+ DOM imperatively. Server-only handlers and browser methods can coexist in the same module.
167
+
168
+ ## Feature overview
169
+
170
+ ### Tree shaking
171
+
172
+ PyJS starts at the selected entry point and includes reachable browser code. In this example,
173
+ `sleep()` and `run()` are reachable; `eat()` and `bark()` are omitted:
174
+
175
+ ```python
176
+ from pyjs import js
177
+
178
+
179
+ @js
180
+ class Animal:
181
+ def sleep(self):
182
+ pass
183
+
184
+ def eat(self):
185
+ pass
186
+
187
+
188
+ @js
189
+ class Dog(Animal):
190
+ def run(self):
191
+ pass
192
+
193
+ def bark(self):
194
+ pass
195
+
196
+
197
+ def main():
198
+ dog = Dog()
199
+ dog.sleep()
200
+ dog.run()
201
+ ```
202
+
203
+ Ordinary event handlers and called methods do not need `include=True`. That option remains an
204
+ escape hatch for unusual methods invoked dynamically by JavaScript.
205
+
206
+ ### Type inference and checking
207
+
208
+ The analyzer infers types from literals, constructors, calls, and control flow. Empty collections
209
+ and public boundaries generally need annotations because their element or return type cannot be
210
+ recovered from a value:
211
+
212
+ ```python
213
+ from pyjs import js
214
+
215
+
216
+ @js
217
+ class Animal:
218
+ def __init__(self, name: str):
219
+ self.name = name
220
+
221
+ def get_name(self) -> str:
222
+ return self.name
223
+
224
+
225
+ def main():
226
+ values = {"one": 1, "two": 2}
227
+ animal = Animal("Hazel")
228
+ print(values["one"])
229
+ print(animal.get_name())
230
+ ```
231
+
232
+ Type errors are reported during analysis instead of being deferred to generated JavaScript.
233
+ Diagnostics are improving and do not yet cover every invalid program equally well.
234
+
235
+ ### Type narrowing
236
+
237
+ Union types narrow through `isinstance()`, branches, assertions, and null checks:
238
+
239
+ ```python
240
+ from pyjs import js
241
+
242
+
243
+ @js
244
+ def length(items: dict[str, int] | list[int] | str) -> int:
245
+ if isinstance(items, dict):
246
+ return len(items)
247
+ if isinstance(items, list):
248
+ return len(items)
249
+ assert isinstance(items, str)
250
+ return len(items)
251
+
252
+
253
+ def main():
254
+ length(["one"])
255
+ length({"one": 1, "two": 2})
256
+ length("four")
257
+ ```
258
+
259
+ `is None` and `is not None` compile to nullish JavaScript comparisons, covering both JavaScript
260
+ `null` and `undefined`, while identity comparisons between ordinary objects retain identity
261
+ semantics.
262
+
263
+ ### Operator overloading
264
+
265
+ Built-in operators use their normal JavaScript equivalents for compatible primitive values and
266
+ dispatch to Python special methods for user-defined classes:
267
+
268
+ ```python
269
+ from pyjs import js
270
+
271
+
272
+ @js
273
+ class ListAdder:
274
+ def __init__(self):
275
+ self.values: list[str] = []
276
+
277
+ def __add__(self, other: str):
278
+ self.values.append(other)
279
+ return self
280
+
281
+ def __str__(self) -> str:
282
+ return "|".join(self.values)
283
+
284
+
285
+ def main():
286
+ values = ListAdder()
287
+ values += "a"
288
+ values += "b"
289
+ print(values)
290
+ ```
291
+
292
+ ### Generic types
293
+
294
+ The analyzer preserves concrete element and key/value types for built-in collections such as
295
+ `list[T]`, `dict[K, V]`, and `tuple[...]`. User-defined generic specialization exists in the
296
+ analyzer but remains experimental and is not yet a stable application-facing feature.
297
+
298
+ ### Async code and exceptions
299
+
300
+ Async functions and `await` lower to JavaScript promises. Typed browser APIs such as `fetch()`,
301
+ WebSockets, and WebGPU use the same syntax as asynchronous Python code. Basic raising and exception
302
+ handling are supported, but exception semantics are not yet a complete match for CPython.
303
+
304
+ ### Metaprogramming and compiler extensions
305
+
306
+ Module and class bodies execute in Python before analysis, so ordinary Python metaprogramming can
307
+ construct the definitions that PyJS later analyzes. The `@js` decorator also supports client
308
+ replacements and inline call generation for typed browser API bindings. Compilation extensions can
309
+ rewrite function ASTs and inject imports before analysis; the browser-testing integration uses this
310
+ mechanism for assertion diagnostics.
311
+
312
+ These are advanced integration tools. Application code should normally use typed Python and the
313
+ APIs already provided by `pyjs.web.dom`, `pyjs.web.domx`, and `pyjs.web.ui`.
314
+
315
+ ## Web UI and state
316
+
317
+ `pyjs.web.ui` contains reusable custom-element components inspired by shadcn/ui and adapted for
318
+ normal Python imports, subclassing, and imperative DOM composition. The catalog includes forms,
319
+ dialogs, menus, popovers, tabs, accordions, data display, navigation, charts, and layout primitives.
320
+
321
+ ```python
322
+ from pyjs.web.ui.button import Button
323
+ from pyjs.web.ui.card import Card, CardContent, CardFooter, CardHeader, CardTitle
324
+
325
+ profile = Card(
326
+ CardHeader(CardTitle("Profile")),
327
+ CardContent("Update your public details."),
328
+ CardFooter(Button("Save changes")),
329
+ )
330
+ ```
331
+
332
+ Reactive state is backed by custom-element attributes:
333
+
334
+ ```python
335
+ from pyjs import effect, js, state
336
+ from pyjs.web.domx import CustomElement, ref, tag
337
+
338
+
339
+ @js
340
+ class Counter(CustomElement):
341
+ count = state(0)
342
+
343
+ def __init__(self):
344
+ super().__init__()
345
+ self.value = ref(tag("output"))
346
+ tag(self, self.value)
347
+
348
+ @effect(count)
349
+ def render_count(self):
350
+ self.value.textContent = str(self.count)
351
+ ```
352
+
353
+ Effects run during server rendering. Hydration reuses that rendered result rather than repeating
354
+ the initial effect in the browser.
355
+
356
+ ## Testing
357
+
358
+ PyJS registers a pytest plugin that can run portable tests in Python or compile them for isolated
359
+ browser iframes:
360
+
361
+ ```bash
362
+ python -m pytest -q
363
+ python -m pytest -q --pyjs-target=web
364
+ ```
365
+
366
+ Use `pytest.mark.pyjs_web` for tests requiring native browser behavior and
367
+ `pytest.mark.pyjs_python` for tests that cannot be compiled. A filename such as
368
+ `test_browser_dialog.py` is only an organizational convention and has no implicit behavior.
369
+
370
+ Browser tests retain console output and errors. Tests that render meaningful UI retain their iframe
371
+ preview, and render assertions can compare screenshots against checked-in PNG baselines.
372
+
373
+ ## Commands
374
+
375
+ | Command | Purpose |
376
+ | --- | --- |
377
+ | `pyjs --version` | Show the installed version |
378
+ | `pyjs FILE.py`, `pyjs -m MODULE`, `pyjs -c CODE` | Compile and run with managed Node |
379
+ | `pyjs --src INPUT` | Print generated JavaScript without running it |
380
+ | `pyjs --src-all INPUT` | Include all tree-shaken dependency sources |
381
+ | `pyjs --perf INPUT` | Compare Python and generated-JavaScript performance |
382
+ | `pyjs create NAME [DESTINATION]` | Create a starter project |
383
+ | `pyjs template` | List templates registered by installed packages |
384
+ | `pyjs template NAME` | Print the complete materialized template source |
385
+ | `pyjs template NAME --src` | Print the transpiled entry-module JavaScript |
386
+ | `pyjs build MODULE[:ENTRY]` | Write generated JavaScript, CSS, and HTML |
387
+ | `pyjs docs build` | Build a static documentation site |
388
+ | `pyjs docs serve` | Build and serve documentation locally |
389
+ | `pyjs skill` | Print version-matched instructions for coding agents |
390
+
391
+ The built-in application server is run from Python source with `serve(__file__)`; the generated
392
+ starter and examples already provide this entry point.
393
+
394
+ ## Current limitations and missing features
395
+
396
+ PyJS is intentionally a typed subset of Python, and the first release remains pre-alpha:
397
+
398
+ - Multiple inheritance is not supported.
399
+ - Reflection, runtime monkey-patching, `eval()`, and arbitrary dynamic imports are outside the
400
+ compilation model.
401
+ - Python standard-library and browser API coverage is incomplete; APIs are added as typed PyJS
402
+ definitions.
403
+ - User-defined generic class specialization still has unsupported shapes and needs dedicated
404
+ regression coverage before it is considered stable.
405
+ - Some invalid programs still produce low-level analyzer errors instead of concise diagnostics with
406
+ precise source locations.
407
+ - Source maps from generated JavaScript back to Python are not implemented yet.
408
+ - The development server rebuilds when it starts, but browser hot reload is not implemented.
409
+ - Browser-target pytest fixtures and helpers are a subset of normal pytest; compatibility work such
410
+ as browser-side `pytest.raises` remains planned.
411
+ - Tree shaking still has an `include=True` escape hatch for unusual methods reached only through
412
+ opaque JavaScript dispatch.
413
+ - Reactive effects run immediately for each attribute mutation; updates are not currently batched.
414
+ - The bundled HTTP server and documentation server are development tools, not production servers.
415
+ - NativeScript output is experimental; the first proof of concept currently targets Android and
416
+ covers a small set of core views.
417
+
418
+ See [TESTING.md](TESTING.md) and [TREE_SHAKING.md](TREE_SHAKING.md) for focused implementation
419
+ status. The broader guides and references live in [docs/](docs/).
420
+
421
+ ## Development from a checkout
422
+
423
+ PyJS currently requires Python 3.14:
424
+
425
+ ```bash
426
+ python -m pip install -e .
427
+ python -m pytest -q
428
+ ```
429
+
430
+ The examples are a separate distribution:
431
+
432
+ ```bash
433
+ python -m pip install -e examples
434
+ cd examples
435
+ python -m pytest -q
436
+ ```
437
+
438
+ Run Ruff against changed Python files before submitting changes. Generated `.main.js`, `.main.css`,
439
+ and `.main.html` files are build artifacts rather than hand-authored source.
440
+
441
+ PyJS is distributed under the [BSD 3-Clause License](LICENSE).