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 HTTP events, including 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).

The framework uses reflection to find a suitable function to wrap; it should not be necessary to import any of the following modules in your own code unless you want (e.g. for type definitions):

  • frameork (this module; on PyPi as http-containerize)
  • flask
  • cloudevents

Instead, simply ensure that you have a single non-_ prefixed function which uses some combination of the following:

  • HTTP request arguments (named req, request, body, headers or of the flask.Request type)
  • CloudEvent arguments (named event, payload, data, attributes or of the cloudevents.sdk.event.v1.Event type)

Usage:

import logging
from typing import Any


counter = 0


def DoEvent(data: Any, attributes: dict, req: Any):
    global counter
    counter = counter + 1

    logging.info(f"Got data: {data}")
    logging.info(f"From {req.origin}, my {counter}th request!")

    attributes["type"] = "com.example.reply"
    attributes["datacontenttype"] = "text/plain"

    return attributes, "It's a demo"

Building into a container:

You can use the packeto buildpacks if you add http-containerize>=0.4.0 to your requirements.txt:

pack build pytestapp --buildpack  ekanderson/pyfun:0.1.1 --builder paketobuildpacks/builder:base

You can then invoke it via:

docker run --rm -p 8080:8080 -e 8080 pytestapp

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.4.3.tar.gz (4.3 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.4.3-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: http-containerize-0.4.3.tar.gz
  • Upload date:
  • Size: 4.3 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.4.3.tar.gz
Algorithm Hash digest
SHA256 0d092de2e8b17a6d7010bfb24dfb26447ff2e50503eb51e56a4da59c472c5077
MD5 7d19ad2a63553548faebb45ed0b6fd1f
BLAKE2b-256 9fdb75f9d397d05157daa663c6f5d1dd84043659f351386f3a8ac056daef0bea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: http_containerize-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 9.0 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.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5ada27b00618f631a80ff3888225c0712a3107da2426d70706361d71c019aaec
MD5 dd035f58dbd80b759f88986fe9473cad
BLAKE2b-256 686951f13d7d312277d45a12c89fe56c48cb435f7740d94660d2a4dc64e99112

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.3 This release

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.15

2 files

0.3.14

2 files

0.3.13

2 files

0.3.12

2 files

0.3.11

2 files

0.3.10

2 files

0.3.9

2 files

0.3.8

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

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