Skip to content

_python

TasksPythonSettings

Bases: BaseModel

Configuration for the Python base interpreters to be used for task venvs.

For task collection to work, there must be one or more base Python interpreters available on your system.

ATTRIBUTE DESCRIPTION
default_version

Default task-collection Python version (must be a key of versions).

TYPE: NonEmptyStr

versions

Dictionary mapping Python versions to the corresponding interpreters. Example:

{
  "3.11": "/path/to/python3.11",
  "3.13": "/path/to/python3.13"
}

TYPE: dict[Literal['3.9', '3.10', '3.11', '3.12', '3.13', '3.14'], AbsolutePathStr]

pip_cache_dir

Argument for --cache-dir option of pip install, if set.

TYPE: AbsolutePathStr | None

Source code in fractal_server/tasks/config/_python.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class TasksPythonSettings(BaseModel):
    """
    Configuration for the Python base interpreters to be used for task venvs.

    For task collection to work, there must be one or more base Python
    interpreters available on your system.

    Attributes:
        default_version:
            Default task-collection Python version (must be a key of
            `versions`).
        versions:
            Dictionary mapping Python versions to the corresponding
            interpreters. Example:
            ```json
            {
              "3.11": "/path/to/python3.11",
              "3.13": "/path/to/python3.13"
            }
            ```
        pip_cache_dir:
            Argument for `--cache-dir` option of `pip install`, if set.
    """

    default_version: NonEmptyStr
    versions: dict[
        Literal[
            "3.9",
            "3.10",
            "3.11",
            "3.12",
            "3.13",
            "3.14",
        ],
        AbsolutePathStr,
    ]

    pip_cache_dir: AbsolutePathStr | None = None

    @model_validator(mode="after")
    def _validate_versions(self) -> Self:
        if self.default_version not in self.versions.keys():
            raise ValueError(
                f"The default Python version ('{self.default_version}') is "
                f"not available in {list(self.versions.keys())}."
            )

        return self