Skip to main content

Handler for FastAPI apps in Yandex Cloud Functions

Project description

YcFuncs

Yandex Cloud Functions handler for FastAPI applications

For what?

I was unable to launch applications written using the FastAPI framework in the form of Yandex cloud functions. So I had to develop an adapter to solve this problem.

Example

from fastapi import FastAPI
from ycfuncs import FastAPIHandler

# For local launch
app = FastAPI()


@app.get("/")
async def root():
    return 'Hello World!'

# Entry point for launch in Yandex cloud function 
handler = FastAPIHandler(app)

local launch

Install uv sync or pip install -r requirements.txt Run in terminal uv run fastapi dev --port=5004 or uvicorn main:app --port=5004

Yandex cloud functions launch

Set entry point to main.handler Request handler for a function in Python

Yandex Cloud ApiGateway

Now you can use Yandex Cloud ApiGateway like this:

openapi: 3.0.0
info:
  title: Sample API
  version: 1.0.0
servers:
- url: https://yourdomain.apigw.yandexcloud.net
paths:
  /some-prefix/{url+}:
    x-yc-apigateway-any-method:
      x-yc-apigateway-integration:
        payload_format_version: '0.1'
        function_id: your-function-id
        tag: $latest
        type: cloud_functions
        service_account_id: your-service-account
      parameters:
        - name: url
          in: path
          description: path
          required: true
          schema:
            type: string

And check curl -XGET https://yourdomain.apigw.yandexcloud.net/some-prefix/ - you should get "Hello World!". In this case {url+} is your APIRouter endpoints.

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

ycfuncs-25.8.81530.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ycfuncs-25.8.81530-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file ycfuncs-25.8.81530.tar.gz.

File metadata

  • Download URL: ycfuncs-25.8.81530.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.20

File hashes

Hashes for ycfuncs-25.8.81530.tar.gz
Algorithm Hash digest
SHA256 04331931ec28c940d1289034f2363734229af107ac2106645486e1134b19b434
MD5 42db4687ed377105f56dc3cb4f3db9cd
BLAKE2b-256 428070d55e2f5e916646a639801d560654e038da0eff509adadedd49a8e9c803

See more details on using hashes here.

File details

Details for the file ycfuncs-25.8.81530-py3-none-any.whl.

File metadata

File hashes

Hashes for ycfuncs-25.8.81530-py3-none-any.whl
Algorithm Hash digest
SHA256 2f191a231f19ce78dab152b4aa96688bb1f117621f18e75468a0b54f8446e11c
MD5 0c0e58177b08ea772653f50747b23e84
BLAKE2b-256 3da266d6ccae22d273d24252d6c8a2144a5904fd99a2846aa705651aff09c105

See more details on using hashes here.

Supported by

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