Skip to content

Instantly share code, notes, and snippets.

View BlackHacked's full-sized avatar
📷
Hello World

Latin BlackHacked

📷
Hello World
View GitHub Profile
@wwdegroot
wwdegroot / app.py
Created March 1, 2025 08:55
FastApi proxy endpoint
# adapted from https://github.com/fastapi/fastapi/issues/1788
from fastapi import FastAPI
from starlette.requests import Request
from starlette.responses import StreamingResponse
from starlette.background import BackgroundTask
import uvicorn
import httpx
API_KEY = os.getenv('API_KEY')
@qtangs
qtangs / sql_alchemy.py
Last active November 27, 2024 07:01
chainlit.data.SQLAlchemyDataLayer
# https://github.com/qtangs/chainlit/blob/b81f82c9eff86fc9fd6da6f8f9f09ec03d95d8e0/backend/chainlit/data/sql_alchemy_orm.py
import datetime
import json
import logging
import os
import ssl
import uuid
from typing import Any, Callable, Dict, List, Optional, Union, cast
@thevickypedia
thevickypedia / proxy.py
Last active March 24, 2025 08:54
Basic proxy service using FastAPI (asynchronous)
import logging
from http import HTTPStatus
import httpx
import uvicorn.logging
from fastapi import FastAPI, HTTPException, Request, Response
from fastapi.routing import APIRoute
TARGET_URL = "http://127.0.0.1:8080" # Change this to the URL you want to proxy requests to
@walnutwaldo
walnutwaldo / README.md
Last active March 24, 2025 08:49
FastAPI Proxy

FastAPI HTTP Proxy Application

Introduction

This FastAPI application serves as an HTTP proxy, forwarding client requests to an upstream API server and relaying the server's response back to the client. It supports arbitrary paths and HTTP methods, providing a versatile proxy solution for various API interactions.

Requirements

  • Python 3.6 or higher
  • FastAPI
  • Uvicorn
  • HTTPX
@KokoseiJ
KokoseiJ / db.py
Created January 18, 2024 07:02
Simple Asynchronous MongoDB ORM on Python
import re
import asyncio
from pymongo import MongoClient
from pymongo.collection import Collection as MongoCollection
from pymongo.results import InsertOneResult, UpdateResult, DeleteResult
from typing import Awaitable, Self
mongo: MongoClient = None
DATABASE_NAME = "kokomemo"
@Calcifer777
Calcifer777 / reverse_proxy.py
Last active March 24, 2025 08:47
fasatapi reverse proxy
from fastapi import FastAPI, Request
from fastapi.responses import StreamingResponse
from starlette.background import BackgroundTask
import httpx
app = FastAPI()
client = httpx.AsyncClient(base_url="http://localhost:8000/")
async def reverse_proxy(r: Request):
@gdamjan
gdamjan / README.md
Last active March 24, 2025 08:55
fastapi and proxies

Quickstart

pdm install

These are equivalent (given the main.py code)

UVICORN_ROOT_PATH=/api/ pdm run uvicorn main:app
FASTAPI_ROOT_PATH=/api/ pdm run uvicorn main:app
## Build angular site
- name: build
pull: if-not-exists
image: node:16.18.1-alpine
when:
branch:
- master
event:
- push
commands:

每个 Python 程序员可能都会遇到这样的场景:你写了一个 Python 程序,可能是一个简单的、包含单个文件的 、只使用了标准库的 Python 脚本,抑或是一个庞大的、包含多个模块的、甚至引用了大量的第三方库的复杂 Python 应用,如何将他们送到目标用户手中,让他们能很顺利地使用起来呢?

一种方案就是写一个详尽的文档,连带着你的程序一起发送给用户。文档中要说明,目标用户如何在自己机器上安装 Python 环境及依赖的包,如何对程序进行配置,等等。但倘若你的目标用户没用过 Python 甚至不懂编程,此种方案执行起来便困难重重。

另一种方案,就是将 Python 程序“打包”成可执行程序(.exe),只要目标用户具备基本的电脑操作技能,便能很容易地将程序运行起来。

在 Windows 平台上,将 Python 程序“打包”为可执行程序(.exe)的方案很多,我尝试过的方案有如下几种:

@nilleb
nilleb / proxy.py
Created July 11, 2022 19:12
CORS proxy
# -*- coding: utf-8 -*-
# forwards the calls to http://localhost:8000/https://google.com to https://google.com - copying the headers, query strings, etc
from fastapi import FastAPI, Request, Response
from fastapi.middleware.cors import CORSMiddleware
import requests
app = FastAPI()