# fdk-asgi
[![pipeline status](https://github.com/bjoern-reetz/fdk-asgi/actions/workflows/publish.yml/badge.svg?main)](https://github.com/bjoern-reetz/fdk-asgi/actions/workflows/publish.yml)
[![latest package version](https://img.shields.io/pypi/v/fdk-asgi)](https://pypi.org/project/fdk-asgi/)
[![supported python versions](https://img.shields.io/pypi/pyversions/fdk-asgi)](https://www.python.org/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/fdk-asgi)](https://pypistats.org/packages/fdk-asgi)
[![license](./images/license.svg)](./LICENSE)
[![source files coverage](./images/coverage.svg)](https://coverage.readthedocs.io/)
[![ruff](./images/ruff.svg)](https://docs.astral.sh/ruff)
[![mypy](./images/mypy.svg)](https://www.mypy-lang.org/)
[![pre-commit](./images/pre-commit.svg)](https://pre-commit.com/)
An alternative FDK to easily run any ASGI application on OCI Functions behind an API Gateway.
## Basic usage
Use it just like uvicorn. The fdk-asgi-serve command wraps your ASGI app with a middleware
that translates from/to the Fn protocol and starts a server that respects runtime Fn configuration,
e.g. listens on a unix-socket etc.
```bash
pip install fdk-asgi[cli]
fdk-asgi-serve package.module:app
```
If you install the package without extras, Typer and uvicorn dependencies are skipped.
This is particularly useful if you want to use another ASGI server
and just need the ASGI middleware this package provides.
## Full usage
```
fdk-asgi-serve --help
Usage: fdk-asgi-serve [OPTIONS] APP
Arguments:
APP [required]
Options:
--uds TEXT Path to the UNIX domain socket, prefixed
with "unix:". This will be managed by the Fn
Server. [env var: FN_LISTENER; default:
unix:./fdk-asgi.socket]
--loop [none|auto|asyncio|uvloop]
[env var: FDK_ASGI_LOOP; default: none]
--http [auto|h11|httptools] [env var: FDK_ASGI_HTTP; default: auto]
--lifespan [auto|on|off] [env var: FDK_ASGI_LIFESPAN; default: auto]
--env-file PATH Read configuration from an env file. Only
affects the ASGI app, not the FDK/Server!
[env var: FDK_ASGI_ENV_FILE]
--log-config PATH [env var: FDK_ASGI_LOG_CONFIG]
--log-level TEXT [env var: FDK_ASGI_LOG_LEVEL]
--proxy-headers / --no-proxy-headers
Enable/Disable X-Forwarded-Proto,
X-Forwarded-For, X-Forwarded-Port to
populate remote address info. [env var:
FDK_ASGI_PROXY_HEADERS; default: proxy-
headers]
--server-header / --no-server-header
[env var: FDK_ASGI_SERVER_HEADER; default:
server-header]
--date-header / --no-date-header
[env var: FDK_ASGI_DATE_HEADER; default:
date-header]
--prefix TEXT Strips the given prefix from URL paths. Also
sets root_path to this value. [env var:
FDK_ASGI_PREFIX]
--timeout-keep-alive INTEGER [env var: FDK_ASGI_TIMEOUT_KEEP_ALIVE;
default: 5]
--factory / --no-factory Treat APP as an application factory, i.e. a
() -> <ASGI app> callable. [env var:
FDK_ASGI_FACTORY; default: no-factory]
--h11-max-incomplete-event-size INTEGER
[env var:
FDK_ASGI_H11_MAX_INCOMPLETE_EVENT_SIZE]
--install-completion [bash|zsh|fish|powershell|pwsh]
Install completion for the specified shell.
--show-completion [bash|zsh|fish|powershell|pwsh]
Show completion for the specified shell, to
copy it or customize the installation.
--help Show this message and exit.
```
## Documentation on the Open Fn Project and OCI Functions
Example request:
```
POST /call HTTP/1.1
Fn-Call-Id : 12345678910
Fn-Deadline: <date/time>
Fn-Http-Request-Url: https://my.fn.com/t/hello/world
Fn-Http-Method: PUT
Fn-Http-H-Custom-Header: foo
Content-type: text/plain
<Body here>
```
Example Response:
```
HTTP/1.1 200 OK
Fn-Http-Status: 204
Fn-Http-H-My-Header: foo
Fn-Fdk-Version: fdk-go/0.0.42
Content-type: text/plain
<Body here>
```
For more info see [Fn container contract](https://github.com/fnproject/docs/blob/master/fn/develop/fn-format.md).
Notes:
- 0666 contract can be fulfilled by `gunicorn --umask 0666`.
### Default Environment Variables
Here is the list of automatically generated environment variables that are available to your functions.
| Fn Generated Var | Sample Value | Description |
|------------------|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `FN_APP_ID` | `01NNNNNNNNNG8G00GZJ0000001` | The application ID for the app the current function is contained in. |
| `FN_FN_ID` | `01DYNNNNNNNG8G00GZJ0000002` | The ID of the current function |
| `FN_FORMAT` | `http-stream` | Communications protocol. **(Deprecated)** |
| `FN_LISTENER` | `unix:/tmp/iofs/lsnr.sock` | The Unix socket address (prefixed with “unix:”) on the file system that the FDK should create to listen for requests. The platform will guarantee that this directory is writable to the function. FDKs must not write any other data than the unix socket to this directory. |
| `FN_MEMORY` | `128` | The maximum memory of the function in MB. |
| `FN_TYPE` | `sync` | The type of function. Always sync currently. |
Source: [Fn Project: Using Config Variables and Environment Variables](https://fnproject.io/tutorials/basics/UsingRuntimeContext/#UsingConfigVariablesandEnvironmentVariables)
Raw data
{
"_id": null,
"home_page": "https://github.com/bjoern-reetz/fdk-asgi/",
"name": "fdk-asgi",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "oci, functions, fnproject, runtime, asgi",
"author": "Bj\u00f6rn Reetz",
"author_email": "git@bjoern-reetz.de",
"download_url": "https://files.pythonhosted.org/packages/3e/81/d471e5166b3c2ee8d53d8cb1c2ac61e4056b639066be85b21963583d5c69/fdk_asgi-0.7.2.tar.gz",
"platform": null,
"description": "# fdk-asgi\n\n[![pipeline status](https://github.com/bjoern-reetz/fdk-asgi/actions/workflows/publish.yml/badge.svg?main)](https://github.com/bjoern-reetz/fdk-asgi/actions/workflows/publish.yml)\n[![latest package version](https://img.shields.io/pypi/v/fdk-asgi)](https://pypi.org/project/fdk-asgi/)\n[![supported python versions](https://img.shields.io/pypi/pyversions/fdk-asgi)](https://www.python.org/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/fdk-asgi)](https://pypistats.org/packages/fdk-asgi)\n[![license](./images/license.svg)](./LICENSE)\n[![source files coverage](./images/coverage.svg)](https://coverage.readthedocs.io/)\n[![ruff](./images/ruff.svg)](https://docs.astral.sh/ruff)\n[![mypy](./images/mypy.svg)](https://www.mypy-lang.org/)\n[![pre-commit](./images/pre-commit.svg)](https://pre-commit.com/)\n\nAn alternative FDK to easily run any ASGI application on OCI Functions behind an API Gateway.\n\n## Basic usage\n\nUse it just like uvicorn. The fdk-asgi-serve command wraps your ASGI app with a middleware\nthat translates from/to the Fn protocol and starts a server that respects runtime Fn configuration,\ne.g. listens on a unix-socket etc.\n\n```bash\npip install fdk-asgi[cli]\nfdk-asgi-serve package.module:app\n```\n\nIf you install the package without extras, Typer and uvicorn dependencies are skipped.\nThis is particularly useful if you want to use another ASGI server\nand just need the ASGI middleware this package provides.\n\n## Full usage\n\n```\nfdk-asgi-serve --help\nUsage: fdk-asgi-serve [OPTIONS] APP\n\nArguments:\n APP [required]\n\nOptions:\n --uds TEXT Path to the UNIX domain socket, prefixed\n with \"unix:\". This will be managed by the Fn\n Server. [env var: FN_LISTENER; default:\n unix:./fdk-asgi.socket]\n --loop [none|auto|asyncio|uvloop]\n [env var: FDK_ASGI_LOOP; default: none]\n --http [auto|h11|httptools] [env var: FDK_ASGI_HTTP; default: auto]\n --lifespan [auto|on|off] [env var: FDK_ASGI_LIFESPAN; default: auto]\n --env-file PATH Read configuration from an env file. Only\n affects the ASGI app, not the FDK/Server!\n [env var: FDK_ASGI_ENV_FILE]\n --log-config PATH [env var: FDK_ASGI_LOG_CONFIG]\n --log-level TEXT [env var: FDK_ASGI_LOG_LEVEL]\n --proxy-headers / --no-proxy-headers\n Enable/Disable X-Forwarded-Proto,\n X-Forwarded-For, X-Forwarded-Port to\n populate remote address info. [env var:\n FDK_ASGI_PROXY_HEADERS; default: proxy-\n headers]\n --server-header / --no-server-header\n [env var: FDK_ASGI_SERVER_HEADER; default:\n server-header]\n --date-header / --no-date-header\n [env var: FDK_ASGI_DATE_HEADER; default:\n date-header]\n --prefix TEXT Strips the given prefix from URL paths. Also\n sets root_path to this value. [env var:\n FDK_ASGI_PREFIX]\n --timeout-keep-alive INTEGER [env var: FDK_ASGI_TIMEOUT_KEEP_ALIVE;\n default: 5]\n --factory / --no-factory Treat APP as an application factory, i.e. a\n () -> <ASGI app> callable. [env var:\n FDK_ASGI_FACTORY; default: no-factory]\n --h11-max-incomplete-event-size INTEGER\n [env var:\n FDK_ASGI_H11_MAX_INCOMPLETE_EVENT_SIZE]\n --install-completion [bash|zsh|fish|powershell|pwsh]\n Install completion for the specified shell.\n --show-completion [bash|zsh|fish|powershell|pwsh]\n Show completion for the specified shell, to\n copy it or customize the installation.\n --help Show this message and exit.\n```\n\n## Documentation on the Open Fn Project and OCI Functions\n\nExample request:\n\n```\nPOST /call HTTP/1.1\nFn-Call-Id : 12345678910\nFn-Deadline: <date/time>\nFn-Http-Request-Url: https://my.fn.com/t/hello/world\nFn-Http-Method: PUT\nFn-Http-H-Custom-Header: foo\nContent-type: text/plain\n\n<Body here>\n```\n\nExample Response:\n\n```\nHTTP/1.1 200 OK\nFn-Http-Status: 204\nFn-Http-H-My-Header: foo\nFn-Fdk-Version: fdk-go/0.0.42\nContent-type: text/plain\n\n<Body here>\n```\n\nFor more info see [Fn container contract](https://github.com/fnproject/docs/blob/master/fn/develop/fn-format.md).\n\nNotes:\n\n- 0666 contract can be fulfilled by `gunicorn --umask 0666`.\n\n### Default Environment Variables\n\nHere is the list of automatically generated environment variables that are available to your functions.\n\n| Fn Generated Var | Sample Value | Description |\n|------------------|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `FN_APP_ID` | `01NNNNNNNNNG8G00GZJ0000001` | The application ID for the app the current function is contained in. |\n| `FN_FN_ID` | `01DYNNNNNNNG8G00GZJ0000002` | The ID of the current function |\n| `FN_FORMAT` | `http-stream` | Communications protocol. **(Deprecated)** |\n| `FN_LISTENER` | `unix:/tmp/iofs/lsnr.sock` | The Unix socket address (prefixed with \u201cunix:\u201d) on the file system that the FDK should create to listen for requests. The platform will guarantee that this directory is writable to the function. FDKs must not write any other data than the unix socket to this directory. |\n| `FN_MEMORY` | `128` | The maximum memory of the function in MB. |\n| `FN_TYPE` | `sync` | The type of function. Always sync currently. |\n\nSource: [Fn Project: Using Config Variables and Environment Variables](https://fnproject.io/tutorials/basics/UsingRuntimeContext/#UsingConfigVariablesandEnvironmentVariables)\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "An alternative FDK to easily run any ASGI application on OCI Functions behind an API Gateway.",
"version": "0.7.2",
"project_urls": {
"Documentation": "https://github.com/bjoern-reetz/fdk-asgi/",
"Homepage": "https://github.com/bjoern-reetz/fdk-asgi/",
"Repository": "https://github.com/bjoern-reetz/fdk-asgi/"
},
"split_keywords": [
"oci",
" functions",
" fnproject",
" runtime",
" asgi"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8d380aee778677b615975eafdfa318cad44a8b4dc4e18d99a6655c6ba02897bc",
"md5": "c375d3dc087afcacb92d79defb83299c",
"sha256": "5ebf89808cd57c0981f95207c5000e744ce8709556f72f0098947607726c1c0c"
},
"downloads": -1,
"filename": "fdk_asgi-0.7.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c375d3dc087afcacb92d79defb83299c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 11035,
"upload_time": "2024-08-04T11:38:52",
"upload_time_iso_8601": "2024-08-04T11:38:52.941294Z",
"url": "https://files.pythonhosted.org/packages/8d/38/0aee778677b615975eafdfa318cad44a8b4dc4e18d99a6655c6ba02897bc/fdk_asgi-0.7.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3e81d471e5166b3c2ee8d53d8cb1c2ac61e4056b639066be85b21963583d5c69",
"md5": "015635c4c83043457b0ae5389d0b29cf",
"sha256": "9d3a69f0dfd2a9d68e5fec3c970204f6f5b63555e1e8fa3cab9b0864f2a3c74e"
},
"downloads": -1,
"filename": "fdk_asgi-0.7.2.tar.gz",
"has_sig": false,
"md5_digest": "015635c4c83043457b0ae5389d0b29cf",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 11630,
"upload_time": "2024-08-04T11:38:54",
"upload_time_iso_8601": "2024-08-04T11:38:54.104558Z",
"url": "https://files.pythonhosted.org/packages/3e/81/d471e5166b3c2ee8d53d8cb1c2ac61e4056b639066be85b21963583d5c69/fdk_asgi-0.7.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-04 11:38:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bjoern-reetz",
"github_project": "fdk-asgi",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "fdk-asgi"
}