Skip to content

Commit a080c3e

Browse files
igorlukaninKSDaemon
authored andcommitted
Add docs
1 parent 01d2702 commit a080c3e

File tree

2 files changed

+67
-18
lines changed

2 files changed

+67
-18
lines changed

docs/pages/product/configuration.mdx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
---
2-
redirect_from:
3-
- /configuration/overview
4-
---
5-
61
# Overview
72

83
Cube is configured via [environment variables][link-env-vars] and
@@ -103,6 +98,9 @@ module.exports = {
10398

10499
Both ways are equivalent; when in doubt, use Python.
105100

101+
You can read more about [Python][ref-python] and [JavaScript][ref-javascript] support
102+
in the dynamic data modeling section of the documentation.
103+
106104
### Cube Core
107105

108106
When using Docker, ensure that the configuration file and your [data model
@@ -112,7 +110,8 @@ Docker container.
112110
### Cube Cloud
113111

114112
You can edit the configuration file by going into <Btn>Development Mode</Btn>
115-
and navigating to the <Btn>Data Model</Btn> page.
113+
and navigating to <Btn>[Data Model][ref-data-model]</Btn> or <Btn>[Visual
114+
Model][ref-visual-model]</Btn> pages.
116115

117116
## Runtimes and dependencies
118117

@@ -178,4 +177,8 @@ mode does the following:
178177
[link-docker-env-vars]: https://docs.docker.com/compose/environment-variables/set-environment-variables/
179178
[ref-mls]: /product/auth/member-level-security
180179
[link-current-python-version]: https://github.com/cube-js/cube/blob/master/packages/cubejs-docker/latest.Dockerfile#L13
181-
[link-current-nodejs-version]: https://github.com/cube-js/cube/blob/master/packages/cubejs-docker/latest.Dockerfile#L1
180+
[link-current-nodejs-version]: https://github.com/cube-js/cube/blob/master/packages/cubejs-docker/latest.Dockerfile#L1
181+
[ref-data-model]: /product/workspace/data-model
182+
[ref-visual-model]: /product/workspace/visual-model
183+
[ref-python]: /product/data-modeling/dynamic/jinja#python
184+
[ref-javascript]: /product/data-modeling/dynamic/javascript

docs/pages/product/data-modeling/dynamic/jinja.mdx

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,20 @@ class SafeString(str):
155155

156156
## Python
157157

158-
You can declare and invoke Python functions from within a Jinja template. This
159-
allows the reuse of existing code to generate data models. Cube uses Python 3.9 to execute Python code.
160-
It also installs packages listed in the `requirements.txt` with pip on the startup.
158+
### Template context
161159

162-
These helper functions must be located in `model/globals.py` file or explicitly loaded from the YAML files.
163-
In the following example, we declare a function called `load_data()` which will load data from a remote
164-
API endpoint. We will then use the function to generate a data model in Cube.
160+
You can use Python to declare functions that can be invoked and variables that can be
161+
referenced from within a Jinja template. These functions and variables must be defined
162+
in `model/globals.py` file and registered in the `TemplateContext` instance.
163+
164+
<ReferenceBox>
165+
166+
See the [`TemplateContext` reference][ref-cube-template-context] for more details.
167+
168+
</ReferenceBox>
169+
170+
In the following example, we declare a function called `load_data` that supposedly loads
171+
data from a remote API endpoint. We will then use the function to generate a data model:
165172

166173
```python
167174
from cube import TemplateContext
@@ -237,12 +244,46 @@ cubes:
237244
{%- endfor %}
238245
```
239246

240-
<ReferenceBox>
247+
### Imports
241248

242-
If you'd like to split your Python code into several files, see
243-
[this issue](https://github.com/cube-js/cube/issues/8443#issuecomment-2219804266).
249+
In the `model/globals.py` file (or the `cube.py` configuration file), you can
250+
import modules from the current directory. In the following example, we import a function
251+
from the `utils` module and use it to populate a variable in the template context:
244252

245-
</ReferenceBox>
253+
```python filename="model/utils.py"
254+
def answer_to_main_question() -> str:
255+
return "42"
256+
```
257+
258+
```python filename="model/globals.py"
259+
from cube import TemplateContext
260+
from utils import answer_to_main_question
261+
262+
template = TemplateContext()
263+
264+
answer = answer_to_main_question()
265+
template.add_variable('answer', answer)
266+
```
267+
### Dependencies
268+
269+
If you need to use dependencies in your dynamic data model (or your `cube.py`
270+
configuration file), you can list them in the `requirements.txt` file in the root
271+
directory of your Cube deployment. They will be automatically installed with `pip` on
272+
the startup.
273+
274+
<InfoBox>
275+
276+
[`cube` package][ref-cube-package] is available out of the box, it doesn't need to be
277+
listed in `requirements.txt`.
278+
279+
</InfoBox>
280+
281+
If you use dbt for data transformation, you might find the [`cube_dbt`
282+
package][ref-cube-dbt-package] useful. It provides a set of utilities that simplify
283+
defining the data model in YAML [based on dbt models][ref-cube-with-dbt].
284+
285+
If you need to use dependencies with native extensions, build a [custom Docker
286+
image][ref-docker-image-extension].
246287

247288

248289
[jinja]: https://jinja.palletsprojects.com/
@@ -253,4 +294,9 @@ If you'd like to split your Python code into several files, see
253294
[jinja-docs-autoescaping]: https://jinja.palletsprojects.com/en/3.1.x/api/#autoescaping
254295
[jinja-docs-filters-safe]: https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.safe
255296
[ref-cube-dbt]: /reference/python/cube_dbt
256-
[ref-visual-model]: /product/workspace/visual-model
297+
[ref-visual-model]: /product/workspace/visual-model
298+
[ref-docker-image-extension]: /product/deployment/core#extend-the-docker-image
299+
[ref-cube-package]: /reference/python/cube
300+
[ref-cube-template-context]: /reference/python/cube#templatecontext-class
301+
[ref-cube-dbt-package]: /reference/python/cube_dbt
302+
[ref-cube-with-dbt]: /guides/dbt

0 commit comments

Comments
 (0)