Skip to main content

An alternative FDK to easily run any ASGI application on OCI Functions behind an API Gateway.

Project description

fdk-asgi

pipeline status latest package version supported python versions PyPI - Downloads source files coverage pre-commit

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.

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.

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

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

fdk_asgi-0.7.1.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

fdk_asgi-0.7.1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file fdk_asgi-0.7.1.tar.gz.

File metadata

  • Download URL: fdk_asgi-0.7.1.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for fdk_asgi-0.7.1.tar.gz
Algorithm Hash digest
SHA256 364c44b83603f2dc42d3338d80c15465dd6ad3d98ec1d5fb7a0baac2555e09ce
MD5 466bffd26249c31c4b772754a8c8d680
BLAKE2b-256 f8c072bb616f2c97050d24c4c48c65df6f3e2255b6e426591345759f2fe73852

See more details on using hashes here.

File details

Details for the file fdk_asgi-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: fdk_asgi-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for fdk_asgi-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cf11e1c1a5261686997423a56602099d550c1f96c7c5a4a023f3313cc5bb94b0
MD5 6bc50ed79a91b3c383fc13e4855bf1db
BLAKE2b-256 7efb8fa32eee5a15ef33dde65548ac10f98f655f70c21cad50122df3a4a4987a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page