Python/FastAPI (6) 썸네일형 리스트형 FastAPI + SQLAlchemy: DB Connection이 지속적으로 생기는 문제 FastAPI는 일반적으로 SQLAlchemy와 함께 사용하며,다수의 커넥션풀을 유지하기 위해서 QueuePool을 사용한다.(비동기 데이터베이스 라이브러리 사용시에는 QueuePool이 아닌 async에 맞는 풀 사용)# database.pyfrom sqlalchemy import create_enginefrom sqlalchemy.pool import QueuePoolfrom sqlalchemy.orm import sessionmakersync_engine = create_engine( SYNC_DATABASE_URL, poolclass=QueuePool, pool_size=20, max_overflow=5, pool_timeout=30, pool_recycle=360.. FastAPI + SQLAlchemy: connection pool log 찍기 # Pool 커스텀 https://github.com/Junanjunan/g6/commit/709b910470c6c216f5e7d5870f1403095b7ef44e 로그 생성용 커스텀 커넥션 풀 설정 · Junanjunan/g6@709b910Junanjunan committed May 3, 2024github.com FastAPI, Javascript: EventSource Example EventSource HTTP를 통해서 server-sent-events (SSEs)를 받기 위한 인터페이스 페이지 새로고침 없이 real-time(실시간)으로 서버에서 데이터를 받을 때 유용하게 쓸 수 있다. 아래는 오픈소스 g6의 데이터 베이스가 설치되는 과정에서 Python 코루틴을 활용하여 백엔드 FastAPI에서 프론트엔드 Javascript로 페이지 리로딩 없이 설치 정보를 전달하는 예제 @router.get("/process") async def install_process(request: Request): async def install_event(): db_connect = DBConnect() engine = db_connect.engine SessionLocal = db_connect.. FastAPI: WebSocket Example 1. Websocket을 통해 서버로부터 일정 주기로 데이터 받아오기 * fastapi와 websocket 사용을 위한 uvicorn[standard] 설치 pip install fastapi "uvicorn[standard]" * main.py from fastapi import FastAPI, WebSocket import asyncio app = FastAPI() @app.websocket("/ws") async def websocket_endpoint(websocket: WebSocket): await websocket.accept() counter = 0 while True: counter += 1 await websocket.send_json({"message": f"Update #{count.. request.scope vs request.headers in FastAPI # ChatGPT Q. in Python FastAPI, How can I see the request user's prefix whethere http or https? A. In FastAPI, you can determine whether a request uses HTTP or HTTPS by inspecting the request object. The request object contains various information about the incoming HTTP request, including the scheme which indicates whether the request was made using HTTP or HTTPS. To access the request object in FastAPI,.. FastAPI description FastAPI is a Python class that provides all the functionality for your API FastAPI is a class that inherits directly from Starlette. You can use all the Starlette functionality with FastAPI too. (https://fastapi.tiangolo.com/tutorial/first-steps) Pydantic All the data validation is performed under the hood by Pydantic, so you get all the benefits from it. And you know you are in good hands. Pyda.. 이전 1 다음