Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyloid_server_adapter-0.1.8.tar.gz (90.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyloid_server_adapter-0.1.8-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file pyloid_server_adapter-0.1.8.tar.gz.

File metadata

File hashes

Hashes for pyloid_server_adapter-0.1.8.tar.gz
Algorithm Hash digest
SHA256 996b59fcdd0a2e4be3e4073ff35f1fe07db74899bbb3a748e71fbb64282fd8d9
MD5 4fde177fbbbdff68c9a76a110cabc2e3
BLAKE2b-256 8b483ea7e6fd3000b6fe0cbc26fc4bcfefd0150d6ecb1a099c6341b580ab5250

See more details on using hashes here.

File details

Details for the file pyloid_server_adapter-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for pyloid_server_adapter-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ca6c63ebe1b3f9ea44769c3912d37fa01b1818c813ec9647f2ef417a96f93f7c
MD5 74661b21a000f2f2354ada55984fb6a1
BLAKE2b-256 7f84bddbef5990d5d1ecf4b959c1f3833c85662f15a408118d275ddc4a576cab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page