728x90

FastAPI 개발자 tiangolo는 FastAPI를 어떻게 사용할까 궁금해서 찾아본 프로젝트

https://github.com/tiangolo/full-stack-fastapi-postgresql

이번 게시글에서는 프로젝트 설정파일인 project.toml을 분석하려고 함

 

pyproject.toml 설명

[tool.poetry]
name = "app"
version = "0.1.0"
description = ""
authors = ["Admin <admin@example.com>"]

[tool.poetry.dependencies]
python = "^3.10"
uvicorn = "^0.24.0.post1"
fastapi = "^0.104.1"
python-multipart = "^0.0.6"
email-validator = "^2.1.0.post1"
celery = "^5.3.5"
passlib = {extras = ["bcrypt"], version = "^1.7.4"}
tenacity = "^8.2.3"
pydantic = ">2.0"
emails = "^0.6"
gunicorn = "^21.2.0"
jinja2 = "^3.1.2"
alembic = "^1.12.1"
python-jose = {extras = ["cryptography"], version = "^3.3.0"}
httpx = "^0.25.1"
psycopg = {extras = ["binary"], version = "^3.1.13"}
sqlmodel = "^0.0.16"
# Pin bcrypt until passlib supports the latest
bcrypt = "4.0.1"
pydantic-settings = "^2.2.1"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.3"
pytest-cov = "^4.1.0"
mypy = "^1.8.0"
ruff = "^0.2.2"
pre-commit = "^3.6.2"

[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
line_length = 88

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

[tool.mypy]
strict = true

[tool.ruff]
target-version = "py310"

[tool.ruff.lint]
select = [
    "E",  # pycodestyle errors
    "W",  # pycodestyle warnings
    "F",  # pyflakes
    "I",  # isort
    "B",  # flake8-bugbear
    "C4",  # flake8-comprehensions
    "UP",  # pyupgrade
]
ignore = [
    "E501",  # line too long, handled by black
    "B008",  # do not perform function calls in argument defaults
    "W191",  # indentation contains tabs
    "B904",  # Allow raising exceptions without from e, for HTTPException
]

[tool.ruff.lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true

 

  • [tool.poetry] 섹션
    • 프로젝트의 기본 정보를 정의
    • name: 프로젝트의 이름
    • version: 프로젝트의 버전
    • description: 프로젝트에 대한 간단한 설명
    • authors: 프로젝트 저자들의 이메일 주소를 포함한 리스트
  • [tool.poetry.dependencies] 섹션
    • 여러 Python 라이브러리와 프레임워크에 대한 의존성을 정의 (requirements.txt와 유사한 역할)
    • python: 사용할 Python 버전
    • uvicorn, fastapi, python-multipart, ...: FastAPI와 관련된 라이브러리 및 도구들
    • pydantic: 데이터 유효성 검사 및 설정을 위한 라이브러리
    • gunicorn, jinja2, alembic, ...: 다양한 라이브러리 및 도구들
    • bcrypt: 비밀번호 해싱을 위한 라이브러리
    • pydantic-settings: Pydantic 설정을 관리하기 위한 도구
  • [tool.isort] 섹션
    • 코드를 정렬하기 위한 isort 설정
    • 참고 : isort는 Python 코드 파일의 import 문을 정렬해주는 도구
  • [build-system] 섹션
    • 프로젝트 빌드에 사용되는 도구 및 설정
  • [tool.mypy] 섹션
    • mypy 정적 타입 검사 도구의 설정
    • 참고 : mypy는 Python 코드의 정적 타입 검사를 수행하는 도구로 런타임 이전에 코드를 분석하여 타입 오류를 찾아내고 이를 사전에 방지
  • [tool.ruff] 섹션
    • ruff 코드 포맷터 및 정적 분석 도구의 설정
    • 참고 : ruff는 rust로 만든 매우 빠른 Python linter
    • 참고 : linter는 코드의 오류나 버그가 있는지 확인하고 정해진 규칙을 잘 지키고 있는지에 대한 것들을 개발하면서 확인 및 점검을 하기 위해 사용하는 도구

 

pyproject.toml을 이용한 poetry 가상환경 설정

pyproject.toml이 있는 경우 poetry를 이용하여 간단하게 가상환경을 세팅할 수 있음

pip install --upgrade pip
pip install poetry
poetry install
poetry shell

 

가상환경을 세팅한 후에는 vscode에서 F1Python: Select Interpreter 를 클릭하여 poetry 가상환경 사용 가능

 

참고 : FastAPI 개발자가 직접 개발한 FastAPI backend 시리즈

FastAPI 개발자가 직접 개발한 FastAPI backend 프로젝트 구조

FastAPI 개발자가 직접 개발한 FastAPI backend alembic

FastAPI 개발자가 직접 개발한 FastAPI backend DB 초기화 방법

FastAPI 개발자가 직접 개발한 FastAPI backend pyproject.toml

FastAPI 개발자가 직접 개발한 FastAPI backend 설정파일 config.py

FastAPI 개발자가 직접 개발한 FastAPI backend 데이터모델 models.py

 

728x90

+ Recent posts