ploomber.SourceLoader¶
- class ploomber.SourceLoader(path=None, module=None)¶
Load source files using a jinja2.Environment
Data pipelines usually rely on non-Python source code such as SQL scripts, SourceLoader provides a convenient way of loading them. This serves two purposes: 1) Avoid hardcoded paths to files and 2) Allows using advanced jinja2 features that require an Environment object such as macros (under the hood, SourceLoader initializes an Environment with a FileSystemLoader) SourceLoader returns ploomber.Placeholder objects that can be directly passed to Tasks in the source parameter
- Parameters
path (str, pathlib.Path, optional) – Path (or list of) to load files from. Required if module is None
module (str or module, optional) – Module name as dotted string or module object. Preprends to path parameter
Examples
>>> from ploomber import SourceLoader >>> loader = SourceLoader('path/to/templates/') >>> loader['load_customers.sql'] >>> loader.get_template('load_customers.sql')
Methods
get
(key)Load template, returns None if it doesn’ exist
get_template
(name)Load a template by name
path_to
(key)Return the path to a template, even if it doesn’t exist
- get(key)¶
Load template, returns None if it doesn’ exist
- get_template(name)¶
Load a template by name
- Parameters
name (str or pathlib.Path) – Template to load
- path_to(key)¶
Return the path to a template, even if it doesn’t exist