pyprediktorutilities package
Subpackages
Submodules
pyprediktorutilities.file_transfer module
pyprediktorutilities.send_email module
- class pyprediktorutilities.send_email.SendEmail(server: str, port: int, username: str, password: str)[source]
Bases:
objectHelper function to send emails with attachments using SMTP
- Parameters:
- Returns:
SendEmail object
- Return type:
Object
- send_email(from_email: EmailStr, recipients: list[EmailStr], subject: str, body: str, files: list = [])[source]
_summary_
- Parameters:
- Raises:
ValueError – If no recipients are specified, or a file path contains a NUL byte or a path traversal sequence
FileNotFoundError – If a file in files does not exist
pyprediktorutilities.singleton module
pyprediktorutilities.templating module
- class pyprediktorutilities.templating.Templating(path: str)[source]
Bases:
objectSimple wrapper around a templating engine, allowing for easy rendering of templates such as XMLs and HTMLs. Build on top of Jinja2
- Parameters:
path (str) – The path to the folder containing the templates
- env
The environment to use for rendering
- Type:
jinja2.Environment
- Raises:
FileNotFoundError – If the folder does not exist
FileNotFoundError – If the template does not exist
Exception – If the template could not be rendered
Examples
>>> from pyprediktorutilities.templating import Templating >>> templating = Templating('templates') >>> templates = templating.list_templates() >>> template = templating.load_template('base.html') >>> rendered_template = templating.render(template, title='Home') >>> templating.render_to_file(template, 'output.html', title='Home')
- load_template(template: str) object[source]
Loads a template from the folder
- Parameters:
template (str) – The file name of the template to load
- Raises:
FileNotFoundError – If the template does not exist
ValueError – If the template name attempts to escape the templates folder
- Returns:
The template object
- Return type:
- render(template: str, **kwargs) str[source]
Render a template with the given arguments and return a string
- render_to_file(template: str, file: str, **kwargs) None[source]
Render a template with the given arguments and write to a file
- Parameters:
- Raises:
Exception – If the template could not be rendered
FileNotFoundError – If the template does not exist
ValueError – If file contains a NUL byte or a path traversal sequence
- Returns:
None
- Return type:
None