Skip to main content

Library for creating Functions for CIM Database Cloud.

Project description

CONTACT Logo Functions-SDK for Python

This SDK provides the csfunctions library for developing Functions with Python.

Functions are deeply integrated in the CIM Database Cloud Webhooks technology. They are designed to work seamlessly together. The goal is to allow implementing custom business logic in a CIM Database Cloud SaaS application without leaving the CONTACT Cloud and without the need to create and maintain a separate infrastructure.

Documentation: https://cslab.github.io/functions-sdk-python/

Source code: https://github.com/cslab/functions-sdk-python

Requirements

Python 3.10+

csfunctions is build with Pydantic 2

Installation

Install using pip:

pip install contactsoftware-functions

Usage

Build the Function

Folder content of a minimal example for a Function implementation:

  my_example_functions/
  ├── environment.yaml
  ├── mymodule.py
  └── requirements.txt

Code for a Function:

import requests
import json

from csfunctions import MetaData, Service
from csfunctions.events import DocumentReleaseEvent

def send_doc_to_erp(metadata: MetaData, event: DocumentReleaseEvent, service: Service):
  # iterate over the documents contained in the event
  for document in event.data.documents:
    # create the payload for our (fictional ERP system)
    payload = json.dumps({
      "document_number": document.z_nummer,
      "document_index": document.z_index,
      "document_title": document.titel
    })
    res = requests.post("https://example.com", data=payload)
    if res.status_code != 200:
      return ValueError(f"Failed to upload document to ERP. Got response code {res.status_code}")

Environment file to define runtime and Function entrypoints:

runtime: python3.10
version: v1
functions:
  - name: send_doc_to_erp
    entrypoint: mymodule.send_doc_to_erp

Define requirements:

contactsoftware-functions

Deploy the Code

To deploy the Code you first need to install the contactsoftware-functions-client and retrieve developer credentials in the CONTACT Portal.

Install client:

pip install contactsoftware-functions-client

Login:

cfc login

Create a new environment:

cfc env create myenv

Upload code into new environment:

cfc env deploy myenv

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

contactsoftware_functions-0.8.2.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

contactsoftware_functions-0.8.2-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file contactsoftware_functions-0.8.2.tar.gz.

File metadata

  • Download URL: contactsoftware_functions-0.8.2.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.10 Linux/6.5.0-1025-azure

File hashes

Hashes for contactsoftware_functions-0.8.2.tar.gz
Algorithm Hash digest
SHA256 6e417e3d9837e649afd4d39ce786e5a6ceff3dafd0b17c91959c07063839bec0
MD5 1000cab65e84a1d47be251a824dc1407
BLAKE2b-256 60aaef54f080e9c4cbac3a1495092df74f7bb4e0229910473b6750e34984a4a5

See more details on using hashes here.

File details

Details for the file contactsoftware_functions-0.8.2-py3-none-any.whl.

File metadata

File hashes

Hashes for contactsoftware_functions-0.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dc3c0a9daca51043d82ad9309b5eac9a1dcbde08de435084859c4a96959cf1b7
MD5 b617609a587321674066ba991a175095
BLAKE2b-256 9361f24885607b0a2f74d0107c6a82613e5545acc9b808476bd5870e9b5763cc

See more details on using hashes here.

Supported by

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