✨ 일반적으로 머신러닝 서버가 존재하거나 커다란 서버 안에 머신러닝 파트가 존재한다.
- Monolithic Architecture : 하나의 큰 서버에서 파트 별로 처리하는 형식
- Build 가 무거워지고 부분 Side Effect 발생 시 전체 서비스가 영향 받는다.
✨ 참고 : 프로젝트 구조 (v1)
- 프로젝트의 코드가 들어갈 모듈 설정(ap)
__main__.py
: 간단하게 애플리케이션을 실행할 수 있는 entry pointmain.py
또는app.py
: FastAPI 의 애플리케이션과 Router 설청model.py
는 ML model 에 대한 클래스와 함수 정의
virtualenv 는 순차적 설치라 의존성이 깨지기 쉽다. Poetry 는 이 점을 보완한다.
poetry init
poetry shell
- poetry 활성화
poetry install
- .toml 에 저장된 내용을 바탕으로 라이브러리 설치
poetry add
- 필요한 패키지를 추가하고 싶은 경우 사용
curl -sSL https://install.python-poetry.org | python3 -
export PATH="/opt/ml/.local/bin:$PATH"
를 추가 해주어야 한다. Retrieving Poetry metadata
# Welcome to Poetry!
This will download and install the latest version of Poetry,
a dependency and package manager for Python.
It will add the `poetry` command to Poetry's bin directory, located at:
/opt/ml/.local/bin
You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.
Installing Poetry (1.3.1): Done
Poetry (1.3.1) is installed now. Great!
To get started you need Poetry's bin directory (/opt/ml/.local/bin) in your `PATH`
environment variable.
Add `export PATH="/opt/ml/.local/bin:$PATH"` to your shell configuration file.
Alternatively, you can call Poetry explicitly with `/opt/ml/.local/bin/poetry`.
You can test that everything is set up by executing:
`poetry --version`
shell configuration file 에 추가
export PATH="/opt/ml/.local/bin:$PATH"
[tool.poetry]
name = "test-fastapi"
version = "0.1.0"
description = "FastAPI Test"
authors = ["hobbang2 <cattie@pukyong.ac.kr>"]
license = "MIT"
readme = "README.md"
packages = [{include = "test_fastapi"}]
[tool.poetry.dependencies]
python = ">=3.6.2,<3.10"
fastapi = "^0.70.0"
uvicorn = "^0.15.0"
pandas = "1.0.0"
[tool.poetry.group.dev.dependencies]
pytest = "^6.2.5"
black = "^21.9b0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
from fastapi import FastAPI
app = FastAPI()
# "/" 로 접근하면 return message 를 보여준다.
@app.get("/")
def read_root():
return {"Hello": "World"}
CLI 또는 터미널에서 실행
uvicorn 01_simple_webserver:app --reload --host 0.0.0.0 --port 30001
또는
from fastapi import FastAPI
import uvicorn
app = FastAPI()
# "/" 로 접근하면 return message 를 보여준다.
@app.get("/")
def read_root():
return {"Hello": "World"}
if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0",port=30001)
- PowerShell 에서 (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
- 환경 변수 추가
To get started you need Poetry's bin directory ($USERPROFILE$\AppData\Roaming\Python\Scripts) in your <PATH> environment variable.
- PowerShell 에서 poetry --version
이 글은 커넥트 재단 Naver AI Boost Camp 교육자료를 참고했습니다.