Template repo for a GCP-hosted REST API with automatic API versioning and custom domain mapping

Overview

Python + Poetry REST API with FastAPI, hosted on GCP

This template will get you ready to deploy a FastAPI app in Google Cloud with automatic API versioning by major release version and automatic custom domain mapping.

Major tags maintain separate API services in Cloud Run. For example, if my custom domain is api.k2bd.dev, running the release GitHub action to create version v2.3.4 will update the v2 tag and automatically (re)-deploy to the v2.api.k2bd.dev service with the released code. The v1 service is unaffected, and there's no need to keep v1-compatible code around in the default branch of your repo after bumping to v2. New v1 versions can be pushed separately to update that version using whatever workflow you want that produces a new v1.*.* semver tag, for example for bugfixes that affect the previous version. This keeps the maintenance cost of the code low while also ensuring old versions of the API are live and available to clients until they're migrated to the newer versions.

Getting started from the template

  1. Rename the src/gcp_fastapi_poetry package.
  2. Globally replace (case-sensitive) instances of gcp-fastapi-poetry, gcp_fastapi_poetry, and GCP_FASTAPI_POETRY with your project and package name (including later in this list).
  3. Set your repo up on CodeCov and add a codecov token to your repo under the CODECOV_TOKEN secret.
  4. Create a new repo-scoped personal access token and add it as a DEPLOY_TOKEN repo secret. This is so we can maintain major version tags.
  5. Change your Cloud Run configuration in cloudbuild.yaml as appropriate. By default, it will deploy an API that can be invoked with no authentication.
  6. Configure a Cloud Build trigger in your GCP project to deploy from cloudbuild.yaml on a new tag that matches the regex ^(v(\d+))$, with a substituion variable _GCP_FASTAPI_POETRY_API_DOMAIN pointing to the (sub)-domain you want to host the API on. Make sure the cloudbuild service account has the required permissions (Cloud Build settings --> enable Cloud Run, Service Accounts, and Cloud Build) and is registered as an owner of your custom domain if required.
  7. Update LICENSE.md as appropriate, making sure to retain the original copyright and permissions notices in your distribution according to the MIT license that this template is distributed under.
  8. Create and test your API. Your app under gcp_fastapi_poetry.api:app will be hosted on CloudRun when it's deployed.
  9. When you're ready to release the first version, run the release GitHub action with the "major" option to deploy v1 of your API! (or minor/patch to deploy v0)
  10. Remove this section from README.md.
  11. Happy hacking!

Like this template?

"Buy Me A Coffee"

Developing

Install Poetry and poetry install the project

Useful Commands

Note: if Poetry is managing a virtual environment for you, you may need to use poetry run poe instead of poe

  • poe autoformat - Autoformat code
  • poe lint - Linting
  • poe test - Run Tests
  • poe local-server - Run your API locally

Deployment

Release a new version by manually running the release action on GitHub with a 'major', 'minor', or 'patch' version bump selected. This will create an push a new semver tag of the format v1.2.3, and also update the appropriate major version tag (v1, v2, ...).

Updating the major version tags will cause Cloud Build to create or update that version's deployment automatically and host it at e.g. v1.(your configured domain). You may need to configure your domain's DNS if you're creating an endpoint for a new major version and you use an external provider. See the domain mappings page linked here for instructions.

Owner
Kevin Duff
Scientific Software Developer
Kevin Duff
A set of tools to keep your pinned Python dependencies fresh.

pip-tools = pip-compile + pip-sync A set of command line tools to help you keep your pip-based packages fresh, even when you've pinned them. You do pi

Jazzband 6.5k Dec 29, 2022
A Poetry plugin for dynamically extracting the package version.

Poetry Version Plugin A Poetry plugin for dynamically extracting the package version. It can read the version from a file __init__.py with: # __init__

Sebastián Ramírez 264 Dec 22, 2022
A PyPI mirror client according to PEP 381 http://www.python.org/dev/peps/pep-0381/

This is a PyPI mirror client according to PEP 381 + PEP 503 http://www.python.org/dev/peps/pep-0381/. bandersnatch =4.0 supports Linux, MacOSX + Wind

