pyprediktorutilities package

Subpackages

Submodules

pyprediktorutilities.file_transfer module

class pyprediktorutilities.file_transfer.SFTPClient(server: str, username: str, password: str, port: int)[source]

Bases: object

An SFTP client to upload files to a remote server

Parameters:
  • server (AnyUrl) – The server address

  • username (str) – The username

  • password (str) – The password

  • port (int) – The port number

Returns:

SFTPClient object

Return type:

Object

upload(files: list[str], remote_directory: str)[source]

Upload the files to the remote directory, create the directory recursively if it does not exist (and the remote server allows it)

Parameters:
  • files (list[str]) – _description_

  • remote_directory (str) – _description_

pyprediktorutilities.send_email module

class pyprediktorutilities.send_email.SendEmail(server: str, port: int, username: str, password: str)[source]

Bases: object

Helper function to send emails with attachments using SMTP

Parameters:
  • server (str) – SMTP server address

  • port (int) – SMTP server port

  • username (str) – SMTP server username

  • password (str) – SMTP server password

Returns:

SendEmail object

Return type:

Object

send_email(from_email: EmailStr, recipients: list[EmailStr], subject: str, body: str, files: list = [])[source]

_summary_

Parameters:
  • from_email (email address) – The sender email address

  • recipients (list of email addresses) – list of one or more recipient email addresses

  • subject (str) – The email subject

  • body (str) – The email body

  • files (list, optional) – A list of paths to files to include. Defaults to [].

pyprediktorutilities.shared module

pyprediktorutilities.shared.request_from_api(rest_url: AnyUrl, method: Literal['GET', 'POST'], endpoint: str, data: str = None, params: dict = None, headers: dict = None, extended_timeout: bool = False) str[source]

Function to perform request against a REST API

Parameters:
  • rest_url (str) – The URL with trailing shash

  • method (str) – “GET” or “POST”

  • endpoint (str) – The last part of the url (without the leading slash)

  • data (str) – defaults to None but can contain the data to send to the endpoint

  • headers (str) – default to None but can contain the headers og the request

Returns:

The result if successfull

Return type:

JSON

pyprediktorutilities.shared.validate_file(file: str)[source]
pyprediktorutilities.shared.validate_folder(folder: str)[source]

pyprediktorutilities.singleton module

class pyprediktorutilities.singleton.SingletonMeta[source]

Bases: type

This is a thread-safe implementation of Singleton.

pyprediktorutilities.templating module

class pyprediktorutilities.templating.Templating(path: str)[source]

Bases: object

Simple 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

path

The path to the folder containing the templates

Type:

str

env

The environment to use for rendering

Type:

jinja2.Environment

Raises:

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')
list_templates() list[str][source]

Returns a list of templates in the folder

Returns:

A list of strings containing the template names

Return type:

list[str]

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

Returns:

The template object

Return type:

object

render(template: str, **kwargs) str[source]

Render a template with the given arguments and return a string

Parameters:
  • template (str) – The file name of the template to load

  • **kwargs – The arguments to pass to the template

Raises:

Exception – If the template could not be rendered

Returns:

The rendered template

Return type:

str

render_to_file(template: str, file: str, **kwargs) None[source]

Render a template with the given arguments and write to a file

Parameters:
  • template (str) – The file name of the template to load

  • file (str) – The path and file name of the file to write to

  • **kwargs – The arguments to pass to the template

Raises:
Returns:

None

Return type:

None

Module contents