reflex 0.7.2a2__py3-none-any.whl → 0.7.3__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.

Potentially problematic release.


This version of reflex might be problematic. Click here for more details.

Files changed (45) hide show
  1. reflex/.templates/jinja/web/pages/custom_component.js.jinja2 +6 -3
  2. reflex/.templates/web/components/reflex/radix_themes_color_mode_provider.js +1 -1
  3. reflex/.templates/web/components/shiki/code.js +26 -21
  4. reflex/.templates/web/postcss.config.js +1 -1
  5. reflex/.templates/web/utils/client_side_routing.js +18 -16
  6. reflex/.templates/web/utils/helpers/dataeditor.js +1 -1
  7. reflex/.templates/web/utils/helpers/range.js +30 -30
  8. reflex/.templates/web/utils/state.js +44 -22
  9. reflex/app_mixins/middleware.py +9 -10
  10. reflex/compiler/compiler.py +7 -0
  11. reflex/components/core/banner.py +1 -1
  12. reflex/components/core/foreach.py +3 -2
  13. reflex/components/datadisplay/logo.py +1 -1
  14. reflex/components/el/__init__.pyi +22 -0
  15. reflex/components/el/elements/__init__.py +20 -1
  16. reflex/components/el/elements/__init__.pyi +42 -1
  17. reflex/components/el/elements/media.py +11 -0
  18. reflex/components/el/elements/media.pyi +11 -0
  19. reflex/components/lucide/icon.py +8 -6
  20. reflex/components/lucide/icon.pyi +0 -1
  21. reflex/components/radix/themes/components/slider.py +2 -1
  22. reflex/config.py +13 -7
  23. reflex/custom_components/custom_components.py +23 -25
  24. reflex/event.py +7 -2
  25. reflex/istate/data.py +59 -7
  26. reflex/reflex.py +75 -32
  27. reflex/state.py +3 -3
  28. reflex/style.py +3 -3
  29. reflex/testing.py +4 -10
  30. reflex/utils/exceptions.py +31 -1
  31. reflex/utils/exec.py +4 -8
  32. reflex/utils/export.py +2 -2
  33. reflex/utils/prerequisites.py +3 -45
  34. reflex/utils/pyi_generator.py +2 -2
  35. reflex/utils/redir.py +3 -12
  36. reflex/vars/base.py +26 -3
  37. reflex/vars/number.py +22 -21
  38. reflex/vars/object.py +29 -0
  39. reflex/vars/sequence.py +37 -0
  40. {reflex-0.7.2a2.dist-info → reflex-0.7.3.dist-info}/METADATA +52 -59
  41. {reflex-0.7.2a2.dist-info → reflex-0.7.3.dist-info}/RECORD +64 -64
  42. {reflex-0.7.2a2.dist-info → reflex-0.7.3.dist-info}/WHEEL +1 -1
  43. reflex-0.7.3.dist-info/entry_points.txt +2 -0
  44. reflex-0.7.2a2.dist-info/entry_points.txt +0 -3
  45. {reflex-0.7.2a2.dist-info → reflex-0.7.3.dist-info/licenses}/LICENSE +0 -0
reflex/vars/number.py CHANGED
@@ -23,6 +23,7 @@ from reflex.utils.exceptions import (
23
23
  VarValueError,
24
24
  )
25
25
  from reflex.utils.imports import ImportDict, ImportVar
26
+ from reflex.utils.types import safe_issubclass
26
27
 
