FastAPI on Google Cloud Run

Overview
Comments
  • Question about the Gunicorn config

    Question about the Gunicorn config

    Hey, thanks for the project and your work. I have a question about the Gunicorn config. The official Cloud Run tutorial for Python applications (in this case Flask and not async) states that this config should be used:

    CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
    

    I understand that this might not be the best config for FastAPI applications but they explicitly say that "Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling."

    So is there a reason to use your timeout value of 60 instead of the recommended one?

    Thanks!

    good first issue question 
    opened by pbizimis 5
  • [QUESTION] why using gunicorn?

    [QUESTION] why using gunicorn?

    Hi, FastAPI docs say that when running in a system that manages distributed containers (e.g. K8s) it is better to run a single Uvicorn process. See here: https://fastapi.tiangolo.com/deployment/docker/#replication-number-of-processes

    I believe Cloud Run falls under that group of systems that manage container clusters, load balancing, etc'... So the question is, why use Gunicron to manage the workload? WDYT?

    opened by H3zi 4
  • Fix dockerignore

    Fix dockerignore

    When deploying to Cloud Run, this error triggered: ModuleNotFoundError: No module named python container tests

    This is because tests/ is in the .dockerignore.

    opened by dhassault 3
  • ModuleNotFoundError

    ModuleNotFoundError

    When deploying to Cloud Run, this error triggered: ModuleNotFoundError: No module named python container tests. tests/ was indeed added to .dockerignore

    opened by dhassault 2
  • View docs when cloud run service is on a custom domain

    View docs when cloud run service is on a custom domain

    Hi! Thanks for this repo.

    Quick q, I am able to view docs on the raw cloud run domain, but I am using a custom domain mapping so all my services are reachable at customdomain.com/{service-name}, this works fine for all uses apart from the docs are not available at customdomain.com/{service-name}/docs

    Any idea why that could be the case?

    opened by ydennisy 1
  • Cannot migrate to Cloud SQL

    Cannot migrate to Cloud SQL

    Hi!

    When I'm connecting to my cloud SQL instance with psql "sslmode=disable host=/tmp/cloudsql/PROJECT_ID:REGION:INSTANCE_NAME user=postgres dbname=postgres", it works well but when using:

    cloud_sql_proxy -instances=PROJECT_ID:REGION:INSTANCE_NAME -dir=/tmp/cloudsql
    

    And then doing:

    PYTHONPATH=. alembic revision --autogenerate -m "initial setup"
    

    I have the error:

    ...
    sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string 'PROJECT_ID:REGION:INSTANCE_NAME'
    

    (PROJECT_ID:REGION:INSTANCE_NAME being my own instance)

    Any idea or documentation to solve this issue?

    opened by dhassault 1
  • Cannot connect to local posgres

    Cannot connect to local posgres

    Hi,

    First, thank you a lot for this template. I'm new to the API world and trying to deploy my own one on GCP. But first I'm developing locally. But I'm struggling using the local db.

    I first run postgres on a container locally with docker run --rm --name pg-docker -e POSTGRES_DB=postgres_test_db -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres:12.3-alpine

    Then if I run PYTHONPATH=. alembic revision --autogenerate -m "initial setup", I have the following error message:

    ...
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
    sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: No such file or directory
            Is the server running locally and accepting
            connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
    

    In config.py I have url = 'postgresql+psycopg2://postgres:postgres@localhost/postgres_test_db'.

    Is there any documentation that could help me?

    I'm running everything on Ubuntu (20.04), use vscode and poetry. If I run psql -U postgres -h localhost it connects to the database as expected.

    opened by dhassault 1
  • Sending Emails with SendGrid

    Sending Emails with SendGrid

    SendGrid is a great choice for sending emails and managing the analytics around them. Checkout their free tier, https://sendgrid.com/free, to get started. In order to send emails, you will have to verify your sending authentication. You can set that up here https://app.sendgrid.com/settings/sender_auth.

    In this sample, we'll place all templates in the assets/templates/ directory, located in the project root.

    Sample provided from SendGrid:

    from sendgrid import SendGridAPIClient
    from sendgrid.helpers.mail import Mail
    
    message = Mail(
        from_email='[email protected]',
        to_emails='[email protected]',
        subject='Sending with Twilio SendGrid is Fun',
        html_content='<strong>and easy to do anywhere, even with Python</strong>')
    try:
        sg = SendGridAPIClient(api_key=<YOUR_API_KEY>)
        response = sg.send(message=message)
        print(response.status_code)
        print(response.body)
        print(response.headers)
    except Exception as e:
        print(e)
        print(e.body)
    
    enhancement 
    opened by anthonycorletti 1
  • Feature/sqlmodel

    Feature/sqlmodel

    • [ ] I have added tests to tests to cover my changes.
    • [ ] I have updated docs/, if necessary.
    • [ ] I have updated the README.md, if necessary.

    What existing issue does this pull request close?

    No issue. Adding support for sqlmodel!

    How are these changes tested?

    CI

    Demonstration

    CI ✨

    Provide additional context.

    🚀

    opened by anthonycorletti 0
  • doc: update

    doc: update

    Please do not create a pull request without creating an issue first.

    Changes need to be discussed before proceeding, pull requests submitted without linked issues may be rejected.

    Please provide enough information so that others can review your pull request. You can skip this if you're fixing a typo – it happens.

    Please remove all quoted text above and including this line before submitting your pull request.

    • [ ] I have added tests to tests to cover my changes.
    • [ ] I have updated docs/, if necessary.
    • [ ] I have updated the README.md, if necessary.

    What existing issue does this pull request close?

    Put closes #issue-number in this pull request's description to auto-close the issue that this fixes.

    How are these changes tested?

    This pull request includes automated tests for the code it touches and those tests are described below. If no tests are included, reasons why must be provided below. These changes are tested with [...]

    Demonstration

    Demonstrate your contribution. For example, what are the exact commands you ran and their output, related screenshots, screen-recordings, test runs, anything that can showcase.

    Provide additional context.

    Provide as much relevant context as you like.

    opened by anthonycorletti 0
  • Bump fastapi from 0.60.1 to 0.65.2

    Bump fastapi from 0.60.1 to 0.65.2

    Bumps fastapi from 0.60.1 to 0.65.2.

    Release notes

    Sourced from fastapi's releases.

    0.65.2

    Security fixes

    This change fixes a CSRF security vulnerability when using cookies for authentication in path operations with JSON payloads sent by browsers.

    In versions lower than 0.65.2, FastAPI would try to read the request payload as JSON even if the content-type header sent was not set to application/json or a compatible JSON media type (e.g. application/geo+json).

    So, a request with a content type of text/plain containing JSON data would be accepted and the JSON data would be extracted.

    But requests with content type text/plain are exempt from CORS preflights, for being considered Simple requests. So, the browser would execute them right away including cookies, and the text content could be a JSON string that would be parsed and accepted by the FastAPI application.

    See CVE-2021-32677 for more details.

    Thanks to Dima Boger for the security report! 🙇🔒

    Internal

    0.65.1

    Security fixes

    0.65.0

    Breaking Changes - Upgrade

    • ⬆️ Upgrade Starlette to 0.14.2, including internal UJSONResponse migrated from Starlette. This includes several bug fixes and features from Starlette. PR #2335 by @​hanneskuettner.

    Translations

    Internal

    0.64.0

    Features

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Login with Google and other OAuth Providers

    Login with Google and other OAuth Providers

    Regular email auth is great but using other providers would be nice too.

    • [ ] Google
    • [ ] GitHub
    • [ ] Replace username-password with passwordless login
    enhancement 
    opened by anthonycorletti 0
