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 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  gcr.io/paketo-community/python --builder paketobuildpacks/builder:base

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.4.0.tar.gz (4.2 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.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: http-containerize-0.4.0.tar.gz
  • Upload date:
  • Size: 4.2 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.0.tar.gz
Algorithm Hash digest
SHA256 baa52968b64ac9239018e2a8d1a6d47884765f7762ab210a358fc98b767ba51e
MD5 47bf99ca6a721b231214551a8fbb7b03
BLAKE2b-256 1b6ac89bc540690d5fa60e81e8da59a3c7b09fdcf475f47a6cbd6c3c4f743ad3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: http_containerize-0.4.0-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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ce34012867c67e9b7296a28b8d6667c62c2e3ea2d72daa726b0c9733e9e9e1d
MD5 249b43b1c7d89fac6620fcfb1260f495
BLAKE2b-256 2120073ab721bd54e2013f7ae15cebd7485a2e9d960b6db0409b7661d8346148

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