TemplateFileLoader
Base classes¶
Name | Children | Inherits |
---|---|---|
NestedDictLoader jinjarope.configloaders A jinja loader for loading templates from nested dicts. |
⋔ Inheritance diagram¶
graph TD
94173637833664["configloaders.TemplateFileLoader"]
94173637836640["configloaders.NestedDictLoader"]
94173637890544["loaders.LoaderMixin"]
139866058043616["builtins.object"]
94173636407456["loaders.BaseLoader"]
94173637836640 --> 94173637833664
94173637890544 --> 94173637836640
139866058043616 --> 94173637890544
94173636407456 --> 94173637836640
139866058043616 --> 94173636407456
🛈 DocStrings¶
Bases: NestedDictLoader
A jinja loader for loading templates from config files.
This loader allows to access templates from config files. Config files often often resemble nested dicts when getting loaded / deserialized.
The loader will load config file from given path and will make it accessible in the
same way as the NestedDictLoader
. (esp. TOML is well-suited for this)
Config files can be loaded from any fsspec protocol URL.
Examples:
loader = TemplateFileLoader("http://path_to_toml_file.toml")
env = Environment(loader=loader)
env.get_template("example/template")
loader = TemplateFileLoader("path/to/file.json")
env = Environment(loader=loader)
env.get_template("example/template")
Source code in src/jinjarope/configloaders.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
__init__
¶
__init__(
path: str | PathLike[str],
fmt: Literal["toml", "json", "ini", "yaml"] | None = None,
sub_path: tuple[str, ...] | None = None,
)
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | PathLike[str]
|
Path / fsspec protocol URL to the file |
required |
fmt
|
Literal['toml', 'json', 'ini', 'yaml'] | None
|
Config file format. If None, try to auto-infer from file extension |
None
|
sub_path
|
tuple[str, ...] | None
|
An optional tuple of keys describing the "dictionary path" inside the file |
None
|
Source code in src/jinjarope/configloaders.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|