cloudrun-fastapi
Boilerplate for running FastAPI on Google Cloud Run with Google Cloud Build for deployment.
For all documentation visit the docs folder.
Contributions & Suggestions
Pull requests and issues are very welcome!
Boilerplate for running FastAPI on Google Cloud Run with Google Cloud Build for deployment.
For all documentation visit the docs folder.
Pull requests and issues are very welcome!
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 questionHi, 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?
When deploying to Cloud Run, this error triggered: ModuleNotFoundError: No module named python container tests
This is because tests/
is in the .dockerignore
.
When deploying to Cloud Run, this error triggered: ModuleNotFoundError: No module named python container tests
.
tests/
was indeed added to .dockerignore
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?
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?
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.
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
tests
to cover my changes.docs/
, if necessary.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.
🚀
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.
tests
to cover my changes.docs/
, if necessary.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.
Bumps fastapi from 0.60.1 to 0.65.2.
Sourced from fastapi's releases.
0.65.2
Security fixes
- 🔒 Check Content-Type request header before assuming JSON. Initial PR #2118 by
@patrickkwang
.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 thecontent-type
header sent was not set toapplication/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
- 🔧 Update sponsors badge, course bundle. PR #3340 by
@tiangolo
.- 🔧 Add new gold sponsor Jina 🎉. PR #3291 by
@tiangolo
.- 🔧 Add new banner sponsor badge for FastAPI courses bundle. PR #3288 by
@tiangolo
.- 👷 Upgrade Issue Manager GitHub Action. PR #3236 by
@tiangolo
.0.65.1
Security fixes
- 📌 Upgrade pydantic pin, to handle security vulnerability CVE-2021-29510. PR #3213 by
@tiangolo
.0.65.0
Breaking Changes - Upgrade
- ⬆️ Upgrade Starlette to
0.14.2
, including internalUJSONResponse
migrated from Starlette. This includes several bug fixes and features from Starlette. PR #2335 by@hanneskuettner
.Translations
- 🌐 Initialize new language Polish for translations. PR #3170 by
@neternefer
.Internal
- 👷 Add GitHub Action cache to speed up CI installs. PR #3204 by
@tiangolo
.- ⬆️ Upgrade setup-python GitHub Action to v2. PR #3203 by
@tiangolo
.- 🐛 Fix docs script to generate a new translation language with
overrides
boilerplate. PR #3202 by@tiangolo
.- ✨ Add new Deta banner badge with new sponsorship tier 🙇. PR #3194 by
@tiangolo
.- 👥 Update FastAPI People. PR #3189 by
@github-actions[bot]
.- 🔊 Update FastAPI People to allow better debugging. PR #3188 by
@tiangolo
.0.64.0
Features
... (truncated)
4d91f97
🔖 Release version 0.65.2aabe2c7
📝 Update release notes377234a
🔒 Create Security Policy38b7858
📝 Update release notesfa7e3c9
🐛 Check Content-Type request header before assuming JSON (#2118)90120dd
📝 Update release notes3677254
🔧 Update sponsors badge, course bundle (#3340)40bb0c5
📝 Update release notes60918d2
🔧 Add new gold sponsor Jina 🎉 (#3291)3afce2c
📝 Update release notesDependabot 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
.
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 languageYou can disable automated security fix PRs for this repo from the Security Alerts page.
updates:
Regular email auth is great but using other providers would be nice too.
enhancementFastAPI ADMIN 中文文档 Introduction FastAPI-Admin is a admin dashboard based on fastapi and tortoise-orm. FastAPI-Admin provide crud feature out-of-the-bo
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
iter8-analytics iter8 enables statistically robust continuous experimentation of microservices in your CI/CD pipelines. For in-depth information about
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
视频教学地址 中文学习教程 1、本教程每一个案例都可以独立跑,前提是安装好依赖包。 2、本教程并未按照官方教程顺序,而是按照实际使用顺序编排。 Video Teaching Address FastAPI Learning Example 1.Each case in this tutorial c
Mall项目后台管理 前段时间学习Vue写了一个移动端项目 https://www.charmcode.cn/app/mall/home 然后教程到此就结束了, 我就总感觉少点什么,计划自己着手写一套后台管理。 相关项目 移动端Mall项目源码(Vue构建): https://github.com/
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
Backend API Skeleton Based on @tiangolo's full stack postgres template, with some things added, some things removed, and some things changed. This is
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'
FastAPI Auth Pluggable auth for use with FastAPI Supports OAuth2 Password Flow Uses JWT access and refresh tokens 100% mypy and test coverage Supports
FastAPI Boilerplate Features SQlAlchemy session Custom user class Top-level dependency Dependencies for specific permissions Celery SQLAlchemy for asy
FastAPI with Celery Minimal example utilizing FastAPI and Celery with RabbitMQ for task queue, Redis for Celery backend and flower for monitoring the
fastapi - celery - rabbitmq - redis -> Docker A simple docker-compose app for orchestrating a fastapi application, a celery queue with rabbitmq(broker
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
Description JSON-RPC server based on fastapi: https://fastapi.tiangolo.com Motivation Autogenerated OpenAPI and Swagger (thanks to fastapi) for JSON-R
FastAPI Model Server Skeleton Serving machine learning models production-ready, fast, easy and secure powered by the great FastAPI by Sebastián Ramíre
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
Plugins for FastAPI framework, high performance, easy to learn, fast to code, ready for production fastapi-plugins FastAPI framework plugins Cache Mem
Quickstart Then run the following commands to bootstrap your environment with poetry: git clone https://github.com/xiaozl/fastapi-realworld-example-ap