No project description provided
Project description
PyFunc
This package 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):
pyfunc(this module; on PyPi aspyfunc)flaskcloudevents
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,headersor of theflask.Requesttype) - CloudEvent arguments (named
event,payload,data,attributesor of thecloudevents.sdk.event.v1.Eventtype)
Usage:
import logging
from typing import Any
counter = 0
def handler(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"
Usage
To check the current working directory for a module called handler and function handler:
python -m pyfunc
To check the current working directory for a module called myhandler and function func:
PYTHON_HANDLER=myhandler.func python -m pyfunc
To check a specific directory ./myfuncs/http/ for a module called handler and function handler:
python -m pyfunc ./myfuncs/http/
To check a specific directory ./myfuncs/http/ for a module called myhandler and function func:
PYTHON_HANDLER=myhandler.func python -m pyfunc ./myfuncs/http/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfunc-invoker-0.1.0.tar.gz.
File metadata
- Download URL: pyfunc-invoker-0.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb01714ce627f157e4fe76a301cb6ae092f0f33b149f802c2dbdfe86a9660e49
|
|
| MD5 |
06584a6fea7015b7f278ea31edc51df2
|
|
| BLAKE2b-256 |
29b71ba62c715f04c8bcac4fd8ece3ca38f5a0a8ceba906faf2217890aa719b2
|
File details
Details for the file pyfunc_invoker-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyfunc_invoker-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb7c73803f5b80e9779b56fb346ac515fa21b24d4e6eb0dc20aa5474a697e0df
|
|
| MD5 |
4767e9e08e02eaf8b212c8295ad3144d
|
|
| BLAKE2b-256 |
78a859e2d39565d76edc42874198cac7f1bbae07f92d1a459230c79d2359dbb0
|