Skip to content

Commit 0cce2c1

Browse files
committed
ITables can use an itables.toml configuration file
1 parent 718c6e5 commit 0cce2c1

File tree

14 files changed

+281
-63
lines changed

14 files changed

+281
-63
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- name: Set up Python
3131
uses: actions/setup-python@v5
3232
with:
33+
python-version: '3.13'
3334
cache: 'pip'
3435
- run: |
3536
python -m venv .venv

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ITables ChangeLog
99

1010
**Added**
1111
- We have added the `columnControl` extension that was recently added to DataTables ([blog post](https://datatables.net/blog/2025/columncontrol)) ([#403](https://github.com/mwouts/itables/issues/403))
12+
- The default options can be set through an `itables.toml` configuration file, either in the current or in a parent folder ([#429](https://github.com/mwouts/itables/issues/429))
1213

1314
**Changed**
1415
- We have changed the default value of the `html` argument in `itables.sample_dfs.get_countries`. It now defaults to `False`, in which case the example dataframes contains no HTML code.

docs/options/buttons.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ the location of the buttons (the default is `layout={"topStart": "buttons"}`). A
3535

3636
As always, it is possible to set default values for these parameters by setting these on `itables.options`. For instance, set
3737
```python
38-
itables.options.buttons = ["copyHtml5", "csvHtml5", "excelHtml5"]
38+
itables.options.buttons = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]
3939
```
4040
to get the buttons for all your tables.
4141

42+
You can also add
43+
```
44+
buttons = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]
45+
```
46+
to your `itables.toml` configuration file.
47+
4248

4349
By default, the exported file name is the name of the HTML page. To change it, set a
4450
[`title` option](https://datatables.net/extensions/buttons/examples/html5/filename.html) on the buttons, like

docs/options/classes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ itables.show(df, classes="display")
4545
4646
itables.show(df, classes="display nowrap cell-border")
4747
```
48+
49+
```tip
50+
You can change the default for all your notebooks and apps by creating an `itables.toml` file in the current or a parent directory, with e.g. this content:
51+
~~~
52+
classes = ["display", "nowrap", "compact"]
53+
~~~
54+
```

docs/options/column_control.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,17 @@ itables.show(
7272
ordering={"indicators": False, "handler": False},
7373
)
7474
```
75+
76+
As usual, you can make this the default by either setting `itables.options.columnControl` in your notebook or application, or by adding this to your `itables.toml` configuration file:
77+
```
78+
[[columnControl]]
79+
target = 0
80+
content = ["order"]
81+
[[columnControl]]
82+
target = "tfoot"
83+
content = ["search"]
84+
85+
[ordering]
86+
indicators = false
87+
handler = false
88+
```

docs/options/options.md

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,61 @@ kernelspec:
1616

1717
## DataTable Options
1818

19-
ITables is a wrapper for the Javascript DataTables library, which means that you can use more or less directly the DataTables [options](https://datatables.net/options) from within Python.
19+
ITables is a wrapper for the JavaScript DataTables library, which means you can often use DataTables [options](https://datatables.net/options) directly within ITables.
2020

21-
Since ITables just maps these options to DataTables, you are invited to have a look at DataTable's great [documentation](https://datatables.net/), and to its huge collection of [examples](https://datatables.net/examples/index). The DataTable [forum](https://datatables.net/forums/) can be quite useful as well.
21+
Since ITables simply maps these options to DataTables, we encourage you to consult DataTables’ excellent [documentation](https://datatables.net/) and its extensive collection of [examples](https://datatables.net/examples/index). The DataTables [forum](https://datatables.net/forums/) can also be quite helpful.
2222

23-
A non-exhaustive list of the DataTable options, together with their expected types, is available at [`itables.typing.DataTableOptions`](https://github.com/mwouts/itables/blob/main/src/itables/typing.py).
23+
A non-exhaustive list of DataTables options, along with their expected types, is provided by `DataTableOptions` in [`itables.typing`](https://github.com/mwouts/itables/blob/main/src/itables/typing.py).
2424

25-
Option names and types are checked by default at run time when `typeguard>=4.4.1` is installed - you can deactivate this by setting `warn_on_undocumented_option=False`.
25+
## ITable Options
26+
27+
ITables adds a few options of its own, such as `connected`, `maxBytes`, `allow_html`, and others. An exhaustive list of these additional options is provided by `ITableOptions` in [`itables.typing`](https://github.com/mwouts/itables/blob/main/src/itables/typing.py).
28+
29+
## Default Values
2630

27-
If you see an option that you find useful and is not documented, or a type hint that is incorrect, please make a PR (and add an example to the documentation, too).
31+
The default values for these options are set in [`itables.options`](https://github.com/mwouts/itables/blob/main/src/itables/options.py). These defaults are used in each call to `to_html_datatable`, `show`, or `ITable`, unless a corresponding option is set locally—in which case, the local value takes precedence.
2832

29-
```{code-cell} ipython3
30-
:tags: [scroll-output]
33+
## Changing the Defaults
3134

32-
import inspect
35+
You can change the default options in your notebook or application with:
3336

37+
```python
3438
import itables
3539

36-
print(inspect.getsource(itables.typing.DataTableOptions))
40+
itables.options.maxBytes = "128KB"
3741
```
3842

39-
## ITable Options
40-
41-
ITables itself adds a few options like `connected`, `maxBytes`, `allow_html` etc.
43+
## Configuration File
4244

43-
The ITable options are documented at [`itables.typing.ITableOptions`](https://github.com/mwouts/itables/blob/main/src/itables/typing.py):
45+
Since v2.5.0, ITable can load its default options from a configuration file. The configuration file is identified using `get_config_file` from [`itables.config`](https://github.com/mwouts/itables/blob/main/src/itables/config.py). It can be:
4446

45-
```{code-cell} ipython3
46-
:tags: [scroll-output]
47+
- The file pointed to by the environment variable `ITABLES_CONFIG`, if set and non-empty (if the variable is an empty string, no configuration file is used)
48+
- An `itables.toml` file in the current or a parent directory
49+
- A `tool.itables` section in a `pyproject.toml` file in the current or a parent directory
4750

48-
print(inspect.getsource(itables.typing.ITableOptions))
51+
A sample configuration file could look like this:
52+
```
53+
# itables.toml
54+
classes = ["display", "nowrap", "compact"]
55+
buttons = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]
4956
```
5057

51-
## Default values
52-
53-
Some of the options have a default value set in [`itables.options`](https://github.com/mwouts/itables/blob/main/src/itables/options.py). You can change these defaults easily, and even set defauts for the options that don't have one yet with e.g.
54-
55-
```python
56-
import itables
57-
58-
itables.options.maxBytes = "128KB"
58+
Add this to use the [column control](column_control.md) extension:
59+
```
60+
[[columnControl]]
61+
target = 0
62+
content = ["order"]
63+
[[columnControl]]
64+
target = "tfoot"
65+
content = ["search"]
66+
67+
[ordering]
68+
indicators = false
69+
handler = false
5970
```
6071

61-
```{code-cell} ipython3
62-
:tags: [scroll-output]
72+
## Option Names and Type Checks
6373

64-
print(inspect.getsource(itables.options))
65-
```
74+
Option names and types are checked by default at runtime when `typeguard>=4.4.1` is installed. You can disable this by setting `warn_on_undocumented_option=False`.
75+
76+
If you find an option that is useful but undocumented, or if you notice an incorrect type hint, please submit a PR (and consider adding an example to the documentation, too).

docs/py/options/buttons.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@
3636
#
3737
# As always, it is possible to set default values for these parameters by setting these on `itables.options`. For instance, set
3838
# ```python
39-
# itables.options.buttons = ["copyHtml5", "csvHtml5", "excelHtml5"]
39+
# itables.options.buttons = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]
4040
# ```
4141
# to get the buttons for all your tables.
4242
#
43+
# You can also add
44+
# ```
45+
# buttons = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]
46+
# ```
47+
# to your `itables.toml` configuration file.
48+
#
4349
#
4450
# By default, the exported file name is the name of the HTML page. To change it, set a
4551
# [`title` option](https://datatables.net/extensions/buttons/examples/html5/filename.html) on the buttons, like

docs/py/options/classes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@
4141

4242
# %% tags=["full-width"]
4343
itables.show(df, classes="display nowrap cell-border")
44+
45+
# %% [markdown]
46+
# ```tip
47+
# You can change the default for all your notebooks and apps by creating an `itables.toml` file in the current or a parent directory, with e.g. this content:
48+
# ~~~
49+
# classes = ["display", "nowrap", "compact"]
50+
# ~~~
51+
# ```

docs/py/options/column_control.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,18 @@
7272
],
7373
ordering={"indicators": False, "handler": False},
7474
)
75+
76+
# %% [markdown]
77+
# As usual, you can make this the default by either setting `itables.options.columnControl` in your notebook or application, or by adding this to your `itables.toml` configuration file:
78+
# ```
79+
# [[columnControl]]
80+
# target = 0
81+
# content = ["order"]
82+
# [[columnControl]]
83+
# target = "tfoot"
84+
# content = ["search"]
85+
#
86+
# [ordering]
87+
# indicators = false
88+
# handler = false
89+
# ```

docs/py/options/options.py

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# ---
22
# jupyter:
33
# jupytext:
4-
# default_lexer: ipython3
54
# formats: docs///md:myst,docs/py///py:percent
65
# notebook_metadata_filter: -jupytext.text_representation.jupytext_version
76
# text_representation:
@@ -19,43 +18,61 @@
1918
#
2019
# ## DataTable Options
2120
#
22-
# ITables is a wrapper for the Javascript DataTables library, which means that you can use more or less directly the DataTables [options](https://datatables.net/options) from within Python.
21+
# ITables is a wrapper for the JavaScript DataTables library, which means you can often use DataTables [options](https://datatables.net/options) directly within ITables.
2322
#
24-
# Since ITables just maps these options to DataTables, you are invited to have a look at DataTable's great [documentation](https://datatables.net/), and to its huge collection of [examples](https://datatables.net/examples/index). The DataTable [forum](https://datatables.net/forums/) can be quite useful as well.
23+
# Since ITables simply maps these options to DataTables, we encourage you to consult DataTables’ excellent [documentation](https://datatables.net/) and its extensive collection of [examples](https://datatables.net/examples/index). The DataTables [forum](https://datatables.net/forums/) can also be quite helpful.
2524
#
26-
# A non-exhaustive list of the DataTable options, together with their expected types, is available at [`itables.typing.DataTableOptions`](https://github.com/mwouts/itables/blob/main/src/itables/typing.py).
25+
# A non-exhaustive list of DataTables options, along with their expected types, is provided by `DataTableOptions` in [`itables.typing`](https://github.com/mwouts/itables/blob/main/src/itables/typing.py).
2726
#
28-
# Option names and types are checked by default at run time when `typeguard>=4.4.1` is installed - you can deactivate this by setting `warn_on_undocumented_option=False`.
29-
#
30-
# If you see an option that you find useful and is not documented, or a type hint that is incorrect, please make a PR (and add an example to the documentation, too).
31-
32-
# %% tags=["scroll-output"]
33-
import inspect
34-
35-
import itables
36-
37-
print(inspect.getsource(itables.typing.DataTableOptions))
38-
39-
# %% [markdown]
4027
# ## ITable Options
4128
#
42-
# ITables itself adds a few options like `connected`, `maxBytes`, `allow_html` etc.
29+
# ITables adds a few options of its own, such as `connected`, `maxBytes`, `allow_html`, and others. An exhaustive list of these additional options is provided by `ITableOptions` in [`itables.typing`](https://github.com/mwouts/itables/blob/main/src/itables/typing.py).
4330
#
44-
# The ITable options are documented at [`itables.typing.ITableOptions`](https://github.com/mwouts/itables/blob/main/src/itables/typing.py):
45-
46-
# %% tags=["scroll-output"]
47-
print(inspect.getsource(itables.typing.ITableOptions))
48-
49-
# %% [markdown]
50-
# ## Default values
31+
# ## Default Values
32+
#
33+
# The default values for these options are set in [`itables.options`](https://github.com/mwouts/itables/blob/main/src/itables/options.py). These defaults are used in each call to `to_html_datatable`, `show`, or `ITable`, unless a corresponding option is set locally—in which case, the local value takes precedence.
5134
#
52-
# Some of the options have a default value set in [`itables.options`](https://github.com/mwouts/itables/blob/main/src/itables/options.py). You can change these defaults easily, and even set defauts for the options that don't have one yet with e.g.
35+
# ## Changing the Defaults
36+
#
37+
# You can change the default options in your notebook or application with:
5338
#
5439
# ```python
5540
# import itables
5641
#
5742
# itables.options.maxBytes = "128KB"
5843
# ```
59-
60-
# %% tags=["scroll-output"]
61-
print(inspect.getsource(itables.options))
44+
#
45+
# ## Configuration File
46+
#
47+
# Since v2.5.0, ITable can load its default options from a configuration file. The configuration file is identified using `get_config_file` from [`itables.config`](https://github.com/mwouts/itables/blob/main/src/itables/config.py). It can be:
48+
#
49+
# - The file pointed to by the environment variable `ITABLES_CONFIG`, if set and non-empty (if the variable is an empty string, no configuration file is used)
50+
# - An `itables.toml` file in the current or a parent directory
51+
# - A `tool.itables` section in a `pyproject.toml` file in the current or a parent directory
52+
#
53+
# A sample configuration file could look like this:
54+
# ```
55+
# # itables.toml
56+
# classes = ["display", "nowrap", "compact"]
57+
# buttons = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]
58+
# ```
59+
#
60+
# Add this to use the [column control](column_control.md) extension:
61+
# ```
62+
# [[columnControl]]
63+
# target = 0
64+
# content = ["order"]
65+
# [[columnControl]]
66+
# target = "tfoot"
67+
# content = ["search"]
68+
#
69+
# [ordering]
70+
# indicators = false
71+
# handler = false
72+
# ```
73+
#
74+
# ## Option Names and Type Checks
75+
#
76+
# Option names and types are checked by default at runtime when `typeguard>=4.4.1` is installed. You can disable this by setting `warn_on_undocumented_option=False`.
77+
#
78+
# If you find an option that is useful but undocumented, or if you notice an incorrect type hint, please submit a PR (and consider adding an example to the documentation, too).

0 commit comments

Comments
 (0)