Skip to main content
Version: 10 - TBD

Third-Party Python Modules

Engine flows are written in Python 3.8. In addition to all standard Python modules several third-party modules are available.

Use Cases

The third-party Python modules serve different purposes. Please refer to their individual documentation pages which are linked below.

Available Third-Party Python Modules

The following third-party Python modules are available to be used in your flow scripts:

Module nameDescriptionLinks
arrowBetter dates & times for Pythonhttps://arrow.readthedocs.io/en/latest/
chevronA Python implementation of mustachehttps://github.com/noahmorrison/chevron
gensonGenSON is a powerful, user-friendly JSON Schema generator built in Pythonhttps://github.com/wolverdude/GenSON
holidaysGenerate and work with holidays in Pythonhttps://github.com/dr-prodigy/python-holidays
html5libStandards-compliant library for parsing and serializing HTML documents and fragments in Pythonhttps://github.com/html5lib/html5lib-python
iso3166Standalone ISO 3166-1 country definitionshttps://github.com/deactivated/python-iso3166
jinja2A very fast and expressive template enginehttps://github.com/pallets/jinja
jsonschemaAn implementation of the JSON Schema specification for Pythonhttps://github.com/python-jsonschema/jsonschema
lxmlThe lxml XML toolkit for Pythonhttps://github.com/lxml/lxml
markdownA Python implementation of John Gruber’s Markdown with Extension support.https://github.com/Python-Markdown/markdown
mathplotlibplotting with Pythonhttps://github.com/matplotlib/matplotlib
numpyThe fundamental package for scientific computing with Pythonhttps://github.com/numpy/numpy
pandasFlexible and powerful data analysis / manipulation library for Pythonhttps://github.com/pandas-dev/pandas
passlibThe Passlib Python Libraryhttps://passlib.readthedocs.io/en/stable/
pdf2imageA python module that wraps the pdftoppm utility to convert PDF to PIL Image objecthttps://github.com/Belval/pdf2image
pdftotextSimple PDF text extractionhttps://github.com/jalan/pdftotext
phonenumbersPython port of Google's libphonenumberhttps://github.com/daviddrysdale/python-phonenumbers
PillowPython Imaging Libraryhttps://github.com/python-pillow/Pillow
pycryptodomexA self-contained cryptographic library for Pythonhttps://github.com/Legrandin/pycryptodome
pyjwtJSON Web Token implementation in Pythonhttps://github.com/jpadilla/pyjwt
pyotpPython One-Time Password Libraryhttps://github.com/pyauth/pyotp
pyqueryA jquery-like library for pythonhttps://github.com/gawel/pyquery
python-dateutilUseful extensions to the standard Python datetime featureshttps://github.com/dateutil/dateutil
pytzWorld Timezone Definitions for Pythonhttps://pythonhosted.org/pytz/
pyyamlPyYAML-based module to produce pretty and readable YAML-serialized datahttps://github.com/mk-fg/pretty-yaml
ujsonUltra fast JSON decoder and encoder written in C with Python bindingshttps://github.com/ultrajson/ultrajson
yarlYet another URL libraryhttps://github.com/aio-libs/yarl
note

Contact us at info@cloudomation.com to request additional Python modules.

Examples

Parse a PDF File

You can access the content of PDF files directly in your flow script.

example

Access a date written in a PDF file

import re
import base64
import io
import pdftotext
import flow_api

def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
pdf_name = 'example.pdf'
# Open the Engine file object
pdf_file = system.file(pdf_name)
# Files contain binary content which is returned base64 encoded
file_base64 = pdf_file.get('content')
file_bytes = base64.b64decode(file_base64)
# Construct a `PDF` object from the bytes
pdf = pdftotext.PDF(io.BytesIO(file_bytes))
# Access the text of the first page of the PDF file
pdf_text = pdf[0]
# Clear the PDF object, so that the file object is closed
pdf = None
# Use a Regex to find the date
the_date = re.search(r'Date:\s*(\d{4}-[01]\d-[0-3]\d)', pdf_text).group(1)
this.log(the_date)
return this.success('all done')

Work with CSV Files

You can use the csv module to read CSV files into Python objects or write Python objects into CSV files.

example

Create a CSV file and send it by email.

import base64
import csv
import io
import flow_api

def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
fake_data_list = [
{'name': 'spam', 'number': 1},
{'name': 'eggs', 'number': 2},
{'name': 'foo', 'number': 3},
{'name': 'bar', 'number': 4},
]
result_file = io.StringIO()
csv_writer = csv.DictWriter(
result_file,
fieldnames=['name', 'number'],
)
csv_writer.writeheader()
for data in fake_data_list:
csv_writer.writerow(data)
csv_content = result_file.getvalue()
result_file.close()
result_file = None
csv_writer = None

system.file('result.csv').save_text_content(csv_content)

this.connect(
connector_type='SMTP',
from_='me@example.com',
to='you@example.com',
subject= 'Result',
text='See the attached file',
login='me@example.com',
password= '****',
smtp_host= 'SMTP.example.com',
smtp_port= 587,
use_tls= True,
attachments= [
'cloudomation:result.csv',
],
)

return this.success('all done')