hypie 0.1.1.dev2__tar.gz → 0.1.1.dev3__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.
- hypie-0.1.1.dev2/README.md → hypie-0.1.1.dev3/PKG-INFO +34 -6
- hypie-0.1.1.dev2/PKG-INFO → hypie-0.1.1.dev3/README.md +20 -20
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/pyproject.toml +1 -1
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/cli/build_components.py +1 -1
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/LICENSE +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/__init__.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/commands.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/dom_position.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/events.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/experimental/client_components.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/experimental/components.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/experimental/hyperscript.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/experimental/templates.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/features.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/hs_ast/commands.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/hs_ast/constants.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/hs_ast/contexts.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/hs_ast/expressions.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/hs_ast/features.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/hs_ast/helpers.py +0 -0
- {hypie-0.1.1.dev2 → hypie-0.1.1.dev3}/src/hypie/literals.py +0 -0
|
@@ -1,7 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hypie
|
|
3
|
+
Version: 0.1.1.dev3
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Author: Yasser Ahmed
|
|
6
|
+
Author-email: Yasser Ahmed <yasserfawzi1029@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: htpy>=26.5.1
|
|
10
|
+
Requires-Dist: watchfiles>=1.2.0
|
|
11
|
+
Requires-Python: >=3.12
|
|
12
|
+
Project-URL: Repository, https://github.com/Infrared1029/hypie
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
1
15
|
<p align="center">
|
|
2
16
|
<img src="https://raw.githubusercontent.com/Infrared1029/hypie/main/assets/hypie_logo.jpg" alt="Logo" width="400">
|
|
3
17
|
</p>
|
|
4
18
|
|
|
19
|
+
## Table of Contents
|
|
20
|
+
- [Intro](#intro)
|
|
21
|
+
- [Installation](#installation)
|
|
22
|
+
- [Motivation](#motivation)
|
|
23
|
+
- [Htpy and _Hyperscript Primers](#htpy-and-hyperscript-primers)
|
|
24
|
+
- [Htpy](#htpy)
|
|
25
|
+
- [_Hyperscript](#_hyperscript)
|
|
26
|
+
- [Htpy + _Hyperscript](#htpy--_hyperscript)
|
|
27
|
+
- [Hypie](#hypie)
|
|
28
|
+
- [Simple Counter Example Using Hypie](#simple-counter-example-using-hypie)
|
|
29
|
+
- [Todo App Example Using Hypie](#todo-app-example-using-hypie)
|
|
30
|
+
- [Pass One: Working App](#pass-one-working-app)
|
|
31
|
+
- [Pass Two: Refactor Towards Purer Components And An Event Driven System](#pass-two-refactor-towards-purer-components-and-an-event-driven-system)
|
|
32
|
+
|
|
5
33
|
<!-- # Hypie -->
|
|
6
34
|
## Intro
|
|
7
35
|
Hypie, pronounced "high-pie", is a python library for building web frontends, built on top of [_hyperscript](https://github.com/bigskysoftware/_hyperscript), a scripting language for the web made by the [htmx](https://github.com/bigskysoftware/htmx) folks, and [htpy](https://github.com/pelme/htpy), a library for generating HTML in python.
|
|
@@ -31,7 +59,7 @@ The way Hypie pushes you to think about frontend system is as follows:
|
|
|
31
59
|
- If you need to generate HTML from the client that does not need a server trip (i.e. a visual component that does not rely on any kind of data from the server), like a Modal, you can define a "Template" that you can render anywhere, client side, no server roundtrips.
|
|
32
60
|
|
|
33
61
|
Before diving into hypie, it is useful to take a very quick look at the two main technologies hypie relies on, htpy and _hyperscript, all examples will assume a fastapi backend, but it should work with **any** python backend framework.
|
|
34
|
-
## Htpy and
|
|
62
|
+
## Htpy and _Hyperscript Primers
|
|
35
63
|
### Htpy
|
|
36
64
|
[htpy](https://github.com/pelme/htpy) is a python library for writing html, it is essentially a pythonic answer to templating languages.
|
|
37
65
|
```python
|
|
@@ -164,7 +192,7 @@ htpy.button(_=On("click")[
|
|
|
164
192
|
```
|
|
165
193
|
That way you get IDE support for the arguments the different commands support, you do not deal with messy strings anymore, and the English issue is gone. Again, this is already helpful, but we can take it a step further, taking inspiration from how components look in frameworks like [Vue](https://github.com/vuejs/core) and [Svelte](https://github.com/sveltejs/svelte), a hypie component is as follows:
|
|
166
194
|
|
|
167
|
-
|
|
195
|
+
## Hypie
|
|
168
196
|
```python
|
|
169
197
|
from hypie.literals import var, cls
|
|
170
198
|
from hypie.commands import log, toggle
|
|
@@ -218,7 +246,7 @@ Behind the scenes, hypie adds a `data-hypie-component=<kebab-case-component_name
|
|
|
218
246
|
|
|
219
247
|
Let's move on to other examples and introduce more capabilities and abstractions as we go.
|
|
220
248
|
|
|
221
|
-
|
|
249
|
+
### Simple Counter Example using Hypie
|
|
222
250
|
Let's create a very basic Counter Component using hypie.
|
|
223
251
|
```python
|
|
224
252
|
# ui/components.py
|
|
@@ -337,7 +365,7 @@ def counter_example():
|
|
|
337
365
|
|
|
338
366
|
You can now run the app and see the blue counter button.
|
|
339
367
|
Reminder: We are using FastAPI here but this works with any backend framework! just adjust the code based on your framework's abstractions.
|
|
340
|
-
|
|
368
|
+
### Todo app Example using Hypie
|
|
341
369
|
Let's move on to a more interesting example, a classic Todo app, inspired by the Todo app done in this [FastHTML tutorial](https://www.youtube.com/watch?v=Auqrm7WFc0I).
|
|
342
370
|
|
|
343
371
|
Our end result should look like this:
|
|
@@ -345,7 +373,7 @@ Our end result should look like this:
|
|
|
345
373
|

|
|
346
374
|
We are going to do two passes in this example, the first pass will give us a working app, the second pass will introduce new abstractions that allows us to refactor the code to reduce dependencies between components, both apps will be identical functionality wise, just one will be much easier to maintain and extend, let's start with the first pass.
|
|
347
375
|
|
|
348
|
-
|
|
376
|
+
#### Pass One: Working App
|
|
349
377
|
We can see 5 major UI components:
|
|
350
378
|
- Layout
|
|
351
379
|
- Header
|
|
@@ -610,7 +638,7 @@ def create_todo_(title: Annotated[str, Body(embed=True)]):
|
|
|
610
638
|
```
|
|
611
639
|
That's it, now we have a very basic todo app!
|
|
612
640
|
|
|
613
|
-
|
|
641
|
+
#### Pass Two: Refactor Towards Purer Components and an Event Driven System
|
|
614
642
|
Even though our app works, there is an issue, our components/template are not... **pure**. What does that mean, you might ask? It means, our components are dependent on things outside of their scope, for example, they are performing fetch requests, this depends on what the server returns, whether the network fails, and other variables, that are outside the scope of the component, other components like `AddTodoForm`, beside doing fetch requests as well, is also modifying other parts of the DOM, this creates a dependency between `AddTodoForm` and the parts its trying to modify, if those bits change, we will have to update `AddTodoForm`, not good.
|
|
615
643
|
|
|
616
644
|
Now a valid objection might be: "We still need to make those fetch requests and DOM modifications, the app would not work otherwise!"
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: hypie
|
|
3
|
-
Version: 0.1.1.dev2
|
|
4
|
-
Summary: Add your description here
|
|
5
|
-
Author: Yasser Ahmed
|
|
6
|
-
Author-email: Yasser Ahmed <yasserfawzi1029@gmail.com>
|
|
7
|
-
License-Expression: MIT
|
|
8
|
-
License-File: LICENSE
|
|
9
|
-
Requires-Dist: htpy>=26.5.1
|
|
10
|
-
Requires-Dist: watchfiles>=1.2.0
|
|
11
|
-
Requires-Python: >=3.12
|
|
12
|
-
Project-URL: Repository, https://github.com/Infrared1029/hypie
|
|
13
|
-
Description-Content-Type: text/markdown
|
|
14
|
-
|
|
15
1
|
<p align="center">
|
|
16
2
|
<img src="https://raw.githubusercontent.com/Infrared1029/hypie/main/assets/hypie_logo.jpg" alt="Logo" width="400">
|
|
17
3
|
</p>
|
|
18
4
|
|
|
5
|
+
## Table of Contents
|
|
6
|
+
- [Intro](#intro)
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Motivation](#motivation)
|
|
9
|
+
- [Htpy and _Hyperscript Primers](#htpy-and-hyperscript-primers)
|
|
10
|
+
- [Htpy](#htpy)
|
|
11
|
+
- [_Hyperscript](#_hyperscript)
|
|
12
|
+
- [Htpy + _Hyperscript](#htpy--_hyperscript)
|
|
13
|
+
- [Hypie](#hypie)
|
|
14
|
+
- [Simple Counter Example Using Hypie](#simple-counter-example-using-hypie)
|
|
15
|
+
- [Todo App Example Using Hypie](#todo-app-example-using-hypie)
|
|
16
|
+
- [Pass One: Working App](#pass-one-working-app)
|
|
17
|
+
- [Pass Two: Refactor Towards Purer Components And An Event Driven System](#pass-two-refactor-towards-purer-components-and-an-event-driven-system)
|
|
18
|
+
|
|
19
19
|
<!-- # Hypie -->
|
|
20
20
|
## Intro
|
|
21
21
|
Hypie, pronounced "high-pie", is a python library for building web frontends, built on top of [_hyperscript](https://github.com/bigskysoftware/_hyperscript), a scripting language for the web made by the [htmx](https://github.com/bigskysoftware/htmx) folks, and [htpy](https://github.com/pelme/htpy), a library for generating HTML in python.
|
|
@@ -45,7 +45,7 @@ The way Hypie pushes you to think about frontend system is as follows:
|
|
|
45
45
|
- If you need to generate HTML from the client that does not need a server trip (i.e. a visual component that does not rely on any kind of data from the server), like a Modal, you can define a "Template" that you can render anywhere, client side, no server roundtrips.
|
|
46
46
|
|
|
47
47
|
Before diving into hypie, it is useful to take a very quick look at the two main technologies hypie relies on, htpy and _hyperscript, all examples will assume a fastapi backend, but it should work with **any** python backend framework.
|
|
48
|
-
## Htpy and
|
|
48
|
+
## Htpy and _Hyperscript Primers
|
|
49
49
|
### Htpy
|
|
50
50
|
[htpy](https://github.com/pelme/htpy) is a python library for writing html, it is essentially a pythonic answer to templating languages.
|
|
51
51
|
```python
|
|
@@ -178,7 +178,7 @@ htpy.button(_=On("click")[
|
|
|
178
178
|
```
|
|
179
179
|
That way you get IDE support for the arguments the different commands support, you do not deal with messy strings anymore, and the English issue is gone. Again, this is already helpful, but we can take it a step further, taking inspiration from how components look in frameworks like [Vue](https://github.com/vuejs/core) and [Svelte](https://github.com/sveltejs/svelte), a hypie component is as follows:
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
## Hypie
|
|
182
182
|
```python
|
|
183
183
|
from hypie.literals import var, cls
|
|
184
184
|
from hypie.commands import log, toggle
|
|
@@ -232,7 +232,7 @@ Behind the scenes, hypie adds a `data-hypie-component=<kebab-case-component_name
|
|
|
232
232
|
|
|
233
233
|
Let's move on to other examples and introduce more capabilities and abstractions as we go.
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
### Simple Counter Example using Hypie
|
|
236
236
|
Let's create a very basic Counter Component using hypie.
|
|
237
237
|
```python
|
|
238
238
|
# ui/components.py
|
|
@@ -351,7 +351,7 @@ def counter_example():
|
|
|
351
351
|
|
|
352
352
|
You can now run the app and see the blue counter button.
|
|
353
353
|
Reminder: We are using FastAPI here but this works with any backend framework! just adjust the code based on your framework's abstractions.
|
|
354
|
-
|
|
354
|
+
### Todo app Example using Hypie
|
|
355
355
|
Let's move on to a more interesting example, a classic Todo app, inspired by the Todo app done in this [FastHTML tutorial](https://www.youtube.com/watch?v=Auqrm7WFc0I).
|
|
356
356
|
|
|
357
357
|
Our end result should look like this:
|
|
@@ -359,7 +359,7 @@ Our end result should look like this:
|
|
|
359
359
|

|
|
360
360
|
We are going to do two passes in this example, the first pass will give us a working app, the second pass will introduce new abstractions that allows us to refactor the code to reduce dependencies between components, both apps will be identical functionality wise, just one will be much easier to maintain and extend, let's start with the first pass.
|
|
361
361
|
|
|
362
|
-
|
|
362
|
+
#### Pass One: Working App
|
|
363
363
|
We can see 5 major UI components:
|
|
364
364
|
- Layout
|
|
365
365
|
- Header
|
|
@@ -624,7 +624,7 @@ def create_todo_(title: Annotated[str, Body(embed=True)]):
|
|
|
624
624
|
```
|
|
625
625
|
That's it, now we have a very basic todo app!
|
|
626
626
|
|
|
627
|
-
|
|
627
|
+
#### Pass Two: Refactor Towards Purer Components and an Event Driven System
|
|
628
628
|
Even though our app works, there is an issue, our components/template are not... **pure**. What does that mean, you might ask? It means, our components are dependent on things outside of their scope, for example, they are performing fetch requests, this depends on what the server returns, whether the network fails, and other variables, that are outside the scope of the component, other components like `AddTodoForm`, beside doing fetch requests as well, is also modifying other parts of the DOM, this creates a dependency between `AddTodoForm` and the parts its trying to modify, if those bits change, we will have to update `AddTodoForm`, not good.
|
|
629
629
|
|
|
630
630
|
Now a valid objection might be: "We still need to make those fetch requests and DOM modifications, the app would not work otherwise!"
|
|
@@ -65,7 +65,7 @@ def find_components_register_artifacts(in_path, out_path, out_files_prefix=""):
|
|
|
65
65
|
hs_files = []
|
|
66
66
|
html = []
|
|
67
67
|
print(
|
|
68
|
-
f"Done Proccessing: {len(COMPONENTS)} Component, {len(
|
|
68
|
+
f"Done Proccessing: {len(COMPONENTS)} Component, {len(HYPERSCRIPT)} HS Scripts"
|
|
69
69
|
)
|
|
70
70
|
for c in COMPONENTS:
|
|
71
71
|
style = c.generate_style(with_style_tags=False)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|