This file contains hidden or 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 fastapi import APIRouter | |
router = APIRouter(prefix="/haha") | |
@router.get("/haha") | |
def home(): | |
... |
This file contains hidden or 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
import io | |
from typing import Any | |
import anyio | |
import ijson | |
from anyio.streams.buffered import BufferedByteReceiveStream | |
from anyio.streams.memory import MemoryObjectReceiveStream | |
from fastapi import FastAPI, Request, UploadFile | |
app = FastAPI() |
This file contains hidden or 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
# Inspired by https://snyk.io/blog/best-practices-containerizing-python-docker/ | |
FROM python:3.10-slim | |
ENV PIP_NO_CACHE_DIR=off | |
RUN groupadd -g 999 python \ | |
&& useradd -r -u 999 -g python python \ | |
&& mkdir /usr/app \ | |
&& chown python:python /usr/app |
This file contains hidden or 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 TYPE_CHECKING | |
if TYPE_CHECKING: | |
from typing import Any, Callable, Generic, Literal, Protocol, Tuple, overload | |
from celery import Celery as _Celery | |
from celery import Task as _Task | |
from typing_extensions import TypeVarTuple, Unpack | |
Ts = TypeVarTuple("Ts") |
This file contains hidden or 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 __future__ import annotations | |
from typing import overload | |
@overload | |
def potato(a: int, b: None = None) -> int: | |
... | |
This file contains hidden or 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 __future__ import annotations | |
from starlette.datastructures import MutableHeaders | |
BROWSER_SYNC_SCRIPT =b"<script>console.log('Hi there!');</script>" | |
class InjectScriptMiddleware: | |
def __init__(self, app, script: bytes = BROWSER_SYNC_SCRIPT): | |
self.app = app | |
self.script = script |
This file contains hidden or 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
import hashlib | |
import os | |
import httpx | |
from httpx_auth import OAuth2AuthorizationCode | |
from pydantic import BaseSettings | |
from rich.console import Console | |
console = Console() |
This file contains hidden or 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
import logging | |
import sys | |
from typing import List | |
import structlog | |
import uvicorn | |
from fastapi import FastAPI | |
from structlog.stdlib import ProcessorFormatter | |
from structlog.types import Processor |
This file contains hidden or 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
#!/bin/sh | |
# Creates a new monorepo by fusing multiple repositories | |
# Mainly copied from http://www.sevangelatos.com/monorepo/ | |
# Child repositories that are going to be fused | |
CHILDREN="repo_lib_a repo_lib_b" | |
# Name of the created monorepo | |
MONOREPO="monorepo" |
This file contains hidden or 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
"""Create a virtual environment, and run a different python process.""" | |
import os | |
import subprocess | |
import tempfile | |
import venv | |
with tempfile.TemporaryDirectory() as temp_dir: | |
VENV_PATH = os.path.join(temp_dir, "venv") | |
venv.create(VENV_PATH, with_pip=True) | |
python_exe = os.path.join(VENV_PATH, "bin", "python") |