Skip to main content

No project description provided

Project description

Function framework for Python

This framework provides a mechanism to write Function-as-a-Service style code in Python for handling CloudEvents delivered via HTTP.

This framework is primarily intended to work with Knative, but also works to provide a generic server for handling CloudEvents over HTTP (e.g. from Kubernetes or on a local machine).


import logging

from pyfun_events import Handle,Get

counter = 0

# @Handle assumes json body. For string or other body conversion, try:
# @Handle(str)
def DoEvent(data: str, context: dict):
    counter = counter + 1

def DoOther(data: str, context: dict):
    if data.get("handshake") == "backwards":
        counter = 0
        return "It's gone, man"

def Info():
    return "Got {0}".format(counter)

def Party():
    return "<BLINK>Like it's 1999</BLINK>"

Running manually

Copy packaging/ and packaging/requirements.txt into your application directory alongside your other code. You can then start the Flaskk webserver running your function with:

flask run

Running on Knative

There is a supplied build template in packaging/build-template.yaml, which you can apply to your cluster with:

kubectl apply -f packaging/build-template.yaml


kubectl apply -f

Then update your Knative Service like so:

kind: Service
  name: message-dumper
+     build:
+       source:
+          git:
+            url: YOUR_REPO_URL
+            revision: HEAD
+       template:
+         name: pyfn
+         arguments:
+         - name: IMAGE
+           value: YOUR_DOCKER_IMAGE
+       serviceAccountName: builder
        image: YOUR_DOCKER_IMAGE

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

pyfun_events-0.2.1.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

pyfun_events-0.2.1-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

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