Skip to main content

No project description provided

Project description

Function framework for Python

NOTICE:

The code has been rewritten for 0.3.0, but the documentation has not been updated!

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 typing import Any

from pyfun_events import Handle, Get

counter = 0


# @Handle assumes json body. For event bodies which are a simple string, try:
# @Handle(str)
@Handle
def DoEvent(data: Any, context: dict):
    logging.info(data)
    counter = counter + 1


@Handle(path="/secret")
def DoOther(data: Any, context: dict) -> v1.Event:
    if data.get("handshake") == "backwards":
        counter = 0
        return v1.Event().SetData("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 Flask 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

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

http-containerize-0.3.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

http_containerize-0.3.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file http-containerize-0.3.1.tar.gz.

File metadata

  • Download URL: http-containerize-0.3.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.4

File hashes

Hashes for http-containerize-0.3.1.tar.gz
Algorithm Hash digest
SHA256 53c3f6623ac2a4bd5a2a423b450a41a6a937c7d015fb7c0c9b6c09344da23e02
MD5 a34b7e996b423ae87aa9d9173ba7e300
BLAKE2b-256 764ef785ae7a8327160335a85cdc3e958ece33e2fa7b8a64a3757b5e928889ac

See more details on using hashes here.

File details

Details for the file http_containerize-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: http_containerize-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.4

File hashes

Hashes for http_containerize-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 65bdffb1397bfa0ea1dc9a487c9809d7226990c275752080c80614b77d84f4b3
MD5 90d4848459689c9a7a9792b1d73b96d4
BLAKE2b-256 e16d8901edc96312961648e62c03616daab0d66e31d14515e4e71b1b5763e5f3

See more details on using hashes here.

Supported by

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