Skip to main content

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).

Usage:

import logging

from pyfun_events import Handle,Get

counter = 0


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


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


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


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

Running manually

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

FLASK_APP=config
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

or

kubectl apply -f https://github.com/evankanderson/pyfun/tree/master/packaging/build-template.yaml

Then update your Knative Service like so:

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
  name: message-dumper
spec:
  runLatest:
    configuration:
+     build:
+       source:
+          git:
+            url: YOUR_REPO_URL
+            revision: HEAD
+       template:
+         name: pyfn
+         arguments:
+         - name: IMAGE
+           value: YOUR_DOCKER_IMAGE
+       serviceAccountName: builder
  revisionTemplate:
    spec:
      container:
        image: YOUR_DOCKER_IMAGE

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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file pyfun_events-0.2.1.tar.gz.

File metadata

  • Download URL: pyfun_events-0.2.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.5.3

File hashes

Hashes for pyfun_events-0.2.1.tar.gz
Algorithm Hash digest
SHA256 cf8c300274f7872538c01ef92a228e437aac42ace13078e9fd7dd74bb2b25f5b
MD5 be22f907bb980dd1a55ab336b85ea655
BLAKE2b-256 b65aa907311bc55a4605e00922ff9e1e9c762cf85ce8519f426db2a51318e294

See more details on using hashes here.

File details

Details for the file pyfun_events-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pyfun_events-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.5.3

File hashes

Hashes for pyfun_events-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8b349f811a58ade8e0a9044596d444f3e02f5b435d3d0b5c497a8e120438d9ab
MD5 62c1b8c3f5496691da80b53d5429c2d9
BLAKE2b-256 11f0092b6e1078ad4e5e0d482285d4e6bd7435e13e3692b6c7d34c7939b343ec

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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