Skip to main content

Python package The FuncFactory! Easily adaptable production grade code on the fly.

Project description

funcfactory logo

FuncFactory

Easily adaptable, Production grade, Python pipelines on the fly.

License: Apache 2.0 Pypi FuncFactory Py versions Build soda-sql


.. We got the Func, you got the Func, she got the Func, he got the Func .. !

What is it?

The FuncFactory is an open-source solution that creates and runs easily adaptable, production grade, python pipelines. Users simply configure the pipelines in simple yaml files and the steps of the pipelines in ordinary python functions. Once loaded in the FuncFactory the pipelines can be triggered and the result creation, loging and error handeling is taken care of by the Factor itself. Any developer that knows how to create python functions can therefore easily incorporate these into production grade python pipelines with a handful lines of code.

Idea

A principle often used in code is the storing of (function & class) config & parameters in yaml files. This package extends that idea by also storing the function implementation and order in yaml files. Users do not have to change a single line of python now to completely change the python pipeline. Resulting in highly adaptable and readable python pipelines.

Bringing code from the development fase into production often adds many very similar lines of code: error handeling, logging, result creation.. Often these can be reduced by the use of more complex python features like decorators. However the FuncFactory takes care of all that for you.

Where to get it

# PyPI
pip3 install funcfactory

Getting started

In the example below we make a complete python pipeline that compares checksums from a downloaded file and the source.

Step 1: Create desired functions

import requests as r
import sha256
def calc_checksum_url(url, **kwargs):
    """Function that calculates checksum of an url
    """
    response = r.get(url)
    assert response 
    checksum = sha256(response.content).hexdigest()
    return checksum, "Found checksum url"

def calc_checksum_file(file, **kwargs):
    """Function that calculates checksum of a file
    """
    with open(file, "rb") as file:
        checksum = sha256(file).hexdigest()
    return checksum, "Found checksum file"

Mind you:

  • FuncFactory specifically deals with assertion errors
  • **kwargs is always(!) needed for the steps to work properly
  • The first return object used for the step result
  • The second object will be added to the logging
  • The third object will be stored in the FuncFactory so it can be accessed by other steps

Step 2: Configure the yaml pipeline file

# Severity levels (Azure standard)
# CRITICAL = 4
# ERROR = 3
# WARNING = 2
# INFORMATION = 1
# VERBOSE = 0
DEFAULT:
  skip_file: False
  check_name: 'Checksum input files'
  significance: 2
  stop_run_on_fail: False

Step_1:
  severity_level: 4
  func_left: calc_checksum_file
  func_right: calc_checksum_url
  kwargs_left: {"file":"/user/data/input_file_1.csv"}
  kwargs_right: {"url":"https://www.my_input_data_url.com/input_file_1.csv",}

Step_2:
  severity_level: 4
  func_left: calc_checksum_file
  func_right: calc_checksum_url
  kwargs_left: {"file":"/user/data/input_file_2.csv"}
  kwargs_right: {"url":"https://www.my_input_data_url.com/input_file_2.csv"}
  • The default is used for general pipeline properties. After loading this the steps are executed.
  • An example is shown where two functions are checked against one another.
  • Single functions can also be made into steps by comparing the result with a function that only returns a single return code.

final step: Create the FuncFactory and run

from funcfactory import FuncFactory
import .my_check_functions as my_check_functions
import .more_check_functions as more_check_functions
# init the FuncFactory with the modules containing the functions from step 1
ff=FuncFactory(list_modules_functions=[my_check_functions, more_check_functions])

# Load (all) yaml files from step 2
ff.read_config_folder("./config_checks")

# optionally: load objects needed in your steps.
import xlrd
excel_workbook = xlrd.open_workbook(file_contents=file_excel)
ff.load_factory_objects(wb = excel_workbook)

# run pipelines
ff.run_func()

Contributors

Steven Zindel (Author)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

funcfactory-0.1.6.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

funcfactory-0.1.6-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file funcfactory-0.1.6.tar.gz.

File metadata

  • Download URL: funcfactory-0.1.6.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.4

File hashes

Hashes for funcfactory-0.1.6.tar.gz
Algorithm Hash digest
SHA256 46daca4920240186720fd3b36b1d417daed0274e640d493de980e139b81cc42d
MD5 d35e95834e0e5e9d4a5dd3b7a1d061b8
BLAKE2b-256 129b72e9e113009cdd7b812067082fe995e8ce66fc4f24b9f0786fade25b82cc

See more details on using hashes here.

File details

Details for the file funcfactory-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: funcfactory-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.4

File hashes

Hashes for funcfactory-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c2566d1c1684fa90aea633308507202dc349712a15fe0e808eab080e6502bfb0
MD5 7ea101b09685c49b966f7e85c5d8a91f
BLAKE2b-256 ea6e59d73f00d6d1dfe3727ed361d3523ef984a597aed6f5f884a7e8f82ce4e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page