This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GH_CONFIG := ~/.config/gh/hosts.yml | |
GITHUB_USER := $(shell cat $(GH_CONFIG) | yq '.[].user' | xargs) | |
GITHUB_TOKEN := $(shell cat $(GH_CONFIG) | yq '.[].oauth_token' | xargs) | |
.PHONY: all | |
build: | |
docker build --build-arg=GITHUB_USER=$(GITHUB_USER) --build-arg=GITHUB_TOKEN=$(GITHUB_TOKEN) . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import Column, Float, Integer, String | |
from sqlalchemy.orm import declarative_base | |
Base = declarative_base() | |
class Company(Base): | |
id = Column(Integer, primary_key=True) | |
name = Column(String) | |
worth = Column(Float) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.10-slim AS install | |
RUN apt-get update \ | |
&& apt-get upgrade -y \ | |
&& apt-get install -y --no-install-recommends curl \ | |
&& apt-get autoremove -y | |
RUN pip install --upgrade pip | |
WORKDIR /app/ | |
# install poetry and keep the get-poetry script so it can be reused later. | |
ENV POETRY_HOME="/opt/poetry" | |
RUN curl https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py > get-poetry.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from starlette.status import HTTP_200_OK | |
from starlite import create_test_client | |
from my_app.main import health_check | |
def test_health_check(): | |
with create_test_client(route_handlers=[health_check]) as client: | |
response = client.get("/health-check") | |
assert response.status_code == HTTP_200_OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from starlite import Starlite, MediaType, get | |
@get(path="/health-check", media_type=MediaType.TEXT) | |
def health_check() -> str: | |
return "healthy" | |
app = Starlite(route_handlers=[health_check]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from starlite import Starlite, LoggingConfig | |
from my_app.users import UserController | |
app = Starlite( | |
route_handlers=[UserController], | |
on_startup=[ | |
LoggingConfig(loggers={ | |
"my_app": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import environ | |
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine | |
# we first define a dependency. The dependency is a function or method (async or sync) whose return value will be injected | |
def create_postgres_connection() -> AsyncEngine: | |
postgres_connection_string = environ.get("POSTGRES_CONNECTION_STRING", "") | |
if not postgres_connection_string: | |
raise ValueError("Missing ENV Variable POSTGRES_CONNECTION_STRING") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
from pydantic import UUID4 | |
from starlite import Controller, Partial, get, post, put, patch, delete | |
from my_app.models import User | |
class UserController(Controller): | |
path = "/users" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
from starlite import Partial, delete, get, patch, post, put | |
from my_app.models import Resource | |
@get(path="/resources") | |
def list_resources() -> List[Resource]: | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Optional | |
from fastapi import FastAPI | |
app = FastAPI() | |
@app.get("/") | |
def read_root(): | |
return {"Hello": "World"} |
NewerOlder