{"id":29738457,"url":"https://github.com/tkote/fn-fastapi","last_synced_at":"2026-05-16T18:35:51.848Z","repository":{"id":188623125,"uuid":"365709864","full_name":"tkote/fn-fastapi","owner":"tkote","description":"Fn / OCI Function without FDK, with FastAPI","archived":false,"fork":false,"pushed_at":"2021-05-10T01:52:45.000Z","size":10,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-25T23:42:56.214Z","etag":null,"topics":["fastapi","fdk","fn","oci-functions"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tkote.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-05-09T09:01:46.000Z","updated_at":"2024-06-27T20:01:37.000Z","dependencies_parsed_at":"2023-08-16T06:28:15.847Z","dependency_job_id":"30ea8336-0dee-4183-ad51-69392aa5d8a4","html_url":"https://github.com/tkote/fn-fastapi","commit_stats":null,"previous_names":["tkote/fn-fastapi"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tkote/fn-fastapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkote%2Ffn-fastapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkote%2Ffn-fastapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkote%2Ffn-fastapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkote%2Ffn-fastapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tkote","download_url":"https://codeload.github.com/tkote/fn-fastapi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkote%2Ffn-fastapi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33114472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","fdk","fn","oci-functions"],"created_at":"2025-07-25T18:47:46.947Z","updated_at":"2026-05-16T18:35:51.831Z","avatar_url":"https://github.com/tkote.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Functions without FDK\n\n## Fn (OCI Functions) の Function を FDK を使わずに作成する方法 - Python/FastAPI 編\n\nFDK (Function Development Kit) を使わずに Function を作る方法として「 [netty と reactor-netty で実装してみた](https://github.com/tkote/fn-netty) 」を以前紹介したが、今回はその Python/FastAPI 編。使い慣れたフレームワークを使って Fnctions を開発したいという人は多いハズ。\n\n## 仕組み\n\nFunctions のロジックを実装しているもの (main.py)と、ASGI (Asynchronous Server Gateway Interface) 実装である uvicorn の起動や Fn/Functions の流儀に従ってソケットまわりのお世話をしているもの (fn-fastapi.py) の二つで構成されていて、fn-fastapi.py は全くいじる必要なし。  \nmain.py で 通常 FastAPI で API を実装するのと同じように、`/call` に対する POST リクエストを実装すればOK。ここでは簡易的なデモ実装をしている。\n\n```python\n@app.post('/call')\nasync def post_call():\n    ... 実際の処理 ...\n```\n\nFn/Functions がどういう仕様で Unix Domain Socket を使ってコンテナと通信しているかについては、前述の netty/reactor-netty 編を参照されたし。\n\n## ビルド \u0026 実行\n\n* ローカルで実行\n\n  ```bash\n  # preparation\n  $ pip install fastapi\n  $ pip install uvicorn\n\n  # run server\n  $ python fn-fastapi.py\n  \n  # call function\n  $ curl --unix-socket /tmp/fnlsnr.sock -X POST -d 'Hello World!' http:/call\n  ```\n\n* Docker image を作成 \u0026 実行\n  \n  ```bash\n  # build\n  $ docker build -t fn-fastapi:0.0.1 .\n  \n  # run server\n  $ docker run --rm -it --name fn-fastapi -v /tmp:/tmp fn-fastapi:0.0.1\n\n  # call function\n  $ curl --unix-socket /tmp/fnlsnr.sock -X POST -d 'Hello World!' http:/call\n  ```\n\n* ローカル Fn Server で実行\n  \n  Fn CLIはインストール済みという前提で\n  \n  ```bash\n  # start Fn server\n  $ fn start\n\n  # setup Fn CLI\n  $ fn use context default\n  \n  # create app\n  $ fn create app funcapp\n\n  # deploy function\n  $ fn deploy -app funcapp --local --no-bump -v\n\n  # call function\n  $ echo -n 'Hello World!' | fn invoke funcapp fn-fastapi\n  ```\n\n* OCI Functions にデプロイ \u0026 実行\n\n  OCI Functions で アプリケーション funcapp が作成されている前提で\n\n  ```bash\n  # setup Fn CLI\n  $ fn use context XXXXXX\n\n  # deploy function\n  $ fn deploy -app funcapp --no-bump -v\n\n  # call functions\n  $ echo -n 'Hello World!' | fn invoke funcapp fn-fastapi\n  ```\n\n## デモ\n\n```\n# call OCI Functions\n$ echo -n 'Hello World!' | fn invoke funcapp fn-fastapi\n[REQUEST HEADERS]\nhost: localhost\nuser-agent: Go-http-client/1.1\ntransfer-encoding: chunked\naccept-encoding: gzip\ncontent-type: application/json\ndate: Sun, 09 May 2021 08:37:51 GMT\nfn-call-id: 01F584D3CM1BT0010ZJ005T5M1\nfn-deadline: 2021-05-09T08:43:16Z\noci-subject-id: ocid1.user.oc1..\noci-subject-tenancy-id: ocid1.tenancy.oc1..\noci-subject-type: user\nopc-compartment-id: ocid1.compartment.oc1..\nopc-request-id: /01F584D3AJ1BT0010ZJ005T5KR/01F584D3AJ1BT0010ZJ005T5KS\nx-content-sha256: f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=\n\n[REQUEST BODY]\nHello World!\n```\n\nOCI Functions で、サーバー起動から最初のリクエスト処理までのログ\n\n```\nENV FN_LISTENER: unix:/tmp/iofs/lsnr.sock\nactual: /tmp/iofs/lsnr.sock\nphony: /tmp/iofs/ldyDK2Jn_lsnr.sock\nINFO:     Started server process [6]\nINFO:     Waiting for application startup.\nINFO:     Application startup complete.\nINFO:     Uvicorn running on unix socket /tmp/iofs/ldyDK2Jn_lsnr.sock (Press CTRL+C to quit)\nReady to receive calls via /tmp/iofs/lsnr.sock -\u003e ldyDK2Jn_lsnr.sock\nINFO:      - \\\"POST /call HTTP/1.1\\\" 200 OK\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkote%2Ffn-fastapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftkote%2Ffn-fastapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkote%2Ffn-fastapi/lists"}