27
28
  from .base import (
28
29
  CustomVarOperationReturn,
@@ -524,7 +525,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
524
525
  Returns:
525
526
  bool: True if the number is a float.
526
527
  """
527
- return issubclass(self._var_type, float)
528
+ return safe_issubclass(self._var_type, float)
528
529
 
529
530
  def _is_strict_int(self) -> bool:
530
531
  """Check if the number is an int.
@@ -532,7 +533,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
532
533
  Returns:
533
534
  bool: True if the number is an int.
534
535
  """
535
- return issubclass(self._var_type, int)
536
+ return safe_issubclass(self._var_type, int)
536
537
 
537
538
  def __format__(self, format_spec: str) -> str:
538
539
  """Format the number.
@@ -546,6 +547,20 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
546
547
  Raises:
547
548
  VarValueError: If the format specifier is not supported.
548
549
  """
550
+ from .sequence import (
551
+ get_decimal_string_operation,
552
+ get_decimal_string_separator_operation,
553
+ )
554
+
555
+ separator = ""
556
+
557
+ if format_spec and format_spec[:1] == ",":
558
+ separator = ","
559
+ format_spec = format_spec[1:]
560
+ elif format_spec and format_spec[:1] == "_":
561
+ separator = "_"
562
+ format_spec = format_spec[1:]
563
+
549
564
  if (
550
565
  format_spec
551
566
  and format_spec[-1] == "f"
@@ -553,14 +568,17 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
553
568
  and format_spec[1:-1].isdigit()
554
569
  ):
555
570
  how_many_decimals = int(format_spec[1:-1])
571
+ return f"{get_decimal_string_operation(self, Var.create(how_many_decimals), Var.create(separator))}"
572
+
573
+ if not format_spec and separator:
556
574
  return (
557
- f"{get_decimal_string_operation(self, Var.create(how_many_decimals))}"
575
+ f"{get_decimal_string_separator_operation(self, Var.create(separator))}"
558
576
  )
559
577
 
560
578
  if format_spec:
561
579
  raise VarValueError(
562
580
  (
563
- "Unknown format code '{}' for object of type 'NumberVar'. It is only supported to use '.f' for float numbers."
581
+ "Unknown format code '{}' for object of type 'NumberVar'. It is only supported to use ',', '_', and '.f' for float numbers."
564
582
  "If possible, use computed variables instead: https://reflex.dev/docs/vars/computed-vars/"
565
583
  ).format(format_spec)
566
584
  )
@@ -568,23 +586,6 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
568
586
  return super().__format__(format_spec)
569
587
 
570
588
 
571
- @var_operation
572
- def get_decimal_string_operation(value: NumberVar, decimals: NumberVar):
573
- """Get the decimal string of the number.
574
-
575
- Args:
576
- value: The number.
577
- decimals: The number of decimals.
578
-
579
- Returns:
580
- The decimal string of the number.
581
- """
582
- return var_operation_return(
583
- js_expression=f"({value}.toFixed({decimals}))",
584
- var_type=str,
585
- )
586
-
587
-
588
589
  def binary_number_operation(
589
590
  func: Callable[[NumberVar, NumberVar], str],
590
591
  ) -> Callable[[number_types, number_types], NumberVar]:
reflex/vars/object.py CHANGED
@@ -202,6 +202,12 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=Mapping):
202
202
  key: Var | Any,
203
203
  ) -> ObjectVar[Mapping[OTHER_KEY_TYPE, VALUE_TYPE]]: ...
204
204
 
205
+ @overload
206
+ def __getitem__(
207
+ self: ObjectVar[Mapping[Any, VALUE_TYPE]],
208
+ key: Var | Any,
209
+ ) -> Var[VALUE_TYPE]: ...
210
+
205
211
  def __getitem__(self, key: Var | Any) -> Var:
206
212
  """Get an item from the object.
207
213
 
@@ -221,6 +227,29 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=Mapping):
221
227
  return self.__getattr__(key)
222
228
  return ObjectItemOperation.create(self, key).guess_type()
223
229
 
230
+ def get(self, key: Var | Any, default: Var | Any | None = None) -> Var:
231
+ """Get an item from the object.
232
+
233
+ Args:
234
+ key: The key to get from the object.
235
+ default: The default value if the key is not found.
236
+
237
+ Returns:
238
+ The item from the object.
239
+ """
240
+ from reflex.components.core.cond import cond
241
+
242
+ if default is None:
243
+ default = Var.create(None)
244
+
245
+ value = self.__getitem__(key) # pyright: ignore[reportUnknownVariableType,reportAttributeAccessIssue,reportUnknownMemberType]
246
+
247
+ return cond( # pyright: ignore[reportUnknownVariableType]
248
+ value,
249
+ value,
250
+ default,
251
+ )
252
+
224
253
  # NoReturn is used here to catch when key value is Any
