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.7.2.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.7.2-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ycfuncs-25.8.7.2.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.7.2.tar.gz
Algorithm Hash digest
SHA256 b98547752a3b5ecab099f539f8bc7fd0fc83061809f6eac4a257e1e33adbb758
MD5 e421a6c053f4d3721fa0ef3359662b52
BLAKE2b-256 af1bf447eae3fc1928f84fcb973e7850bfd4d5126645172e9ed27e6ccee5c009

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ycfuncs-25.8.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 99cabbaf4f7058bee8d72609bdf54bd1019dfe4d01e0f742714193602a5aa3e1
MD5 82e78f86da2048fd44ec8a7104793e85
BLAKE2b-256 c913b97b2861981478d59ffe1a77472eaab550ba2c92536f5db127e9cd89b6aa

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