Owner
Anthony Corletti
Anthony Corletti
FastAPI Admin Dashboard based on FastAPI and Tortoise ORM.

FastAPI ADMIN 中文文档 Introduction FastAPI-Admin is a admin dashboard based on fastapi and tortoise-orm. FastAPI-Admin provide crud feature out-of-the-bo

long2ice 1.6k Dec 31, 2022
Admin Panel for GinoORM - ready to up & run (just add your models)

Gino-Admin Docs (state: in process): Gino-Admin docs Play with Demo (current master 0.2.3) >>>> Gino-Admin demo <<<< (login: admin, pass: 1234) Admin

Iuliia Volkova 46 Nov 2, 2022
Analytics service that is part of iter8. Robust analytics and control to unleash cloud-native continuous experimentation.

iter8-analytics iter8 enables statistically robust continuous experimentation of microservices in your CI/CD pipelines. For in-depth information about

null 16 Oct 14, 2021
Example app using FastAPI and JWT

FastAPI-Auth Example app using FastAPI and JWT virtualenv -p python3 venv source venv/bin/activate pip3 install -r requirements.txt mv config.yaml.exa

Sander 28 Oct 25, 2022
FastAPI Learning Example,对应中文视频学习教程:https://space.bilibili.com/396891097

视频教学地址 中文学习教程 1、本教程每一个案例都可以独立跑,前提是安装好依赖包。 2、本教程并未按照官方教程顺序,而是按照实际使用顺序编排。 Video Teaching Address FastAPI Learning Example 1.Each case in this tutorial c

