Skip to content

Instantly share code, notes, and snippets.

View Kludex's full-sized avatar

Marcelo Trylesinski Kludex

View GitHub Profile
@Kludex
Kludex / redoc.py
Last active October 8, 2024 07:14
Export FastAPI ReDoc to HTML
"""
Script to export the ReDoc documentation page into a standalone HTML file.
Created by https://github.com/pawamoy on https://github.com/Redocly/redoc/issues/726#issuecomment-645414239
"""
import json
from my_app.app import app
HTML_TEMPLATE = """<!DOCTYPE html>
@Kludex
Kludex / main.py
Last active August 31, 2021 17:42
Create dynamic endpoints in FastAPI - DO NOT USE THIS!
import random
import string
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
app = FastAPI()
def custom_openapi():
@Kludex
Kludex / main.py
Last active April 17, 2024 01:55
Document each version on FastAPI
from fastapi import APIRouter, FastAPI
from utils import create_versioning_docs
app = FastAPI(docs_url=None, redoc_url=None)
v1_router = APIRouter(prefix="/v1")
v2_router = APIRouter(prefix="/v2")
@Kludex
Kludex / main.py
Last active March 19, 2025 17:07
Run Gunicorn with Uvicorn workers in code
""" Snippet that demonstrates how to use Gunicorn with Uvicorn workers in code.
Feel free to run:
- `python main.py` - to use uvicorn.
- `ENV=prod python main.py` - to use gunicorn with uvicorn workers.
Reference: https://docs.gunicorn.org/en/stable/custom.html
"""
@Kludex
Kludex / camelize_body_and_query.py
Created February 17, 2021 21:35
Camelize Body and Query parameters
from fastapi import Body, FastAPI
from fastapi.routing import APIRoute, APIRouter
from humps import camelize
from pydantic import BaseModel
app = FastAPI()
router = APIRouter(prefix="/haha")
@Kludex
Kludex / rabbitmq_client.py
Created January 3, 2021 14:18
Async init
import asyncio
from typing import Type
from aio_pika import RobustConnection, connect_robust
from aio_pika.connection import ConnectionType
from aio_pika.types import TimeoutType
class RabbitMQClient:
def __init__(
{"version":1,"resource":"file:///home/marcelo/Development/personal/fastapix/fastapix/loader.py","entries":[{"id":"BxHT.py","timestamp":1666628557303},{"id":"L1X5.py","timestamp":1666628585759},{"id":"QW4O.py","source":"Workspace Edit","timestamp":1666628588867},{"id":"AS97.py","timestamp":1666628591388},{"id":"JbgL.py","timestamp":1666628645376},{"id":"dwcf.py","source":"Workspace Edit","timestamp":1666628655876},{"id":"8sP0.py","timestamp":1666628671132},{"id":"HtJ7.py","source":"Workspace Edit","timestamp":1666628673152}]}