FastAPI Microservice Patterns: Externalized Configuration

Declarative configuration of microservices made easy

Florian Kromer
Jan 8 · 3 min read
Image for post
Image for post
private screenshot

What’s the problem?

The solution!

Pattern implementation

from fastapi import FastAPI
from pydantic import BaseSettings

class Settings(BaseSettings):
string_to_display: str = "World"

settings = Settings()
app = FastAPI()

@app.get("/")
def read_root():
return {"Hello": settings.string_to_display}
(...)apiVersion: apps/v1
kind: Deployment
spec:
containers:
- name: fastapi-service
image: fastapi-service
ports:
- containerPort: 80
env:
- name: STRING_TO_DISPLAY
value: "Another World"
Image for post
Image for post
localhost:9000

The post series content

The Startup

Get smarter at building your thing. Join The Startup’s +776K followers.

Florian Kromer

Written by

Software Developer for rapid prototype or high quality software with interest in distributed systems and high performance on premise server applications.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +776K followers.

Florian Kromer

Written by

Software Developer for rapid prototype or high quality software with interest in distributed systems and high performance on premise server applications.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +776K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store