dara-core 1.16.19__py3-none-any.whl → 1.16.20a1__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.
@@ -30,6 +30,7 @@ from dara.core.visual.components.fallback import (
30
30
  Fallback,
31
31
  RowFallbackDef,
32
32
  )
33
+ from dara.core.visual.components.for_cmp import For, ForDef
33
34
  from dara.core.visual.components.invalid_component import InvalidComponent
34
35
  from dara.core.visual.components.menu import Menu, MenuDef
35
36
  from dara.core.visual.components.progress_tracker import (
@@ -49,6 +50,8 @@ __all__ = [
49
50
  'ProgressTrackerDef',
50
51
  'Menu',
51
52
  'MenuDef',
53
+ 'For',
54
+ 'ForDef',
52
55
  'RawString',
53
56
  'RouterContent',
54
57
  'RouterContentDef',
@@ -0,0 +1,149 @@
1
+ from typing import Literal, Optional, Union
2
+
3
+ from pydantic import Field
4
+
5
+ from dara.core.base_definitions import DaraBaseModel
6
+ from dara.core.definitions import ComponentInstance, JsComponentDef
7
+ from dara.core.interactivity.any_variable import AnyVariable
8
+
9
+ ForDef = JsComponentDef(name='For', js_module='@darajs/core', py_module='dara.core')
10
+
11
+
12
+ class VirtualizationConfig(DaraBaseModel):
13
+ size: Union[str, float, None] = None
14
+ """
15
+ The size of each element in the virtualized list.
16
+ If a number is provided, it will be treated as a fixed size.
17
+ If a string is provided, it will be treated as a key accessor to get the size from each element.
18
+ """
19
+
20
+ direction: Literal['vertical', 'horizontal'] = Field(default='vertical')
21
+
22
+
23
+ class For(ComponentInstance):
24
+ """
25
+ The For component is a special component designed to handle rendering of templated components.
26
+ It accepts a renderer component and a data source, then dynamically renders the template
27
+ component for each item in the data source.
28
+
29
+ Note that by default this component only renders the items in the data source, it is not responsible for their layout.
30
+
31
+ To use each item's data in the renderer, use the `LoopVariable` accessible via `Variable.list_item` property.
32
+
33
+ ```python
34
+ from dara.core import Variable
35
+ from dara.core.visual.components import For
36
+
37
+ my_list = Variable([1, 2, 3])
38
+
39
+ # Renders a list of Text component where each item is the corresponding item in the list
40
+ For(
41
+ items=my_list,
42
+ renderer=Text(text=my_list.list_item())
43
+ )
44
+ ```
45
+
46
+ Most of the time, you'll want to store objects in a list. You should then use the `get` property to access specific
47
+ properties of the object and the `key_accessor` on the `For` component to specify the unique key.
48
+
49
+ ```python
50
+ from dara.core import Variable
51
+ from dara.core.visual.components import For
52
+
53
+ my_list = Variable([{'id': 1, 'name': 'John', 'age': 30}, {'id': 2, 'name': 'Jane', 'age': 25}])
54
+
55
+ # Renders a list of Text component where each item is the corresponding item in the list
56
+ For(
57
+ items=my_list,
58
+ renderer=Text(text=my_list.list_item.get('name')),
59
+ key_accessor='id'
60
+ )
61
+ ```
62
+
63
+ For interactivity can use list items in Dara actions, DerivedVariables, py_components, and `If` component for conditional rendering.
64
+
65
+ ```python
66
+ import asyncio
67
+ from dara.core import Variable, action, DerivedVariable, py_component
68
+ from dara.components import Text, Card, Button, Stack, Input
69
+
70
+ # Define a variable that holds a list of items
71
+ arr_var = Variable(
72
+ [
73
+ {'id': 1, 'name': 'foo', 'age': 30, 'data': {'city': 'london', 'country': 'uk'}},
74
+ {'id': 2, 'name': 'bar', 'age': 25, 'data': {'city': 'paris', 'country': 'france'}},
75
+ {'id': 3, 'name': 'baz', 'age': 32, 'data': {'city': 'rome', 'country': 'italy'}},
76
+ {'id': 4, 'name': 'xyz', 'age': 20, 'data': {'city': 'new york', 'country': 'usa'}},
77
+ ]
78
+ )
79
+
80
+ @action
81
+ async def say_hello(ctx: ActionCtx, item):
82
+ await ctx.notify(f'Hello {item}!', title='Hello', status='SUCCESS')
83
+
84
+ @py_component
85
+ async def display_city(city: str):
86
+ return Text(text=f'Server-rendered city: {city}')
87
+
88
+ Stack(
89
+ Text(text='Items:'),
90
+ For(
91
+ items=arr_var,
92
+ key_accessor='id',
93
+ renderer=Card(
94
+ Stack(
95
+ Text('City:'),
96
+ # Dynamic display of the city property
97
+ Text(text=arr_var.list_item['data']['city']),
98
+ Text('Country:'),
99
+ # Dynamic display of the country property
100
+ Text(text=arr_var.list_item['data']['country']),
101
+ # Pass item data into the action
102
+ Button('Say Hello!', onclick=say_hello(arr_var.list_item['name'])),
103
+ # Conditionally render data based on the value
104
+ If(arr_var.list_item['age'] > 30, Text(text='Age is greater than 30')),
105
+ # Pass item data into a derived variable
106
+ Text(
107
+ text=DerivedVariable(lambda x: f'age doubled is {x * 2}', variables=[arr_var.list_item['age']])
108
+ ),
109
+ # Pass item data into a py_component
110
+ display_city(arr_var.list_item['data']['city']),
111
+ ),
112
+ title=arr_var.list_item.get('name'),
113
+ subtitle=arr_var.list_item.get('age'),
114
+ ),
115
+ )
116
+ )
117
+ ```
118
+
119
+ For component also supports "virtualization" of the list items. This means that the component
120
+ will only render a certain number of items at a time, and will load more items as the user scrolls down.
121
+ This can be configured by passing a `VirtualizationConfig` instance to the `virtualization` argument.
122
+
123
+ For example, the above example can be extended to virtualize the list by adding the config:
124
+
125
+ ```python
126
+ Stack(
127
+ For(
128
+ items=arr_var,
129
+ key_accessor='id',
130
+ renderer=..., # omitted for brevity
131
+ virtualization={'size': 300, 'direction': 'vertical'},
132
+ )
133
+ )
134
+ ```
135
+
136
+ which will set each item's size to precisely 300px and will virtualize the list vertically.
137
+
138
+ Alternatively, the size can be set to a string to specify a field in the data to use as the size.
139
+
140
+ :param items: The data source to render the template component for.
141
+ :param renderer: The template component to render for each item in the data source.
142
+ :param key_accessor: The key accessor to use for the data source. If not provided, the key will be the index of the item in the data source.
143
+ :param virtualization: The virtualization configuration for the component. If provided, the component will be virtualized.
144
+ """
145
+
146
+ items: AnyVariable
147
+ renderer: ComponentInstance
148
+ key_accessor: Optional[str] = None
149
+ virtualization: Optional[VirtualizationConfig] = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dara-core
3
- Version: 1.16.19
3
+ Version: 1.16.20a1
4
4
  Summary: Dara Framework Core
5
5
  Home-page: https://dara.causalens.com/
6
6
  License: Apache-2.0
@@ -20,10 +20,10 @@ Requires-Dist: async-asgi-testclient (>=1.4.11,<2.0.0)
20
20
  Requires-Dist: certifi (>=2024.7.4)
21
21
  Requires-Dist: click (==8.1.3)
22
22
  Requires-Dist: colorama (>=0.4.6,<0.5.0)
23
- Requires-Dist: create-dara-app (==1.16.19)
23
+ Requires-Dist: create-dara-app (==1.16.20-alpha.1)
24
24
  Requires-Dist: croniter (>=1.0.15,<3.0.0)
25
25
  Requires-Dist: cryptography (>=42.0.4)
26
- Requires-Dist: dara-components (==1.16.19) ; extra == "all"
26
+ Requires-Dist: dara-components (==1.16.20-alpha.1) ; extra == "all"
27
27
  Requires-Dist: exceptiongroup (>=1.1.3,<2.0.0)
28
28
  Requires-Dist: fastapi (>=0.115.0,<0.116.0)
29
29
  Requires-Dist: fastapi_vite_dara (==0.4.0)
@@ -54,7 +54,7 @@ Description-Content-Type: text/markdown
54
54
 
55
55
  # Dara Application Framework
56
56
 
57
- <img src="https://github.com/causalens/dara/blob/v1.16.19/img/dara_light.svg?raw=true">
57
+ <img src="https://github.com/causalens/dara/blob/v1.16.20-alpha.1/img/dara_light.svg?raw=true">
58
58
 
59
59
  ![Master tests](https://github.com/causalens/dara/actions/workflows/tests.yml/badge.svg?branch=master)
60
60
  [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
@@ -99,7 +99,7 @@ source .venv/bin/activate
99
99
  dara start
100
100
  ```
101
101
 
102
- ![Dara App](https://github.com/causalens/dara/blob/v1.16.19/img/components_gallery.png?raw=true)
102
+ ![Dara App](https://github.com/causalens/dara/blob/v1.16.20-alpha.1/img/components_gallery.png?raw=true)
103
103
 
104
104
  Note: `pip` installation uses [PEP 660](https://peps.python.org/pep-0660/) `pyproject.toml`-based editable installs which require `pip >= 21.3` and `setuptools >= 64.0.0`. You can upgrade both with:
105
105
 
@@ -116,9 +116,9 @@ Explore some of our favorite apps - a great way of getting started and getting t
116
116
 
117
117
  | Dara App | Description |
118
118
  | -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
119
- | ![Large Language Model](https://github.com/causalens/dara/blob/v1.16.19/img/llm.png?raw=true) | Demonstrates how to use incorporate a LLM chat box into your decision app to understand model insights |
120
- | ![Plot Interactivity](https://github.com/causalens/dara/blob/v1.16.19/img/plot_interactivity.png?raw=true) | Demonstrates how to enable the user to interact with plots, trigger actions based on clicks, mouse movements and other interactions with `Bokeh` or `Plotly` plots |
121
- | ![Graph Editor](https://github.com/causalens/dara/blob/v1.16.19/img/graph_viewer.png?raw=true) | Demonstrates how to use the `CausalGraphViewer` component to display your graphs or networks, customising the displayed information through colors and tooltips, and updating the page based on user interaction. |
119
+ | ![Large Language Model](https://github.com/causalens/dara/blob/v1.16.20-alpha.1/img/llm.png?raw=true) | Demonstrates how to use incorporate a LLM chat box into your decision app to understand model insights |
120
+ | ![Plot Interactivity](https://github.com/causalens/dara/blob/v1.16.20-alpha.1/img/plot_interactivity.png?raw=true) | Demonstrates how to enable the user to interact with plots, trigger actions based on clicks, mouse movements and other interactions with `Bokeh` or `Plotly` plots |
121
+ | ![Graph Editor](https://github.com/causalens/dara/blob/v1.16.20-alpha.1/img/graph_viewer.png?raw=true) | Demonstrates how to use the `CausalGraphViewer` component to display your graphs or networks, customising the displayed information through colors and tooltips, and updating the page based on user interaction. |
122
122
 
123
123
  Check out our [App Gallery](https://dara.causalens.com/gallery) for more inspiration!
124
124
 
@@ -145,9 +145,9 @@ And the supporting UI packages and tools.
145
145
  - `ui-utils` - miscellaneous utility functions
146
146
  - `ui-widgets` - widget components
147
147
 
148
- More information on the repository structure can be found in the [CONTRIBUTING.md](https://github.com/causalens/dara/blob/v1.16.19/CONTRIBUTING.md) file.
148
+ More information on the repository structure can be found in the [CONTRIBUTING.md](https://github.com/causalens/dara/blob/v1.16.20-alpha.1/CONTRIBUTING.md) file.
149
149
 
150
150
  ## License
151
151
 
152
- Dara is open-source and licensed under the [Apache 2.0 License](https://github.com/causalens/dara/blob/v1.16.19/LICENSE).
152
+ Dara is open-source and licensed under the [Apache 2.0 License](https://github.com/causalens/dara/blob/v1.16.20-alpha.1/LICENSE).
153
153
 
@@ -11,11 +11,11 @@ dara/core/cli.py,sha256=hgzy8zrEB_JR2GF_nBBfs9d2I9LmjJt0OQJYOOCc284,8158
11
11
  dara/core/configuration.py,sha256=bWD9oL_lqCEq88I2Zr39cPt_8jZIwq5vUAyLFrsmVYQ,22297
12
12
  dara/core/css.py,sha256=KWCJTPpx4tTezP9VJO3k-RSVhWwomJr-4USoLz9vNAs,1771
13
13
  dara/core/data_utils.py,sha256=5GGz4vk6srLO8HMySiAEk_xZCvmf0SeTTgVi-N4qaKY,12636
14
- dara/core/defaults.py,sha256=jRYXdLrEL5NvCDZ2On3Bxije25qvVAduSgrR5PjmUO0,4103
14
+ dara/core/defaults.py,sha256=UkjWwIbo8GLyn8RZRoD3cJe174-3wHZYzvMB0hQCnMg,4150
15
15
  dara/core/definitions.py,sha256=QouD2P2XInW6bqrhPtrfIyDi8i99Au2PTBdWBtgBVrE,16713
16
16
  dara/core/http.py,sha256=LR1Kr5Hca-Z6klNl-M8R8Q1eOfFh3hLrjVS3kVrRsKA,4658
17
17
  dara/core/interactivity/__init__.py,sha256=3e5G5Nww33irzs1LinUmfs6wYpmSLPp9e4BHplw3gIk,2294
18
- dara/core/interactivity/actions.py,sha256=2mkxVsWn5Zb2WzEfUTT00-EJ4JXc0pEsppkM2TRpwgc,45854
18
+ dara/core/interactivity/actions.py,sha256=paujB21J5MYbYZlIP2dIbUStqKbm9PsfCcpcYmOqCSI,45605
19
19
  dara/core/interactivity/any_data_variable.py,sha256=1dLLxLuDErRsgaFPSTXxZHvpVucKKty90twQE6N-_NI,5286
20
20
  dara/core/interactivity/any_variable.py,sha256=LOGhbDdYffujlRxF4LR9ZuWdai03R-EXuGsTEJAwfo0,13544
21
21
  dara/core/interactivity/condition.py,sha256=q_RDDt-DtZEUQL054Mc7zHyJIJIGACljJ2gOFygCHQc,1309
@@ -23,7 +23,8 @@ dara/core/interactivity/data_variable.py,sha256=pvPOx6SMxHWDxoo5Ea5xqLwrBTrWN68x
23
23
  dara/core/interactivity/derived_data_variable.py,sha256=u2HOts5rtmzK3D1K383YfYYQnb4pHZF3rTu1lfwMpPA,15323
24
24
  dara/core/interactivity/derived_variable.py,sha256=7ActxJISTI-EdYUaoqioi8SPznpfCPlqDYlFJO43a38,21886
25
25
  dara/core/interactivity/filtering.py,sha256=BZsWsQvXPhn6WUoAFpAtgN6hXlGDudPbi4h97Qao2ic,9197
26
- dara/core/interactivity/non_data_variable.py,sha256=ewPaNaTpMixR5YCVY1pjmyHgeC53K0CsjQxMusbJsiw,1147
26
+ dara/core/interactivity/loop_variable.py,sha256=w8zDARwsBMJNGgd5oIfoxOrLSyyvSOoQmfY_T8JVSnY,2997
27
+ dara/core/interactivity/non_data_variable.py,sha256=IMH5cNce2O6RUbu4HB_VLT-BBnDnGHr3lp09XU_lWa4,2378
27
28
  dara/core/interactivity/plain_variable.py,sha256=yCm-gBoxNiWsJ43KS4Fr7WCPXIOaChn8FCjXh8IWMUA,9592
28
29
  dara/core/interactivity/url_variable.py,sha256=1ZPFHO3gq7ZuATHt4S9x5ijmk4GBVlUv5KJN6DkM49w,4357
29
30
  dara/core/internal/__init__.py,sha256=QN0wbG9HPQ_vXh8BO8DnBXeYLIENVTNtRmYzZf1lx7c,577
@@ -42,7 +43,7 @@ dara/core/internal/encoder_registry.py,sha256=tq2ka9RjStEFsxTdsWF6kSOU7rycggEq8Y
42
43
  dara/core/internal/execute_action.py,sha256=4lcU4ElyMlaybIv5oDlahsncJA4PM-6hLOKbtEpHPRI,7021
43
44
  dara/core/internal/hashing.py,sha256=bKskv9n7s83uYVRxva77EC9exMbMZudmWsrsTPmg8W8,1139
44
45
  dara/core/internal/import_discovery.py,sha256=XOknoeBsTSa4MgyklG26JGZhVAKhkjcnA7QIWqZlEps,8148
45
- dara/core/internal/normalization.py,sha256=-9cui65ysEFZFDiH3xzfAG8Jr8VlG-EYnMA-CWTN0gw,6349
46
+ dara/core/internal/normalization.py,sha256=_PmPfJTp4--tpX_ltVKbNOuKMqeA1OoacG3ElvLly6U,6360
46
47
  dara/core/internal/pandas_utils.py,sha256=hWOGZbfuakDulviMpaedpi4mhP45hpe9HSRCiDhlF44,2913
47
48
  dara/core/internal/pool/__init__.py,sha256=pBbXE5GR3abVC9Lg3i0QxfdmsrBDMJUYAYb0SiAEBkk,657
48
49
  dara/core/internal/pool/channel.py,sha256=TbyIE-PnfzzsQYhl3INOs5UIHHbF_h9bMFne5FjbWlQ,4948
@@ -81,12 +82,13 @@ dara/core/metrics/cache.py,sha256=bGXwjO_rSc-FkS3PnPi1mvIZf1x-hvmG113dAUk1g-Y,26
81
82
  dara/core/metrics/runtime.py,sha256=YP-6Dz0GeI9_Yr7bUk_-OqShyFySGH_AKpDO126l6es,1833
82
83
  dara/core/metrics/utils.py,sha256=aKaa_hskV3M3h4xOGZYvegDLq_OWOEUlslkQKrrPQiI,2281
83
84
  dara/core/persistence.py,sha256=nTBBjFR39GJgu65SghetSywpVHBdaWDm1L0zTwjkxOM,18342
84
- dara/core/umd/dara.core.umd.js,sha256=HTjWq7MICK8-qUysvQ6Pj2-D-5J5Q7uezm4O5vg4OUA,4916456
85
+ dara/core/umd/dara.core.umd.js,sha256=etSwoV4MhZ_Z17-QVUZ145gCZMhw3KXJb9xubu4Cpoo,4935375
85
86
  dara/core/umd/style.css,sha256=YQtQ4veiSktnyONl0CU1iU1kKfcQhreH4iASi1MP7Ak,4095007
86
87
  dara/core/visual/__init__.py,sha256=QN0wbG9HPQ_vXh8BO8DnBXeYLIENVTNtRmYzZf1lx7c,577
87
- dara/core/visual/components/__init__.py,sha256=4km21GLMLM2cr42SwehLUD7DJOlzvhwHl5hdG1OqmIM,2274
88
+ dara/core/visual/components/__init__.py,sha256=eg6M2YcH1o-I2H3IqLaD32ExfZcXhKuH5KTM52Ow6RM,2359
88
89
  dara/core/visual/components/dynamic_component.py,sha256=w7rxrM9ZTNvkHymkAto_s9UKg7EE8VrlpL9QdRe4sgY,692
89
90
  dara/core/visual/components/fallback.py,sha256=9bhDbyGrWjdSuMX_8eSggkicSjgIa8mP75y9oFNIXK8,3303
91
+ dara/core/visual/components/for_cmp.py,sha256=-0bEFe3GwKpNi0uYb_VEeMNWPwGFps0WGzOHAt5qEwg,6031
90
92
  dara/core/visual/components/invalid_component.py,sha256=Q6O9rAwVUNZXjEmliAKLfWf2lsyYK5JhgQvMM6jVco8,901
91
93
  dara/core/visual/components/menu.py,sha256=ied87GzIoZgmEINgX3WahBqofn-WK1PIBZAgMjR-Bxg,928
92
94
  dara/core/visual/components/progress_tracker.py,sha256=5p_nEJf7RK2oPimXL4YhAN7v0Jcx2HHQzlLxPr7Co38,1705
@@ -104,8 +106,8 @@ dara/core/visual/themes/__init__.py,sha256=aM4mgoIYo2neBSw5FRzswsht7PUKjLthiHLmF
104
106
  dara/core/visual/themes/dark.py,sha256=UQGDooOc8ric73eHs9E0ltYP4UCrwqQ3QxqN_fb4PwY,1942
105
107
  dara/core/visual/themes/definitions.py,sha256=nS_gQvOzCt5hTmj74d0_siq_9QWuj6wNuir4VCHy0Dk,2779
106
108
  dara/core/visual/themes/light.py,sha256=-Tviq8oEwGbdFULoDOqPuHO0UpAZGsBy8qFi0kAGolQ,1944
107
- dara_core-1.16.19.dist-info/LICENSE,sha256=r9u1w2RvpLMV6YjuXHIKXRBKzia3fx_roPwboGcLqCc,10944
108
- dara_core-1.16.19.dist-info/METADATA,sha256=ENPLIUYoskI-1je3TDcjaEgB7H8LGJyIB55IO2r3S74,7507
109
- dara_core-1.16.19.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
110
- dara_core-1.16.19.dist-info/entry_points.txt,sha256=H__D5sNIGuPIhVam0DChNL-To5k8Y7nY7TAFz9Mz6cc,139
111
- dara_core-1.16.19.dist-info/RECORD,,
109
+ dara_core-1.16.20a1.dist-info/LICENSE,sha256=r9u1w2RvpLMV6YjuXHIKXRBKzia3fx_roPwboGcLqCc,10944
110
+ dara_core-1.16.20a1.dist-info/METADATA,sha256=v-pavmYgtNLZ3CBoCRBKuif85oZyh_3be-eEO8Q3O5Q,7581
111
+ dara_core-1.16.20a1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
112
+ dara_core-1.16.20a1.dist-info/entry_points.txt,sha256=H__D5sNIGuPIhVam0DChNL-To5k8Y7nY7TAFz9Mz6cc,139
113
+ dara_core-1.16.20a1.dist-info/RECORD,,