PyLoid Server Adapter
Project description
Pyloid Server Adapter
Pyloid Server Adapter는 Pyloid 애플리케이션과 웹 서버(FastAPI, Flask) 간의 원활한 통합을 위한 어댑터입니다.
기능
- Pyloid 인스턴스 및 브라우저 창 관리
- HTTP 요청에서 자동 컨텍스트 생성
- FastAPI 및 Flask와의 통합
- 서버 라이프사이클 관리
설치
pip install pyloid-server-adapter
FastAPI 사용법
방법 1: 어댑터 인스턴스 사용
from fastapi import FastAPI, Depends
from pyloid_server_adapter import FastAPIAdapter, PyloidContext
app = FastAPI()
adapter = FastAPIAdapter(app=app, start_function=start_server)
# Pyloid 인스턴스 설정
adapter.pyloid = pyloid_instance
# 의존성 주입을 통한 컨텍스트 사용
@app.get("/api/test")
async def test_endpoint(ctx: PyloidContext = Depends(adapter.get_pyloid_dependency)):
return {
"pyloid": ctx.pyloid is not None,
"window": ctx.window is not None
}
방법 2: 전역 인스턴스 사용 (권장)
from fastapi import FastAPI, Depends
from pyloid_server_adapter import set_global_pyloid_instance, get_global_pyloid_context, PyloidContext
app = FastAPI()
# Pyloid 인스턴스 전역 설정
set_global_pyloid_instance(pyloid_instance)
# 전역 의존성 함수 사용
@app.get("/api/test")
async def test_endpoint(ctx: PyloidContext = Depends(get_global_pyloid_context)):
return {
"pyloid": ctx.pyloid is not None,
"window": ctx.window is not None
}
Flask 사용법
from flask import Flask
from pyloid_server_adapter import FlaskAdapter, PyloidContext
app = Flask(__name__)
adapter = FlaskAdapter(app=app, start_function=start_server)
# Pyloid 인스턴스 설정
adapter.pyloid = pyloid_instance
# 데코레이터를 통한 컨텍스트 사용
@app.route("/api/test")
@adapter.pyloid_context
def test_endpoint(ctx: PyloidContext):
return {
"pyloid": ctx.pyloid is not None,
"window": ctx.window is not None
}
Flask는 FastAPI와 달리 의존성 주입 시스템이 없기 때문에 데코레이터 방식을 사용합니다.
요구사항
- Python 3.8+
- FastAPI (FastAPI 어댑터 사용 시)
- Flask (Flask 어댑터 사용 시)
- pyloid
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyloid_server_adapter-0.1.7.tar.gz.
File metadata
- Download URL: pyloid_server_adapter-0.1.7.tar.gz
- Upload date:
- Size: 90.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e76119c164220616e1e8235659454ea7cf6f0cad1877af13852c78c81f91b661
|
|
| MD5 |
14f3abf18452dd33c320c089aee78677
|
|
| BLAKE2b-256 |
384e8d64afcbc3fbf0d441bdabd02a583f6a1544df5ef85b780f3adf13a9c82b
|
File details
Details for the file pyloid_server_adapter-0.1.7-py3-none-any.whl.
File metadata
- Download URL: pyloid_server_adapter-0.1.7-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b44f8caf0bbc65476825494285e3dfa212c5cfaf9481a0972eab6240379ffb2
|
|
| MD5 |
2f3aaa727389f082e205faf425e2f09b
|
|
| BLAKE2b-256 |
60741ca46210504698689b7c3143d0b869d3224141f7315a6413cc868aeaaa41
|