225
254
  @overload
226
255
  def __getattr__( # pyright: ignore [reportOverlappingOverload]
reflex/vars/sequence.py CHANGED
@@ -1202,6 +1202,43 @@ def string_replace_operation(
1202
1202
  )
1203
1203
 
1204
1204
 
1205
+ @var_operation
1206
+ def get_decimal_string_separator_operation(value: NumberVar, separator: StringVar):
1207
+ """Get the decimal string separator.
1208
+
1209
+ Args:
1210
+ value: The number.
1211
+ separator: The separator.
1212
+
1213
+ Returns:
1214
+ The decimal string separator.
1215
+ """
1216
+ return var_operation_return(
1217
+ js_expression=f"({value}.toLocaleString('en-US').replaceAll(',', {separator}))",
1218
+ var_type=str,
1219
+ )
1220
+
1221
+
1222
+ @var_operation
1223
+ def get_decimal_string_operation(
1224
+ value: NumberVar, decimals: NumberVar, separator: StringVar
1225
+ ):
1226
+ """Get the decimal string of the number.
1227
+
1228
+ Args:
1229
+ value: The number.
1230
+ decimals: The number of decimals.
1231
+ separator: The separator.
1232
+
1233
+ Returns:
1234
+ The decimal string of the number.
1235
+ """
1236
+ return var_operation_return(
1237
+ js_expression=f"({value}.toLocaleString('en-US', ((decimals) => ({{minimumFractionDigits: decimals, maximumFractionDigits: decimals}}))({decimals})).replaceAll(',', {separator}))",
1238
+ var_type=str,
1239
+ )
1240
+
1241
+
1205
1242
  # Compile regex for finding reflex var tags.
1206
1243
  _decode_var_pattern_re = (
1207
1244
  rf"{constants.REFLEX_VAR_OPENING_TAG}(.*?){constants.REFLEX_VAR_CLOSING_TAG}"
@@ -1,12 +1,15 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: reflex
3
- Version: 0.7.2a2
3
+ Version: 0.7.3
4
4
  Summary: Web apps in pure Python.
5
+ Project-URL: homepage, https://reflex.dev
6
+ Project-URL: repository, https://github.com/reflex-dev/reflex
7
+ Project-URL: documentation, https://reflex.dev/docs/getting-started/introduction
8
+ Author-email: Nikhil Rao <nikhil@reflex.dev>, Alek Petuskey <alek@reflex.dev>, Masen Furer <masen@reflex.dev>, Elijah Ahianyo <elijahahianyo@gmail.com>, Thomas Brandeho <thomas@reflex.dev>, Khaleel Al-Adhami <khaleel@reflex.dev>
9
+ Maintainer-email: Masen Furer <masen@reflex.dev>, Thomas Brandeho <thomas@reflex.dev>, Khaleel Al-Adhami <khaleel@reflex.dev>
5
10
  License: Apache-2.0
6
- Keywords: web,framework
7
- Author: Nikhil Rao
8
- Author-email: nikhil@reflex.dev
9
- Requires-Python: >=3.10,<4.0
11
+ License-File: LICENSE
12
+ Keywords: framework,web
10
13
  Classifier: Development Status :: 4 - Beta
11
14
  Classifier: License :: OSI Approved :: Apache Software License
12
15
  Classifier: Programming Language :: Python :: 3
@@ -14,41 +17,38 @@ Classifier: Programming Language :: Python :: 3.10
14
17
  Classifier: Programming Language :: Python :: 3.11
15
18
  Classifier: Programming Language :: Python :: 3.12
16
19
  Classifier: Programming Language :: Python :: 3.13
17
- Requires-Dist: alembic (>=1.11.1,<2.0)
18
- Requires-Dist: build (>=1.0.3,<2.0)
19
- Requires-Dist: charset-normalizer (>=3.3.2,<4.0)
20
- Requires-Dist: distro (>=1.8.0,<2.0) ; sys_platform == "linux"
21
- Requires-Dist: fastapi (>=0.96.0,!=0.111.0,!=0.111.1)
22
- Requires-Dist: gunicorn (>=20.1.0,<24.0)
23
- Requires-Dist: httpx (>=0.25.1,<1.0)
24
- Requires-Dist: jinja2 (>=3.1.2,<4.0)
25
- Requires-Dist: lazy_loader (>=0.4)
26
- Requires-Dist: packaging (>=23.1,<25.0)
27
- Requires-Dist: platformdirs (>=3.10.0,<5.0)
28
- Requires-Dist: psutil (>=5.9.4,<7.0)
29
- Requires-Dist: pydantic (>=1.10.21,<3.0)
30
- Requires-Dist: python-engineio (!=4.6.0)
31
- Requires-Dist: python-multipart (>=0.0.5,<0.1)
32
- Requires-Dist: python-socketio (>=5.7.0,<6.0)
33
- Requires-Dist: redis (>=4.3.5,<6.0)
34
- Requires-Dist: reflex-hosting-cli (>=0.1.29)
35
- Requires-Dist: rich (>=13.0.0,<14.0)
36
- Requires-Dist: setuptools (>=75.0)
37
- Requires-Dist: sqlmodel (>=0.0.14,<0.1)
38
- Requires-Dist: starlette-admin (>=0.11.0,<1.0)
39
- Requires-Dist: tomlkit (>=0.12.4,<1.0)
40
- Requires-Dist: twine (>=4.0.0,<7.0)
41
- Requires-Dist: typer (>=0.15.1,<1.0)
42
- Requires-Dist: typing_extensions (>=4.6.0)
43
- Requires-Dist: uvicorn (>=0.20.0)
44
- Requires-Dist: wheel (>=0.42.0,<1.0)
45
- Requires-Dist: wrapt (>=1.17.0,<2.0)
46
- Project-URL: Documentation, https://reflex.dev/docs/getting-started/introduction
47
- Project-URL: Homepage, https://reflex.dev
48
- Project-URL: Repository, https://github.com/reflex-dev/reflex
20
+ Requires-Python: <4.0,>=3.10
21
+ Requires-Dist: alembic<2.0,>=1.11.1
22
+ Requires-Dist: build<2.0,>=1.0.3
23
+ Requires-Dist: charset-normalizer<4.0,>=3.3.2
24
+ Requires-Dist: distro<2.0,>=1.8.0; platform_system == 'Linux'
25
+ Requires-Dist: fastapi!=0.111.0,!=0.111.1,>=0.96.0
26
+ Requires-Dist: gunicorn<24.0,>=20.1.0
27
+ Requires-Dist: httpx<1.0,>=0.25.1
28
+ Requires-Dist: jinja2<4.0,>=3.1.2
29
+ Requires-Dist: lazy-loader>=0.4
30
+ Requires-Dist: packaging<25.0,>=23.1
31
+ Requires-Dist: platformdirs<5.0,>=3.10.0
32
+ Requires-Dist: psutil<8.0,>=5.9.4
33
+ Requires-Dist: pydantic<3.0,>=1.10.21
34
+ Requires-Dist: python-engineio!=4.6.0
35
+ Requires-Dist: python-multipart<0.1,>=0.0.5
36
+ Requires-Dist: python-socketio<6.0,>=5.7.0
37
+ Requires-Dist: redis<6.0,>=4.3.5
38
+ Requires-Dist: reflex-hosting-cli>=0.1.29
39
+ Requires-Dist: rich<14.0,>=13.0.0
40
+ Requires-Dist: setuptools>=75.0
41
+ Requires-Dist: sqlmodel<0.1,>=0.0.14
42
+ Requires-Dist: starlette-admin<1.0,>=0.11.0
43
+ Requires-Dist: tomlkit<1.0,>=0.12.4
44
+ Requires-Dist: twine<7.0,>=4.0.0
45
+ Requires-Dist: typer<1.0,>=0.15.1
46
+ Requires-Dist: typing-extensions>=4.6.0
47
+ Requires-Dist: uvicorn>=0.20.0
48
+ Requires-Dist: wheel<1.0,>=0.42.0
49
+ Requires-Dist: wrapt<2.0,>=1.17.0
49
50
  Description-Content-Type: text/markdown
50
51
 
51
-
52
52
  <div align="center">
53
53
  <img src="https://raw.githubusercontent.com/reflex-dev/reflex/main/docs/images/reflex_dark.svg#gh-light-mode-only" alt="Reflex Logo" width="300px">
54
54
  <img src="https://raw.githubusercontent.com/reflex-dev/reflex/main/docs/images/reflex_light.svg#gh-dark-mode-only" alt="Reflex Logo" width="300px">
@@ -56,10 +56,12 @@ Description-Content-Type: text/markdown
56
56
  <hr>
57
57
 
58
58
  ### **✨ Performant, customizable web apps in pure Python. Deploy in seconds. ✨**
59
+
59
60
  [![PyPI version](https://badge.fury.io/py/reflex.svg)](https://badge.fury.io/py/reflex)
60
61
  ![versions](https://img.shields.io/pypi/pyversions/reflex.svg)
61
62
  [![Documentation](https://img.shields.io/badge/Documentation%20-Introduction%20-%20%23007ec6)](https://reflex.dev/docs/getting-started/introduction)
62
63
  [![Discord](https://img.shields.io/discord/1029853095527727165?color=%237289da&label=Discord)](https://discord.gg/T5WSbC2YtQ)
64
+
63
65
  </div>
64
66
 
65
67
  ---
@@ -73,9 +75,10 @@ Description-Content-Type: text/markdown
73
75
  Reflex is a library to build full-stack web apps in pure Python.
74
76
 
75
77
  Key features:
76
- * **Pure Python** - Write your app's frontend and backend all in Python, no need to learn Javascript.
77
- * **Full Flexibility** - Reflex is easy to get started with, but can also scale to complex apps.
78
- * **Deploy Instantly** - After building, deploy your app with a [single command](https://reflex.dev/docs/hosting/deploy-quick-start/) or host it on your own server.
78
+
79
+ - **Pure Python** - Write your app's frontend and backend all in Python, no need to learn Javascript.
80
+ - **Full Flexibility** - Reflex is easy to get started with, but can also scale to complex apps.
81
+ - **Deploy Instantly** - After building, deploy your app with a [single command](https://reflex.dev/docs/hosting/deploy-quick-start/) or host it on your own server.
79
82
 
80
83
  See our [architecture page](https://reflex.dev/blog/2024-03-21-reflex-architecture/#the-reflex-architecture) to learn how Reflex works under the hood.
81
84
 
@@ -99,7 +102,7 @@ cd my_app_name
99
102
  reflex init
100
103
  ```
101
104
 
102
- This command initializes a template app in your new directory.
105
+ This command initializes a template app in your new directory.
103
106
 
104
107
  You can run this app in development mode:
105
108
 
@@ -111,7 +114,6 @@ You should see your app running at http://localhost:3000.
111
114
 
112
115
  Now you can modify the source code in `my_app_name/my_app_name.py`. Reflex has fast refreshes so you can see your changes instantly when you save your code.
113
116
 
114
-
115
117
  ## 🫧 Example App
116
118
 
117
119
  Let's go over an example: creating an image generation UI around [DALL·E](https://platform.openai.com/docs/guides/images/image-generation?context=node). For simplicity, we just call the [OpenAI API](https://platform.openai.com/docs/api-reference/authentication), but you could replace this with an ML model run locally.
@@ -126,8 +128,6 @@ Let's go over an example: creating an image generation UI around [DALL·E](https
126
128
 
127
129
  Here is the complete code to create this. This is all done in one Python file!
128
130
 
129
-
130
-
131
131
  ```python
132
132
  import reflex as rx
133
133
  import openai
@@ -167,7 +167,7 @@ def index():
167
167
  width="25em",
168
168
  ),
169
169
  rx.button(
170
- "Generate Image",
170
+ "Generate Image",
171
171
  on_click=State.get_image,
172
172
  width="25em",
173
173
  loading=State.processing
@@ -187,17 +187,12 @@ app = rx.App()
187
187
  app.add_page(index, title="Reflex:DALL-E")
188
188
  ```
189
189
 
190
-
191
-
192
-
193
-
194
190
  ## Let's break this down.
195
191
 
196
192
  <div align="center">
197
193
  <img src="docs/images/dalle_colored_code_example.png" alt="Explaining the differences between backend and frontend parts of the DALL-E app." width="900" />
198
194
  </div>
199
195
 
200
-
201
196
  ### **Reflex UI**
202
197
 
203
198
  Let's start with the UI.
@@ -275,11 +270,10 @@ You can create a multi-page app by adding more pages.
275
270
 
276
271
  <div align="center">
277
272
 
278
- 📑 [Docs](https://reflex.dev/docs/getting-started/introduction) &nbsp; | &nbsp; 🗞️ [Blog](https://reflex.dev/blog) &nbsp; | &nbsp; 📱 [Component Library](https://reflex.dev/docs/library) &nbsp; | &nbsp; 🖼️ [Templates](https://reflex.dev/templates/) &nbsp; | &nbsp; 🛸 [Deployment](https://reflex.dev/docs/hosting/deploy-quick-start) &nbsp;
273
+ 📑 [Docs](https://reflex.dev/docs/getting-started/introduction) &nbsp; | &nbsp; 🗞️ [Blog](https://reflex.dev/blog) &nbsp; | &nbsp; 📱 [Component Library](https://reflex.dev/docs/library) &nbsp; | &nbsp; 🖼️ [Templates](https://reflex.dev/templates/) &nbsp; | &nbsp; 🛸 [Deployment](https://reflex.dev/docs/hosting/deploy-quick-start) &nbsp;
279
274
 
280
275
  </div>
281
276
 
282
-
283
277
  ## ✅ Status
284
278
 
285
279
  Reflex launched in December 2022 with the name Pynecone.
@@ -292,14 +286,14 @@ Reflex has new releases and features coming every other week! Make sure to :star
292
286
 
293
287
  We welcome contributions of any size! Below are some good ways to get started in the Reflex community.
294
288
 
295
- - **Join Our Discord**: Our [Discord](https://discord.gg/T5WSbC2YtQ) is the best place to get help on your Reflex project and to discuss how you can contribute.
296
- - **GitHub Discussions**: A great way to talk about features you want added or things that are confusing/need clarification.
297
- - **GitHub Issues**: [Issues](https://github.com/reflex-dev/reflex/issues) are an excellent way to report bugs. Additionally, you can try and solve an existing issue and submit a PR.
289
+ - **Join Our Discord**: Our [Discord](https://discord.gg/T5WSbC2YtQ) is the best place to get help on your Reflex project and to discuss how you can contribute.
290
+ - **GitHub Discussions**: A great way to talk about features you want added or things that are confusing/need clarification.
291
+ - **GitHub Issues**: [Issues](https://github.com/reflex-dev/reflex/issues) are an excellent way to report bugs. Additionally, you can try and solve an existing issue and submit a PR.
298
292
 
299
293
  We are actively looking for contributors, no matter your skill level or experience. To contribute check out [CONTRIBUTING.md](https://github.com/reflex-dev/reflex/blob/main/CONTRIBUTING.md)
300
294
 
301
-
302
295
  ## All Thanks To Our Contributors:
296
+
303
297
  <a href="https://github.com/reflex-dev/reflex/graphs/contributors">
304
298
  <img src="https://contrib.rocks/image?repo=reflex-dev/reflex" />
305
299
  </a>
@@ -307,4 +301,3 @@ We are actively looking for contributors, no matter your skill level or experien
307
301
  ## License
308
302
 
309
303
  Reflex is open-source and licensed under the [Apache License 2.0](LICENSE).
310
-