pyreaction 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.
- pyreaction-0.1.0.dist-info/METADATA +346 -0
- pyreaction-0.1.0.dist-info/RECORD +38 -0
- pyreaction-0.1.0.dist-info/WHEEL +4 -0
- pyreaction-0.1.0.dist-info/entry_points.txt +4 -0
- pyreaction-0.1.0.dist-info/licenses/LICENSE +21 -0
- reaction/__init__.py +220 -0
- reaction/cli/__init__.py +80 -0
- reaction/cli/__main__.py +3 -0
- reaction/cli/scaffold.py +121 -0
- reaction/cli/serve.py +123 -0
- reaction/cli/templates/default/README.md.tmpl +14 -0
- reaction/cli/templates/default/_gitignore +4 -0
- reaction/cli/templates/default/app.py +12 -0
- reaction/cli/templates/default/components/__init__.py +0 -0
- reaction/cli/templates/default/components/counter.py +12 -0
- reaction/cli/templates/default/public/style.css +26 -0
- reaction/cli/templates/default/pyproject.toml.tmpl +29 -0
- reaction/client/client.js +1087 -0
- reaction/client/index.html +15 -0
- reaction/client/style.css +54 -0
- reaction/core/__init__.py +0 -0
- reaction/core/_html_types.py +3768 -0
- reaction/core/boundary.py +46 -0
- reaction/core/components.py +322 -0
- reaction/core/element.py +880 -0
- reaction/core/hooks.py +989 -0
- reaction/core/parse.py +112 -0
- reaction/core/resources.py +96 -0
- reaction/core/router.py +76 -0
- reaction/core/ssr.py +372 -0
- reaction/core/store.py +336 -0
- reaction/core/vdom.py +2558 -0
- reaction/py.typed +0 -0
- reaction/server/__init__.py +3 -0
- reaction/server/app.py +1435 -0
- reaction/server/encoding.py +85 -0
- reaction/server/settings.py +76 -0
- reaction/testing.py +586 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyreaction
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: React-style UI components in pure Python, rendered on the server and patched into the browser over a WebSocket.
|
|
5
|
+
Keywords: react,ui,components,hooks,asgi,websocket
|
|
6
|
+
Author: jeomon
|
|
7
|
+
Author-email: jeomon <jeogeoalukka@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
14
|
+
Classifier: Topic :: Software Development :: User Interfaces
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Framework :: AsyncIO
|
|
22
|
+
Requires-Dist: starlette>=0.37
|
|
23
|
+
Requires-Dist: uvicorn>=0.30
|
|
24
|
+
Requires-Dist: websockets>=12
|
|
25
|
+
Requires-Dist: orjson>=3.9
|
|
26
|
+
Requires-Dist: playwright>=1.50 ; extra == 'browser'
|
|
27
|
+
Requires-Dist: jinja2>=3.1 ; extra == 'jinja'
|
|
28
|
+
Requires-Dist: redis>=5 ; extra == 'redis'
|
|
29
|
+
Requires-Dist: a2wsgi>=1.10 ; extra == 'wsgi'
|
|
30
|
+
Requires-Python: >=3.11
|
|
31
|
+
Project-URL: Homepage, https://github.com/Jeomon/pyreaction
|
|
32
|
+
Project-URL: Documentation, https://github.com/Jeomon/pyreaction/tree/main/docs
|
|
33
|
+
Project-URL: Repository, https://github.com/Jeomon/pyreaction
|
|
34
|
+
Project-URL: Issues, https://github.com/Jeomon/pyreaction/issues
|
|
35
|
+
Project-URL: Changelog, https://github.com/Jeomon/pyreaction/blob/main/CHANGELOG.md
|
|
36
|
+
Provides-Extra: browser
|
|
37
|
+
Provides-Extra: jinja
|
|
38
|
+
Provides-Extra: redis
|
|
39
|
+
Provides-Extra: wsgi
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
<div align="center">
|
|
43
|
+
<h1>⚛️ pyreaction</h1>
|
|
44
|
+
|
|
45
|
+
<img src="https://img.shields.io/badge/license-MIT-green" alt="License: MIT">
|
|
46
|
+
<img src="https://img.shields.io/badge/python-3.11%2B-blue" alt="Python 3.11+">
|
|
47
|
+
<img src="https://img.shields.io/badge/typing-mypy%20checked-informational" alt="Typed with mypy">
|
|
48
|
+
<img src="https://img.shields.io/badge/status-pre--release%200.1-orange" alt="Status: pre-release 0.1">
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
**pyreaction** brings React's component model to Python. Components run on the
|
|
52
|
+
server; the browser gets server-rendered HTML for the first paint, then small DOM
|
|
53
|
+
updates over a WebSocket. No JavaScript to write, no build step, no Node.
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from reaction import component, html, run, use_state
|
|
57
|
+
|
|
58
|
+
@component
|
|
59
|
+
def Counter():
|
|
60
|
+
count, set_count = use_state(0)
|
|
61
|
+
return html.button(f"Clicked {count} times", on_click=lambda: set_count(count + 1))
|
|
62
|
+
|
|
63
|
+
run(Counter) # http://127.0.0.1:8000
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The package is `pyreaction`, the import is `reaction`, and the command is
|
|
67
|
+
`reaction` (`pyreaction` works too).
|
|
68
|
+
|
|
69
|
+
## ✨ Key Features
|
|
70
|
+
|
|
71
|
+
- **The React model in Python**
|
|
72
|
+
Components, `use_state`, `use_effect`, context, keys, error boundaries, Suspense,
|
|
73
|
+
portals, refs, the rules of hooks, `StrictMode`, and React 19's form actions,
|
|
74
|
+
`use_optimistic` and `ViewTransition`.
|
|
75
|
+
|
|
76
|
+
- **Server-rendered first**
|
|
77
|
+
Every URL returns real HTML with its data in it, good for search engines and slow
|
|
78
|
+
devices. Suspense content streams into the same response, and the live page
|
|
79
|
+
adopts the HTML instead of redrawing it.
|
|
80
|
+
|
|
81
|
+
- **Small updates**
|
|
82
|
+
The server diffs the tree and sends only DOM operations, such as "set the text of
|
|
83
|
+
node 12". A click on a small page is a round trip of about a third of a
|
|
84
|
+
millisecond on the server.
|
|
85
|
+
|
|
86
|
+
- **Resilient connections**
|
|
87
|
+
Pages reconnect by themselves and resume with their state, and typing is never
|
|
88
|
+
undone by a slow round trip.
|
|
89
|
+
|
|
90
|
+
- **Large pages stay fast**
|
|
91
|
+
`VirtualList` renders only the rows in view, and per-page stores with selectors
|
|
92
|
+
re-render only the components whose part changed.
|
|
93
|
+
|
|
94
|
+
- **Fits your stack**
|
|
95
|
+
Run it alone, mount it in FastAPI (with `Depends`), put it in front of Django or
|
|
96
|
+
Flask, or drop components into Jinja templates.
|
|
97
|
+
|
|
98
|
+
- **Escape hatches**
|
|
99
|
+
Wrap any JavaScript or React widget, run code in the browser with `js()`, call
|
|
100
|
+
element methods from Python, and read any event property on demand.
|
|
101
|
+
|
|
102
|
+
- **Testable and typed**
|
|
103
|
+
A fake browser for unit tests, a live server helper for Playwright, and typed
|
|
104
|
+
HTML tags that editors autocomplete.
|
|
105
|
+
|
|
106
|
+
## 🛠️ Installation
|
|
107
|
+
|
|
108
|
+
### Prerequisites
|
|
109
|
+
|
|
110
|
+
- Python 3.11 or newer
|
|
111
|
+
- [uv](https://docs.astral.sh/uv/) (recommended) or pip
|
|
112
|
+
|
|
113
|
+
```shell
|
|
114
|
+
uv add pyreaction
|
|
115
|
+
# or
|
|
116
|
+
pip install pyreaction
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Optional extras are added the same way, as in `pyreaction[redis,jinja]`:
|
|
120
|
+
|
|
121
|
+
| Extra | For |
|
|
122
|
+
| --- | --- |
|
|
123
|
+
| `redis` | stores shared between worker processes (`RedisBackend`) |
|
|
124
|
+
| `wsgi` | putting pages in front of a WSGI app such as Flask |
|
|
125
|
+
| `jinja` | the `{% component %}` template tag |
|
|
126
|
+
| `browser` | Playwright, for tests in a real browser |
|
|
127
|
+
|
|
128
|
+
### Start a project
|
|
129
|
+
|
|
130
|
+
```shell
|
|
131
|
+
uvx pyreaction init my-app
|
|
132
|
+
cd my-app
|
|
133
|
+
uv run dev # http://127.0.0.1:8000, restarts on every save
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
my-app/
|
|
138
|
+
pyproject.toml settings under [tool.pyreaction]
|
|
139
|
+
app.py the App component
|
|
140
|
+
components/ your components
|
|
141
|
+
public/ served at /static; style.css is linked from the page
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Use it with your framework
|
|
145
|
+
|
|
146
|
+
<details>
|
|
147
|
+
<summary>FastAPI</summary>
|
|
148
|
+
|
|
149
|
+
Serve the pages next to your API with `mount`, or turn a route into a page with
|
|
150
|
+
`page`, whose function can use `Depends`:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
from fastapi import Depends, FastAPI
|
|
154
|
+
from reaction import mount, page
|
|
155
|
+
|
|
156
|
+
api = FastAPI()
|
|
157
|
+
mount(api, App, "/ui") # a whole app under /ui
|
|
158
|
+
|
|
159
|
+
@page(api, "/orders/{order_id}", title="Order")
|
|
160
|
+
def order(order_id: int, user=Depends(current_user)):
|
|
161
|
+
return OrderPage(order_id=order_id, user=user)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Run it as usual with `uvicorn main:api`. See [Integrations](https://github.com/Jeomon/pyreaction/blob/main/docs/integrations.md#fastapi).
|
|
165
|
+
</details>
|
|
166
|
+
|
|
167
|
+
<details>
|
|
168
|
+
<summary>Django</summary>
|
|
169
|
+
|
|
170
|
+
Put the pages in front of Django's ASGI app, in `asgi.py`:
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from django.core.asgi import get_asgi_application
|
|
174
|
+
from reaction import wrap
|
|
175
|
+
|
|
176
|
+
application = wrap(get_asgi_application(), Dashboard, "/dashboard")
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Run it with `uvicorn mysite.asgi:application`. See [Integrations](https://github.com/Jeomon/pyreaction/blob/main/docs/integrations.md#django-flask-and-other-frameworks).
|
|
180
|
+
</details>
|
|
181
|
+
|
|
182
|
+
<details>
|
|
183
|
+
<summary>Flask</summary>
|
|
184
|
+
|
|
185
|
+
Install the `wsgi` extra, then wrap the Flask app:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from reaction import wrap
|
|
189
|
+
|
|
190
|
+
app = wrap(flask_app, Dashboard, "/dashboard")
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Run it with `uvicorn main:app`. See [Integrations](https://github.com/Jeomon/pyreaction/blob/main/docs/integrations.md#django-flask-and-other-frameworks).
|
|
194
|
+
</details>
|
|
195
|
+
|
|
196
|
+
<details>
|
|
197
|
+
<summary>Jinja templates</summary>
|
|
198
|
+
|
|
199
|
+
Install the `jinja` extra, then add a `{% component %}` tag to your templates:
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from reaction import jinja_components
|
|
203
|
+
|
|
204
|
+
api.mount("/components", jinja_components(templates.env, [Counter, Chart], secret=SECRET))
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
```jinja
|
|
208
|
+
{% component "myapp.widgets.Counter" %}
|
|
209
|
+
{% component "myapp.widgets.Chart", values=[1, 2, 3] %}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
See [Integrations](https://github.com/Jeomon/pyreaction/blob/main/docs/integrations.md#jinja-templates).
|
|
213
|
+
</details>
|
|
214
|
+
|
|
215
|
+
## 🖥️ Running pyreaction
|
|
216
|
+
|
|
217
|
+
| Command | |
|
|
218
|
+
| --- | --- |
|
|
219
|
+
| `python app.py` | a single file that calls `run(App)` |
|
|
220
|
+
| `uv run dev` | a project, with reload on save and errors shown in the page |
|
|
221
|
+
| `uv run pro` | a project, for production |
|
|
222
|
+
| `uvicorn main:app` | any app built with `create_app`, `mount` or `wrap` |
|
|
223
|
+
|
|
224
|
+
`reaction run` and `reaction dev` take `--host` and `--port`, which default to
|
|
225
|
+
`PYREACTION_HOST`/`127.0.0.1` and `PYREACTION_PORT`/`PORT`/`8000`. Behind a proxy,
|
|
226
|
+
pass the WebSocket upgrade through; [Deployment](https://github.com/Jeomon/pyreaction/blob/main/docs/deployment.md) has an Nginx
|
|
227
|
+
example and notes on workers and sticky sessions.
|
|
228
|
+
|
|
229
|
+
## ⚙️ Configuration
|
|
230
|
+
|
|
231
|
+
Options go to `create_app` (and `run`, `mount`, `page`, `wrap`), into a project's
|
|
232
|
+
`[tool.pyreaction]` table, or into `PYREACTION_*` environment variables. The ones
|
|
233
|
+
most often changed:
|
|
234
|
+
|
|
235
|
+
| Option | Default | Environment variable | |
|
|
236
|
+
| --- | --- | --- | --- |
|
|
237
|
+
| `debug` | `False` | `PYREACTION_DEBUG` | errors and warnings shown in the page |
|
|
238
|
+
| `allowed_origins` | `()` | `PYREACTION_ALLOWED_ORIGINS` | extra origins allowed to open the WebSocket |
|
|
239
|
+
| `compress` | `True` | `PYREACTION_COMPRESS` | gzip pages; turn off when a proxy compresses |
|
|
240
|
+
| `resume_timeout` | `30.0` | `PYREACTION_RESUME_TIMEOUT` | seconds a dropped page's state is kept |
|
|
241
|
+
| `max_upload_size` | 10 MiB | `PYREACTION_MAX_UPLOAD_SIZE` | bytes per uploaded file |
|
|
242
|
+
| `reconnect_attempts` | `0` (no limit) | `PYREACTION_RECONNECT_ATTEMPTS` | failed attempts before a page gives up |
|
|
243
|
+
|
|
244
|
+
[Configuration](https://github.com/Jeomon/pyreaction/blob/main/docs/configuration.md) lists all of them.
|
|
245
|
+
|
|
246
|
+
## 📚 Documentation
|
|
247
|
+
|
|
248
|
+
| | |
|
|
249
|
+
| --- | --- |
|
|
250
|
+
| [Getting started](https://github.com/Jeomon/pyreaction/blob/main/docs/getting-started.md) | install, a single-file app, a project |
|
|
251
|
+
| [Elements and events](https://github.com/Jeomon/pyreaction/blob/main/docs/elements-and-events.md) | describing the page, handlers, file uploads |
|
|
252
|
+
| [Hooks](https://github.com/Jeomon/pyreaction/blob/main/docs/hooks.md) | state, effects and the rest |
|
|
253
|
+
| [Data, forms and pending state](https://github.com/Jeomon/pyreaction/blob/main/docs/data-and-forms.md) | loading data, Suspense, form actions, optimistic updates |
|
|
254
|
+
| [Routing and the page head](https://github.com/Jeomon/pyreaction/blob/main/docs/routing.md) | URLs, links, redirects, `<title>` and `<meta>` |
|
|
255
|
+
| [Built-in components and the DOM](https://github.com/Jeomon/pyreaction/blob/main/docs/components.md) | refs, portals, long lists, error boundaries, JavaScript widgets |
|
|
256
|
+
| [Shared state](https://github.com/Jeomon/pyreaction/blob/main/docs/state.md) | stores shared between pages, processes, or within one page |
|
|
257
|
+
| [Integrations](https://github.com/Jeomon/pyreaction/blob/main/docs/integrations.md) | FastAPI, Django, Flask, Jinja templates, static pages |
|
|
258
|
+
| [Testing](https://github.com/Jeomon/pyreaction/blob/main/docs/testing.md) | a fake browser for unit tests, a live server for Playwright |
|
|
259
|
+
| [Configuration](https://github.com/Jeomon/pyreaction/blob/main/docs/configuration.md) | every option, in code, `pyproject.toml` or the environment |
|
|
260
|
+
| [Deployment and security](https://github.com/Jeomon/pyreaction/blob/main/docs/deployment.md) | workers, proxies, compression, origins, limits |
|
|
261
|
+
| [API reference](https://github.com/Jeomon/pyreaction/blob/main/docs/api.md) | everything `reaction` exports |
|
|
262
|
+
| [How it works](https://github.com/Jeomon/pyreaction/blob/main/docs/how-it-works.md) | the request, the live connection, and the update protocol |
|
|
263
|
+
|
|
264
|
+
Runnable apps are in [`examples/`](https://github.com/Jeomon/pyreaction/tree/main/examples): a todo list, routed pages, a login
|
|
265
|
+
flow, JavaScript widgets, and a FastAPI app.
|
|
266
|
+
|
|
267
|
+
## 🔒 Security
|
|
268
|
+
|
|
269
|
+
- WebSockets are accepted only from the page's own origin, plus `allowed_origins`.
|
|
270
|
+
- Log in with ordinary HTTP routes that set an `HttpOnly` cookie; a WebSocket cannot
|
|
271
|
+
set cookies. `examples/login.py` is a complete version.
|
|
272
|
+
- Text is always escaped. `dangerously_set_inner_html`, `js()` code and
|
|
273
|
+
`js_component_from_string` are sent as written: never build them from user input.
|
|
274
|
+
- Uploads, queued events and pending updates are capped per page.
|
|
275
|
+
|
|
276
|
+
[Deployment and security](https://github.com/Jeomon/pyreaction/blob/main/docs/deployment.md#security) has the details. To report a
|
|
277
|
+
vulnerability, see [SECURITY.md](https://github.com/Jeomon/pyreaction/blob/main/SECURITY.md); please do not open a public issue.
|
|
278
|
+
|
|
279
|
+
## 📝 Limitations
|
|
280
|
+
|
|
281
|
+
- **Every interaction is a round trip.** Handlers run on the server, so latency
|
|
282
|
+
follows the network; use `js()` for what must react instantly, such as selecting
|
|
283
|
+
an input's text.
|
|
284
|
+
- **Each open page holds state on the server.** Memory grows with open tabs, and a
|
|
285
|
+
10,000-row page holds about 20 MB. Long lists should use `VirtualList`.
|
|
286
|
+
- **Rendering runs on the server's event loop.** A very large page (10,000 rows)
|
|
287
|
+
takes about 80 ms to serve, during which other pages on that process wait.
|
|
288
|
+
- **Resuming after a drop needs the same process.** With several workers, route a
|
|
289
|
+
page's connections to the worker that served it (sticky sessions).
|
|
290
|
+
- **Before 1.0**, the API may still change between minor versions; see the
|
|
291
|
+
[changelog](https://github.com/Jeomon/pyreaction/blob/main/CHANGELOG.md).
|
|
292
|
+
- **The import name is `reaction`**, which an unrelated, unmaintained PyPI package
|
|
293
|
+
(`reaction`, 2020) also uses. Do not install both in one environment.
|
|
294
|
+
|
|
295
|
+
## 🤝 Contributing
|
|
296
|
+
|
|
297
|
+
Bug reports and pull requests are welcome. [CONTRIBUTING.md](https://github.com/Jeomon/pyreaction/blob/main/CONTRIBUTING.md)
|
|
298
|
+
explains the setup, the tests and type checks, and what a change needs.
|
|
299
|
+
[CHANGELOG.md](https://github.com/Jeomon/pyreaction/blob/main/CHANGELOG.md) lists what changed in each version.
|
|
300
|
+
|
|
301
|
+
## 🙏 References
|
|
302
|
+
|
|
303
|
+
pyreaction follows the design of these projects; their documentation is the best
|
|
304
|
+
explanation of the ideas it borrows.
|
|
305
|
+
|
|
306
|
+
- **[React](https://react.dev)** ([source](https://github.com/facebook/react)):
|
|
307
|
+
the component model, hooks and their rules, keys and reconciliation, Suspense,
|
|
308
|
+
error boundaries, portals, and React 19's form actions, `use_optimistic`, `use`,
|
|
309
|
+
`cache`, resource hints and `ViewTransition`. Where pyreaction has a React API,
|
|
310
|
+
it follows React's behaviour, checked against React 19.3's source.
|
|
311
|
+
- **[ReactPy](https://reactpy.dev)** ([source](https://github.com/reactive-python/reactpy)):
|
|
312
|
+
React's model in Python, rendered over a WebSocket. pyreaction's hook names,
|
|
313
|
+
`html` element factories, `to_vdom` key names and JavaScript component interop
|
|
314
|
+
follow ReactPy's lead; it differs in diffing on the server and sending DOM
|
|
315
|
+
operations rather than VDOM trees, and in rendering every page as HTML first.
|
|
316
|
+
|
|
317
|
+
It is built on [Starlette](https://www.starlette.io), [uvicorn](https://www.uvicorn.org)
|
|
318
|
+
and [orjson](https://github.com/ijl/orjson).
|
|
319
|
+
|
|
320
|
+
pyreaction is an independent project. It is not affiliated with, endorsed by or
|
|
321
|
+
sponsored by Meta, the React project or the ReactPy project. React is a trademark of
|
|
322
|
+
Meta Platforms, Inc.; the name is used only to describe what pyreaction follows.
|
|
323
|
+
|
|
324
|
+
## 🪪 License
|
|
325
|
+
|
|
326
|
+
pyreaction is free and open-source software, released under the
|
|
327
|
+
[MIT License](https://github.com/Jeomon/pyreaction/blob/main/LICENSE). You may use, copy, modify, merge, publish, distribute,
|
|
328
|
+
sublicense and sell it, in personal and commercial projects alike, provided the
|
|
329
|
+
copyright notice and the license text are included in all copies or substantial
|
|
330
|
+
portions of the software.
|
|
331
|
+
|
|
332
|
+
The software is provided "as is", without warranty of any kind; the authors are
|
|
333
|
+
not liable for any claim or damages arising from its use. Contributions to
|
|
334
|
+
pyreaction are accepted under the same license (see [CONTRIBUTING.md](https://github.com/Jeomon/pyreaction/blob/main/CONTRIBUTING.md)).
|
|
335
|
+
|
|
336
|
+
## 📄 Citation
|
|
337
|
+
|
|
338
|
+
```bibtex
|
|
339
|
+
@software{pyreaction,
|
|
340
|
+
author = {jeomon},
|
|
341
|
+
title = {pyreaction: React-style UI components in pure Python},
|
|
342
|
+
year = {2026},
|
|
343
|
+
publisher = {GitHub},
|
|
344
|
+
url = {https://github.com/Jeomon/pyreaction}
|
|
345
|
+
}
|
|
346
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
reaction/__init__.py,sha256=4XZ8JOegTpaZjZiTsYq72CytL8fFYzFIvfHxvHv3dwA,4619
|
|
2
|
+
reaction/cli/__init__.py,sha256=aV57l0HM36hO_IaeB0LDR2_LHaHmhMpmQG9wkHhBw4M,3088
|
|
3
|
+
reaction/cli/__main__.py,sha256=BHLi_-4Bx1gsZn-z6x7wECPn1YTxdc74y0deRea9FzY,45
|
|
4
|
+
reaction/cli/scaffold.py,sha256=bSWT4z2oTGcyCogKMgmReztl1RBVQRG-tZVhdbH-XOA,4128
|
|
5
|
+
reaction/cli/serve.py,sha256=_SVbb8jnjpTblHYbFMn73cf0gMhYgpRr4jJoaBbr9fY,4110
|
|
6
|
+
reaction/cli/templates/default/README.md.tmpl,sha256=MlwITkwGSyX7MlRTM0x_6nyEWTuGwWvxHOYeA4BqnOk,500
|
|
7
|
+
reaction/cli/templates/default/_gitignore,sha256=p6kIyjMJtks9JnbhEyKnnl5gxi-_64X9lelVv1stJvM,35
|
|
8
|
+
reaction/cli/templates/default/app.py,sha256=eugKJNOE8dJoHC_97x2pqsPHiG-RhQpmLvkCgzV67dQ,266
|
|
9
|
+
reaction/cli/templates/default/components/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
reaction/cli/templates/default/components/counter.py,sha256=3-CqXTooUhDd_wogTkVL7pSHXBClmmZuwd9WwJZvlFY,363
|
|
11
|
+
reaction/cli/templates/default/public/style.css,sha256=8vXSWG4r64xmoD32XeuTFFaUbjTwYenk_em3vOWacOk,364
|
|
12
|
+
reaction/cli/templates/default/pyproject.toml.tmpl,sha256=pjsMa6La5xuEYGhmBb3plO-JTthrpj5n3hX702pqmJ0,631
|
|
13
|
+
reaction/client/client.js,sha256=Q04mP0SOTyTGEzNPkOD_6pbMkv1clbRGOIbSkXHgAYg,44207
|
|
14
|
+
reaction/client/index.html,sha256=Wu6CfsiniTnJ2fxNvvVMHRd-TDJsDvUUnbj9t7w2LP0,552
|
|
15
|
+
reaction/client/style.css,sha256=8PSnRtF-A_S11LHiWSvweDPCR0JiYh3opJ5F4WEgrm8,1230
|
|
16
|
+
reaction/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
+
reaction/core/_html_types.py,sha256=rP5CHC8wq0Hm7HPfM4TmSU4lBZtOM3t7xEwSyZqFfDE,148258
|
|
18
|
+
reaction/core/boundary.py,sha256=-L2Mkz9mR1HklCiYSsKDphnxdBnQ1jLv_ADkf1eyZ5Y,1768
|
|
19
|
+
reaction/core/components.py,sha256=PhBLwNCrA3lHpwlfiISB51W5Z87R48CX_QwzzpBuZvs,12092
|
|
20
|
+
reaction/core/element.py,sha256=nTFsjdLEpQfW2MD3Jc-bn9oHgLab03plwjBeysFkRW4,29656
|
|
21
|
+
reaction/core/hooks.py,sha256=2EKJNVDhdUMHAxH2V0SpRkUknfkhHlSb7Df2kHo347k,35273
|
|
22
|
+
reaction/core/parse.py,sha256=ZaawlcV8csPuUoZHCABldUQRH8PJ4y2XGfQIbOGjd5s,4296
|
|
23
|
+
reaction/core/resources.py,sha256=jhEW-qruWpFhumIz2gHvDmGQYdzVnCZlUaIeaWaBXJQ,3653
|
|
24
|
+
reaction/core/router.py,sha256=kOs3xRvv8jV31F6MvbRtS_LSOOeJ7K1P3v389vHcXQM,2704
|
|
25
|
+
reaction/core/ssr.py,sha256=jpzuN8XJ144n2TqvbnRzdQyxvQsQNlq0UXZSydeB8As,14984
|
|
26
|
+
reaction/core/store.py,sha256=2W8JLTyMJN69cijssIS_8fQnIBWPlpLEsxZodGhiGS8,13625
|
|
27
|
+
reaction/core/vdom.py,sha256=232iYHtHg08bIPBOs2i1rQqjFI-X7rw3EkmmVB0cWuo,108717
|
|
28
|
+
reaction/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
|
+
reaction/server/__init__.py,sha256=-ByKauF8NkrfjmfaIpMx7-wSoD2i-Romi2lGFh6pJ5U,188
|
|
30
|
+
reaction/server/app.py,sha256=WU8vJgdizDUyo4oZmEqkEHQMsb4atyO4LrRWRjJ1pDc,64687
|
|
31
|
+
reaction/server/encoding.py,sha256=sTWLg0vzSCgqIK_vPc-hMhIQuWh5MA5Kd5JCdmYqonM,2638
|
|
32
|
+
reaction/server/settings.py,sha256=bc2IwkVP1zfYppXc9I72hWLuGsRXySTZwjUGo5EZ2RI,2243
|
|
33
|
+
reaction/testing.py,sha256=Apo1SEvTRW45mBLgbvJej1L3UXnu8CR_tjRJ8Kc66nI,23552
|
|
34
|
+
pyreaction-0.1.0.dist-info/licenses/LICENSE,sha256=94hEZnm9yjqDdIv5rzlDxRG45z_FTLv0ziGv-6-7wds,1063
|
|
35
|
+
pyreaction-0.1.0.dist-info/WHEEL,sha256=xTCBFIZIIyRSxyowOv5Wqg_jFU6KsdIffuulBB09Ph8,80
|
|
36
|
+
pyreaction-0.1.0.dist-info/entry_points.txt,sha256=Ljqw8KyVLaedA_9UuoVJAJY1EkzZhxzs3-xOnw7mZ60,79
|
|
37
|
+
pyreaction-0.1.0.dist-info/METADATA,sha256=nTbRv_Eag4xo145stvU7F2Rl59n4vA-9fvpTjmcYc1s,15097
|
|
38
|
+
pyreaction-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jeomon
|
|
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.
|
reaction/__init__.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"""pyreaction: React-style components in Python, rendered on the server and
|
|
2
|
+
patched into the browser over a WebSocket.
|
|
3
|
+
|
|
4
|
+
from reaction import component, html, use_state, run
|
|
5
|
+
|
|
6
|
+
@component
|
|
7
|
+
def Counter():
|
|
8
|
+
count, set_count = use_state(0)
|
|
9
|
+
return html.button(f"Clicked {count} times", on_click=lambda: set_count(count + 1))
|
|
10
|
+
|
|
11
|
+
run(Counter)
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from .core.boundary import ErrorBoundary
|
|
15
|
+
from .core.components import (
|
|
16
|
+
Activity,
|
|
17
|
+
Form,
|
|
18
|
+
FormStatus,
|
|
19
|
+
Head,
|
|
20
|
+
Profiler,
|
|
21
|
+
StrictMode,
|
|
22
|
+
Suspense,
|
|
23
|
+
ViewTransition,
|
|
24
|
+
VirtualList,
|
|
25
|
+
image,
|
|
26
|
+
use_form_status,
|
|
27
|
+
use_linked_inputs,
|
|
28
|
+
)
|
|
29
|
+
from .core.element import (
|
|
30
|
+
Children,
|
|
31
|
+
Component,
|
|
32
|
+
Element,
|
|
33
|
+
EventHandler,
|
|
34
|
+
JsComponent,
|
|
35
|
+
clone_element,
|
|
36
|
+
component,
|
|
37
|
+
event,
|
|
38
|
+
forward_ref,
|
|
39
|
+
fragment,
|
|
40
|
+
h,
|
|
41
|
+
html,
|
|
42
|
+
is_valid_element,
|
|
43
|
+
js,
|
|
44
|
+
js_component,
|
|
45
|
+
js_component_from_string,
|
|
46
|
+
memo,
|
|
47
|
+
portal,
|
|
48
|
+
)
|
|
49
|
+
from .core.hooks import (
|
|
50
|
+
add_transition_type,
|
|
51
|
+
browser,
|
|
52
|
+
cache_signal,
|
|
53
|
+
flush_sync,
|
|
54
|
+
lazy,
|
|
55
|
+
request_form_reset,
|
|
56
|
+
cache,
|
|
57
|
+
use,
|
|
58
|
+
use_deferred_value,
|
|
59
|
+
create_ref,
|
|
60
|
+
AsyncState,
|
|
61
|
+
Context,
|
|
62
|
+
Ref,
|
|
63
|
+
create_context,
|
|
64
|
+
use_action_state,
|
|
65
|
+
use_async,
|
|
66
|
+
use_callback,
|
|
67
|
+
use_context,
|
|
68
|
+
use_data,
|
|
69
|
+
use_debug_value,
|
|
70
|
+
use_effect,
|
|
71
|
+
use_layout_effect,
|
|
72
|
+
use_effect_event,
|
|
73
|
+
use_id,
|
|
74
|
+
use_imperative_handle,
|
|
75
|
+
use_location,
|
|
76
|
+
use_memo,
|
|
77
|
+
use_navigate,
|
|
78
|
+
use_reducer,
|
|
79
|
+
use_ref,
|
|
80
|
+
use_request,
|
|
81
|
+
use_state,
|
|
82
|
+
use_status,
|
|
83
|
+
use_sync_external_store,
|
|
84
|
+
use_title,
|
|
85
|
+
use_transition,
|
|
86
|
+
start_transition,
|
|
87
|
+
use_optimistic,
|
|
88
|
+
)
|
|
89
|
+
from .core.parse import parse_html
|
|
90
|
+
from .core.vdom import ElementHandle, Event, FormFields, Location, Reply, Root, UploadedFile, to_vdom
|
|
91
|
+
from .core.router import Link, Navigate, Router
|
|
92
|
+
from .core.ssr import render_to_static_markup, render_to_string
|
|
93
|
+
from .core.resources import preconnect, prefetch_dns, preinit, preinit_module, preload, preload_module
|
|
94
|
+
from .core.store import RedisBackend, Store, StoreBackend, use_page_store, use_store
|
|
95
|
+
|
|
96
|
+
def _version() -> str:
|
|
97
|
+
# The version is written once, in pyproject.toml; this reads the installed copy.
|
|
98
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
99
|
+
|
|
100
|
+
try:
|
|
101
|
+
return version("pyreaction")
|
|
102
|
+
except PackageNotFoundError: # run from a source tree that was never installed
|
|
103
|
+
return "0.0.0"
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
__version__ = _version()
|
|
107
|
+
|
|
108
|
+
__all__ = [
|
|
109
|
+
"forward_ref",
|
|
110
|
+
"request_form_reset",
|
|
111
|
+
"lazy",
|
|
112
|
+
"flush_sync",
|
|
113
|
+
"cache_signal",
|
|
114
|
+
"browser",
|
|
115
|
+
"add_transition_type",
|
|
116
|
+
"ViewTransition",
|
|
117
|
+
"VirtualList",
|
|
118
|
+
"cache",
|
|
119
|
+
"Profiler",
|
|
120
|
+
"use_deferred_value",
|
|
121
|
+
"use",
|
|
122
|
+
"create_ref",
|
|
123
|
+
"is_valid_element",
|
|
124
|
+
"clone_element",
|
|
125
|
+
"Children",
|
|
126
|
+
"Activity",
|
|
127
|
+
"StrictMode",
|
|
128
|
+
"AsyncState",
|
|
129
|
+
"Component",
|
|
130
|
+
"Context",
|
|
131
|
+
"Element",
|
|
132
|
+
"ElementHandle",
|
|
133
|
+
"ErrorBoundary",
|
|
134
|
+
"Event",
|
|
135
|
+
"EventHandler",
|
|
136
|
+
"Form",
|
|
137
|
+
"FormFields",
|
|
138
|
+
"FormStatus",
|
|
139
|
+
"Head",
|
|
140
|
+
"JsComponent",
|
|
141
|
+
"Link",
|
|
142
|
+
"Location",
|
|
143
|
+
"Navigate",
|
|
144
|
+
"Ref",
|
|
145
|
+
"Reply",
|
|
146
|
+
"Root",
|
|
147
|
+
"Router",
|
|
148
|
+
"RedisBackend",
|
|
149
|
+
"Store",
|
|
150
|
+
"StoreBackend",
|
|
151
|
+
"Suspense",
|
|
152
|
+
"UploadedFile",
|
|
153
|
+
"component",
|
|
154
|
+
"create_app",
|
|
155
|
+
"mount",
|
|
156
|
+
"page",
|
|
157
|
+
"wrap",
|
|
158
|
+
"prerender",
|
|
159
|
+
"create_context",
|
|
160
|
+
"embed",
|
|
161
|
+
"jinja_components",
|
|
162
|
+
"event",
|
|
163
|
+
"fragment",
|
|
164
|
+
"h",
|
|
165
|
+
"html",
|
|
166
|
+
"js",
|
|
167
|
+
"js_component",
|
|
168
|
+
"js_component_from_string",
|
|
169
|
+
"image",
|
|
170
|
+
"use_linked_inputs",
|
|
171
|
+
"memo",
|
|
172
|
+
"parse_html",
|
|
173
|
+
"preload_module",
|
|
174
|
+
"preload",
|
|
175
|
+
"preinit_module",
|
|
176
|
+
"preinit",
|
|
177
|
+
"prefetch_dns",
|
|
178
|
+
"preconnect",
|
|
179
|
+
"portal",
|
|
180
|
+
"render_to_static_markup",
|
|
181
|
+
"render_to_string",
|
|
182
|
+
"to_vdom",
|
|
183
|
+
"run",
|
|
184
|
+
"use_action_state",
|
|
185
|
+
"use_async",
|
|
186
|
+
"use_callback",
|
|
187
|
+
"use_context",
|
|
188
|
+
"use_data",
|
|
189
|
+
"use_debug_value",
|
|
190
|
+
"use_effect",
|
|
191
|
+
"use_layout_effect",
|
|
192
|
+
"use_effect_event",
|
|
193
|
+
"use_form_status",
|
|
194
|
+
"use_id",
|
|
195
|
+
"use_imperative_handle",
|
|
196
|
+
"use_location",
|
|
197
|
+
"use_memo",
|
|
198
|
+
"use_navigate",
|
|
199
|
+
"use_reducer",
|
|
200
|
+
"use_ref",
|
|
201
|
+
"use_request",
|
|
202
|
+
"use_state",
|
|
203
|
+
"use_status",
|
|
204
|
+
"use_page_store",
|
|
205
|
+
"use_store",
|
|
206
|
+
"use_sync_external_store",
|
|
207
|
+
"use_title",
|
|
208
|
+
"use_transition",
|
|
209
|
+
"start_transition",
|
|
210
|
+
"use_optimistic",
|
|
211
|
+
]
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def __getattr__(name: str):
|
|
215
|
+
# The server pulls in Starlette; load it only when it is asked for.
|
|
216
|
+
if name in ("create_app", "embed", "jinja_components", "mount", "page", "prerender", "run", "wrap"):
|
|
217
|
+
from . import server
|
|
218
|
+
|
|
219
|
+
return getattr(server, name)
|
|
220
|
+
raise AttributeError(f"module 'reaction' has no attribute {name!r}")
|