ofn-functions-framework


Nameofn-functions-framework JSON
Version 0.2.0rc1 PyPI version JSON
download
home_pagehttps://github.com/OpenFunction/functions-framework-python
SummaryAn open source FaaS (Function as a service) framework for writing portable Python functions.
upload_time2023-08-15 01:23:00
maintainer
docs_urlNone
authorOpenFunction
requires_python>=3.5, <4
license
keywords functions-framework
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Functions Framework for Python

[![PyPI version](https://badge.fury.io/py/ofn-functions-framework.svg)](https://badge.fury.io/py/ofn-functions-framework)

This project is inspired by [GCP functions-framework-python](https://github.com/GoogleCloudPlatform/functions-framework-python) .

An open source FaaS (Function as a service) framework for writing portable Python functions.

The Functions Framework lets you write lightweight functions that run in many different environments, including:

*   [OpenFunction](https://github.com/OpenFunction/OpenFunction)
*   [Knative](https://github.com/knative/)-based environments
*   [Dapr](https://dapr.io/)-based environments
*   Your local development machine

The framework allows you to go from:

```python
from functions_framework.context.user_context import UserContext

def hello(context: UserContext):
    return "Hello world!"
```

To:

```sh
curl http://my-url
# Output: Hello world!
```

All without needing to worry about writing an HTTP server or complicated request handling logic.

## Features

*   Spin up a local development server for quick testing
*   Invoke a function in response to a request
*   Portable between serverless platforms
*   Can integrate various data middlewares

## Installation

Install the Functions Framework via `pip`:

```sh
pip install ofn-functions-framework
```

Or, for deployment, add the Functions Framework to your `requirements.txt` file:

```
ofn-functions-framework==0.2.0
```

## Quickstarts

### Quickstart: HTTP Function (Hello World)

Create an `main.py` file with the following contents:

```python
from functions_framework.context.user_context import UserContext


def hello(context: UserContext):
    # context.get_http_request()
    return "Hello world!"
```

Export Function Context:

```shell
export FUNC_CONTEXT='{"name":"function_name","version":"v1","triggers":{"http":{"port":8080}}}'
```

Run the following command:

```sh
ff --source hello_world.py --target hello
```

Open http://localhost:8080/ in your browser and see *Hello world!*.

Or send requests to this function using `curl` from another terminal window:

```sh
curl localhost:8080
# Output: Hello world!
```

## Run your function on OpenFunction

![OpenFunction Platform Overview](https://openfunction.dev/openfunction-0.5-architecture.png)

Besides Knative function support, one notable feature of OpenFunction is embracing Dapr system, so far Dapr pub/sub and bindings have been support.

Dapr bindings allows you to trigger your applications or services with events coming in from external systems, or interface with external systems. OpenFunction [0.6.0 release](https://openfunction.dev/blog/2022/03/25/announcing-openfunction-0.6.0-faas-observability-http-trigger-and-more/) adds Dapr output bindings to its synchronous functions which enables HTTP triggers for asynchronous functions. For example, synchronous functions backed by the Knative runtime can now interact with middlewares defined by Dapr output binding or pub/sub, and an asynchronous function will be triggered by the events sent from the synchronous function.

Asynchronous function introduces Dapr pub/sub to provide a platform-agnostic API to send and receive messages. A typical use case is that you can leverage synchronous functions to receive an event in plain JSON or Cloud Events format, and then send the received event to a Dapr output binding or pub/sub component, most likely a message queue (e.g. Kafka, NATS Streaming, GCP PubSub, MQTT). Finally, the asynchronous function could be triggered from the message queue.

More details would be brought up to you in some quickstart samples, stay tuned.

## Configure the Functions Framework

You can configure the Functions Framework using command-line flags or environment variables. If you specify both, the environment variable will be ignored.

| Command-line flag | Environment variable | Description                                                  |
| ----------------- | -------------------- | ------------------------------------------------------------ |
| `--host`          | `HOST`               | The host on which the Functions Framework listens for requests. Default: `0.0.0.0` |
| `--port`          | `PORT`               | The port on which the Functions Framework listens for requests. Default: `8080` |
| `--target`        | `FUNCTION_TARGET`    | The name of the exported function to be invoked in response to requests. Default: `function` |
| `--source`        | `FUNCTION_SOURCE`    | The path to the file containing your function. Default: `main.py` (in the current working directory) |
| `--debug`         | `DEBUG`              | A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False` |
| `--dry-run`       | `DRY_RUN`            | A flag that allows for testing the function build from the configuration without creating a server. Default: `False` |

## Advanced Examples

More advanced guides can be found in the [`examples/`](examples/) directory.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/OpenFunction/functions-framework-python",
    "name": "ofn-functions-framework",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5, <4",
    "maintainer_email": "",
    "keywords": "functions-framework",
    "author": "OpenFunction",
    "author_email": "openfunction@kubesphere.io",
    "download_url": "https://files.pythonhosted.org/packages/b5/e4/7e201660fc55256aab18ff6daf5e6bd46bc83f6eb91f0c1ce12f56fb9f91/ofn-functions-framework-0.2.0rc1.tar.gz",
    "platform": null,
    "description": "# Functions Framework for Python\n\n[![PyPI version](https://badge.fury.io/py/ofn-functions-framework.svg)](https://badge.fury.io/py/ofn-functions-framework)\n\nThis project is inspired by [GCP functions-framework-python](https://github.com/GoogleCloudPlatform/functions-framework-python) .\n\nAn open source FaaS (Function as a service) framework for writing portable Python functions.\n\nThe Functions Framework lets you write lightweight functions that run in many different environments, including:\n\n*   [OpenFunction](https://github.com/OpenFunction/OpenFunction)\n*   [Knative](https://github.com/knative/)-based environments\n*   [Dapr](https://dapr.io/)-based environments\n*   Your local development machine\n\nThe framework allows you to go from:\n\n```python\nfrom functions_framework.context.user_context import UserContext\n\ndef hello(context: UserContext):\n    return \"Hello world!\"\n```\n\nTo:\n\n```sh\ncurl http://my-url\n# Output: Hello world!\n```\n\nAll without needing to worry about writing an HTTP server or complicated request handling logic.\n\n## Features\n\n*   Spin up a local development server for quick testing\n*   Invoke a function in response to a request\n*   Portable between serverless platforms\n*   Can integrate various data middlewares\n\n## Installation\n\nInstall the Functions Framework via `pip`:\n\n```sh\npip install ofn-functions-framework\n```\n\nOr, for deployment, add the Functions Framework to your `requirements.txt` file:\n\n```\nofn-functions-framework==0.2.0\n```\n\n## Quickstarts\n\n### Quickstart: HTTP Function (Hello World)\n\nCreate an `main.py` file with the following contents:\n\n```python\nfrom functions_framework.context.user_context import UserContext\n\n\ndef hello(context: UserContext):\n    # context.get_http_request()\n    return \"Hello world!\"\n```\n\nExport Function Context:\n\n```shell\nexport FUNC_CONTEXT='{\"name\":\"function_name\",\"version\":\"v1\",\"triggers\":{\"http\":{\"port\":8080}}}'\n```\n\nRun the following command:\n\n```sh\nff --source hello_world.py --target hello\n```\n\nOpen http://localhost:8080/ in your browser and see *Hello world!*.\n\nOr send requests to this function using `curl` from another terminal window:\n\n```sh\ncurl localhost:8080\n# Output: Hello world!\n```\n\n## Run your function on OpenFunction\n\n![OpenFunction Platform Overview](https://openfunction.dev/openfunction-0.5-architecture.png)\n\nBesides Knative function support, one notable feature of OpenFunction is embracing Dapr system, so far Dapr pub/sub and bindings have been support.\n\nDapr bindings allows you to trigger your applications or services with events coming in from external systems, or interface with external systems. OpenFunction [0.6.0 release](https://openfunction.dev/blog/2022/03/25/announcing-openfunction-0.6.0-faas-observability-http-trigger-and-more/) adds Dapr output bindings to its synchronous functions which enables HTTP triggers for asynchronous functions. For example, synchronous functions backed by the Knative runtime can now interact with middlewares defined by Dapr output binding or pub/sub, and an asynchronous function will be triggered by the events sent from the synchronous function.\n\nAsynchronous function introduces Dapr pub/sub to provide a platform-agnostic API to send and receive messages. A typical use case is that you can leverage synchronous functions to receive an event in plain JSON or Cloud Events format, and then send the received event to a Dapr output binding or pub/sub component, most likely a message queue (e.g. Kafka, NATS Streaming, GCP PubSub, MQTT). Finally, the asynchronous function could be triggered from the message queue.\n\nMore details would be brought up to you in some quickstart samples, stay tuned.\n\n## Configure the Functions Framework\n\nYou can configure the Functions Framework using command-line flags or environment variables. If you specify both, the environment variable will be ignored.\n\n| Command-line flag | Environment variable | Description                                                  |\n| ----------------- | -------------------- | ------------------------------------------------------------ |\n| `--host`          | `HOST`               | The host on which the Functions Framework listens for requests. Default: `0.0.0.0` |\n| `--port`          | `PORT`               | The port on which the Functions Framework listens for requests. Default: `8080` |\n| `--target`        | `FUNCTION_TARGET`    | The name of the exported function to be invoked in response to requests. Default: `function` |\n| `--source`        | `FUNCTION_SOURCE`    | The path to the file containing your function. Default: `main.py` (in the current working directory) |\n| `--debug`         | `DEBUG`              | A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False` |\n| `--dry-run`       | `DRY_RUN`            | A flag that allows for testing the function build from the configuration without creating a server. Default: `False` |\n\n## Advanced Examples\n\nMore advanced guides can be found in the [`examples/`](examples/) directory.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "An open source FaaS (Function as a service) framework for writing portable Python functions.",
    "version": "0.2.0rc1",
    "project_urls": {
        "Homepage": "https://github.com/OpenFunction/functions-framework-python"
    },
    "split_keywords": [
        "functions-framework"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1a64a682fb18fa95392809330c04befaefac1d28327c0b0d55027e839a59ca69",
                "md5": "84381389d4fe6f569e89ac6f0f3cfa78",
                "sha256": "1d0bb62bf68d35c8bae562a22048357b77a8c4b60332fcff5b950ae7b4a9675b"
            },
            "downloads": -1,
            "filename": "ofn_functions_framework-0.2.0rc1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "84381389d4fe6f569e89ac6f0f3cfa78",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5, <4",
            "size": 30591,
            "upload_time": "2023-08-15T01:22:58",
            "upload_time_iso_8601": "2023-08-15T01:22:58.637894Z",
            "url": "https://files.pythonhosted.org/packages/1a/64/a682fb18fa95392809330c04befaefac1d28327c0b0d55027e839a59ca69/ofn_functions_framework-0.2.0rc1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b5e47e201660fc55256aab18ff6daf5e6bd46bc83f6eb91f0c1ce12f56fb9f91",
                "md5": "cc16ebd75c609d156dcd69a98b913367",
                "sha256": "59014353a54139eed5b4df381e40c168e303469b323b9a4997d33f925bc13d9f"
            },
            "downloads": -1,
            "filename": "ofn-functions-framework-0.2.0rc1.tar.gz",
            "has_sig": false,
            "md5_digest": "cc16ebd75c609d156dcd69a98b913367",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5, <4",
            "size": 20001,
            "upload_time": "2023-08-15T01:23:00",
            "upload_time_iso_8601": "2023-08-15T01:23:00.706120Z",
            "url": "https://files.pythonhosted.org/packages/b5/e4/7e201660fc55256aab18ff6daf5e6bd46bc83f6eb91f0c1ce12f56fb9f91/ofn-functions-framework-0.2.0rc1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-15 01:23:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "OpenFunction",
    "github_project": "functions-framework-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "ofn-functions-framework"
}
        
Elapsed time: 0.12069s