Python Packaging Authority 345 Dec 28, 2022
Dotpkg - Package manager for your dotfiles

Dotpkg A package manager for your dotfiles. Usage First make sure to have Python

FW 4 Mar 18, 2022
:package: :fire: Python project management. Manage packages: convert between formats, lock, install, resolve, isolate, test, build graph, show outdated, audit. Manage venvs, build package, bump version.

THE PROJECT IS ARCHIVED Forks: https://github.com/orsinium/forks DepHell -- project management for Python. Why it is better than all other tools: Form

DepHell 1.7k Dec 30, 2022
The Python package installer

pip - The Python Package Installer pip is the package installer for Python. You can use pip to install packages from the Python Package Index and othe

Python Packaging Authority 8.4k Dec 30, 2022
The delightful package manager for AppImages

⚡️ Zap The delightful package manager for AppImages Report bug · Request feature Looking for the older Zap v1 (Python) implementation? Head over to v1

Srevin Saju 368 Jan 04, 2023
Python Environment & Package Manager

Python Environment Manager A Visual Studio Code extension that provides the ability to via and manage all of your Python environments & packages from

Don Jayamanne 72 Dec 29, 2022
A tool to upgrade dependencies to the latest versions

pip-check-updates A tool to upgrade dependencies to the latest versions, inspired by npm-check-updates Install From PyPi pip install pip-check-updates

Zeheng Li 12 Jan 06, 2023
A flexible package manager that supports multiple versions, configurations, platforms, and compilers.

Spack Spack is a multi-platform package manager that builds and installs multiple versions and configurations of software. It works on Linux, macOS, a

Spack 3.1k Jan 09, 2023
Install All Basic Termux Packages To Your Phone

~All-Packages~ The Easiest Way To Install All Termux Packages 🤗 Tool By ⒹⓈ᭄ʜʏᴅʀᴀ✘๛ˢᴸ 👇 Contact Me On 👇 AVAILABLE ON : Termux TESTED ON : Term

ⒹⓈ ʜʏͥᴅᷧʀᷟᴀ✘๛ˢᴸ 7 Nov 12, 2022
Template repo for a GCP-hosted REST API with automatic API versioning and custom domain mapping

Python + Poetry REST API with FastAPI, hosted on GCP This template will get you ready to deploy a FastAPI app in Google Cloud with automatic API versi

Kevin Duff 10 Dec 25, 2022
For when Poetry just doesn't work.

Ballad For when Poetry just doesn't work. Have you tried setting up Poetry, but something doesn't work? Maybe you're... Trying to implement Github Act

BD103 4 Dec 06, 2021
Python PyPi staging server and packaging, testing, release tool

devpi: PyPI server and packaging/testing/release tool This repository contains three packages comprising the core devpi system on the server and clien

629 Jan 01, 2023
Solaris IPS: Image Packaging System

Solaris Image Packaging System Introduction The image packaging system (IPS) is a software delivery system with interaction with a network repository

Oracle 57 Dec 30, 2022
Conan - The open-source C/C++ package manager

Conan Decentralized, open-source (MIT), C/C++ package manager. Homepage: https://conan.io/ Github: https://github.com/conan-io/conan Docs: https://doc

Conan.io 6.5k Jan 05, 2023
Example for how to package a Python library based on Cython.

Cython sample module This project is an example of a module that can be built using Cython. It is an upgrade from a similar model developed by Arin Kh

Juan José García Ripoll 4 Aug 28, 2022
Cilantropy: a Python Package Manager interface created to provide an "easy-to-use" visual and also a command-line interface for Pythonistas.

Cilantropy Cilantropy is a Python Package Manager interface created to provide an "easy-to-use" visual and also a command-line interface for Pythonist

48 Dec 16, 2022
OS-agnostic, system-level binary package manager and ecosystem

Conda is a cross-platform, language-agnostic binary package manager. It is the package manager used by Anaconda installations, but it may be used for

Conda 5.1k Jan 07, 2023
The Fast Cross-Platform Package Manager

The Fast Cross-Platform Package Manager part of mamba-org Package Manager mamba Package Server quetz Package Builder boa mamba Mamba is a reimplementa

Mamba 4k Dec 30, 2022