null 381 Dec 11, 2022
🤪 FastAPI + Vue构建的Mall项目后台管理

Mall项目后台管理 前段时间学习Vue写了一个移动端项目 https://www.charmcode.cn/app/mall/home 然后教程到此就结束了, 我就总感觉少点什么,计划自己着手写一套后台管理。 相关项目 移动端Mall项目源码(Vue构建): https://github.com/

王小右 131 Jan 1, 2023
Backend, modern REST API for obtaining match and odds data crawled from multiple sites. Using FastAPI, MongoDB as database, Motor as async MongoDB client, Scrapy as crawler and Docker.

Introduction Apiestas is a project composed of a backend powered by the awesome framework FastAPI and a crawler powered by Scrapy. This project has fo

Fran Lozano 54 Dec 13, 2022
Backend Skeleton using FastAPI and Sqlalchemy ORM

Backend API Skeleton Based on @tiangolo's full stack postgres template, with some things added, some things removed, and some things changed. This is

David Montague 18 Oct 31, 2022
FastAPI + Django experiment

django-fastapi-example This is an experiment to demonstrate one potential way of running FastAPI with Django. It won't be actively maintained. If you'

Jordan Eremieff 78 Jan 3, 2023
Auth for use with FastAPI

FastAPI Auth Pluggable auth for use with FastAPI Supports OAuth2 Password Flow Uses JWT access and refresh tokens 100% mypy and test coverage Supports

David Montague 95 Jan 2, 2023
FastAPI Boilerplate

FastAPI Boilerplate Features SQlAlchemy session Custom user class Top-level dependency Dependencies for specific permissions Celery SQLAlchemy for asy

Hide 417 Jan 7, 2023
Minimal example utilizing fastapi and celery with RabbitMQ for task queue, Redis for celery backend and flower for monitoring the celery tasks.

FastAPI with Celery Minimal example utilizing FastAPI and Celery with RabbitMQ for task queue, Redis for Celery backend and flower for monitoring the

Grega Vrbančič 371 Jan 1, 2023
A simple docker-compose app for orchestrating a fastapi application, a celery queue with rabbitmq(broker) and redis(backend)

fastapi - celery - rabbitmq - redis -> Docker A simple docker-compose app for orchestrating a fastapi application, a celery queue with rabbitmq(broker

Kartheekasasanka Kaipa 83 Dec 19, 2022
fastapi-crud-sync

Developing and Testing an API with FastAPI and Pytest Syncronous Example Want to use this project? Build the images and run the containers: $ docker-c

null 59 Dec 11, 2022
JSON-RPC server based on fastapi

Description JSON-RPC server based on fastapi: https://fastapi.tiangolo.com Motivation Autogenerated OpenAPI and Swagger (thanks to fastapi) for JSON-R

null 199 Dec 30, 2022
FastAPI Skeleton App to serve machine learning models production-ready.

FastAPI Model Server Skeleton Serving machine learning models production-ready, fast, easy and secure powered by the great FastAPI by Sebastián Ramíre

null 268 Jan 1, 2023
row level security for FastAPI framework

Row Level Permissions for FastAPI While trying out the excellent FastApi framework there was one peace missing for me: an easy, declarative way to def

Holger Frey 315 Dec 25, 2022
FastAPI framework plugins

Plugins for FastAPI framework, high performance, easy to learn, fast to code, ready for production fastapi-plugins FastAPI framework plugins Cache Mem

RES 239 Dec 28, 2022
python fastapi example connection to mysql

Quickstart Then run the following commands to bootstrap your environment with poetry: git clone https://github.com/xiaozl/fastapi-realworld-example-ap

null 55 Dec 15, 2022