| name | dependency-review |
| description | Python 프로젝트 의존성 관리 및 검토 가이드 |
| version | 1.0.0 |
| tags | ["python","dependencies","packages","vulnerability","supply-chain"] |
| author | deep-research-MAF |
Dependency Review Skill
Overview
Python 프로젝트의 의존성 패키지 관리, 취약점 검토, 업데이트 및 최적화 가이드
Dependency Management Tools
1. Pip-audit
PyPI 패키지 보안 감사
uv add --dev pip-audit
pip-audit
pip-audit --vulnerability-service osv --severity HIGH
pip-audit --fix
pip-audit -r requirements.txt
pip-audit --ignore-vuln PYSEC-2023-XXX
2. Safety
Known Security Vulnerabilities 체크
uv add --dev safety
safety check
safety check -r requirements.txt
safety check --json
safety check --full-report
safety check --ignore 12345
3. Pipdeptree
의존성 트리 시각화
uv add --dev pipdeptree
pipdeptree
pipdeptree -r -p requests
pipdeptree --json
pipdeptree --graph-output png > dependencies.png
pipdeptree -p fastapi
4. UV (권장)
Rust 기반의 빠른 Python 패키지 관리자 - 의존성 관리, 잠금, 동기화
uv init
uv add fastapi uvicorn pydantic
uv add --dev pytest ruff mypy
uv sync
uv lock --upgrade
uv add fastapi@latest
pyproject.toml (UV 사용)
[project]
name = "deep-research-maf"
version = "1.0.0"
requires-python = ">=3.12"
dependencies = [
"fastapi>=0.104.0",
"uvicorn[standard]>=0.25.0",
"pydantic>=2.0",
"python-dotenv",
"openai>=1.0.0",
]
[dependency-groups]
dev = [
"pytest>=7.4.0",
"ruff>=0.1.0",
"mypy>=1.7.0",
]
uv.lock (자동 생성)
- 모든 의존성 버전 잠금
- 크로스 플랫폼 재현성 보장
- Git에 커밋 권장
5. UV vs Poetry vs Pip
| Feature | UV (권장) | Poetry | Pip |
|---|
| 속도 | ⚡️ 매우 빠름 | 보통 | 보통 |
| 의존성 잠금 | ✅ uv.lock | ✅ poetry.lock | ❌ (pip-tools 필요) |
| pyproject.toml | ✅ 표준 | ✅ 비표준 | ❌ |
| 가상환경 관리 | ✅ 자동 | ✅ 자동 | ❌ 수동 |
| 패키지 빌드 | ✅ | ✅ | ❌ |
| 취약점 검사 | 외부 도구 | 외부 도구 | 외부 도구 |
UV 사용 권장 이유:
- Rust로 작성되어 pip보다 10-100배 빠름
- PEP 표준 pyproject.toml 사용
- 간단한 명령어 구조
- 의존성 자동 해결 및 잠금
curl -LsSf https://astral.sh/uv/install.sh | sh
uv init
uv add fastapi uvicorn
uv sync
uv add --dev pytest ruff
uv run uvicorn main:app
Dependency Analysis
1. License Compliance
uv add --dev pip-licenses
pip-licenses
pip-licenses --with-urls --with-description
pip-licenses --format=csv --output-file=licenses.csv
pip-licenses --filter-by-license="MIT"
주요 라이선스 호환성:
- ✅ MIT, Apache 2.0, BSD: 상업적 사용 가능
- ⚠️ LGPL: 동적 링크 시 가능
- ❌ GPL: 상업적 사용 시 전체 코드 공개 필요
2. Outdated Packages
uv tree --outdated
pip list --outdated
pip show fastapi
pip list --outdated --format=json | jq -r '.[] | .name' | xargs -n1 pip install -U
3. Dependency Conflicts
uv sync
pip check
pipdeptree --warn conflict
pipdeptree -r -p package-name
4. Unused Dependencies
uv add --dev pipreqs
pipreqs backend/src --force
diff requirements.txt backend/src/requirements.txt
Dependency Pinning Strategies
UV를 사용하는 경우 (권장)
[project]
dependencies = [
"fastapi>=0.104.0",
"uvicorn>=0.25.0",
]
장점:
- pyproject.toml에는 최소 버전만 명시
- uv.lock에 정확한 버전 자동 고정
uv sync로 일관된 환경 보장
uv lock --upgrade로 안전하게 업데이트
requirements.txt를 사용하는 경우
1. Exact Pinning (Reproducible)
# requirements.txt
fastapi==0.104.1
uvicorn==0.25.0
장점: 완벽한 재현성
단점: 보안 패치 누락 가능
2. Compatible Release (~=)
# requirements.txt
fastapi~=0.104.0 # >=0.104.0, <0.105.0
uvicorn~=0.25.0 # >=0.25.0, <0.26.0
장점: 마이너 업데이트 자동 적용
단점: 예상치 못한 변경 가능
3. Minimum Version (>=)
# requirements.txt
fastapi>=0.104.0
uvicorn>=0.25.0
장점: 최신 기능 사용 가능
단점: 호환성 문제 발생 가능
4. Recommended: Two-file Approach
# requirements.in (loose)
fastapi>=0.104.0
uvicorn[standard]>=0.25.0
# requirements.txt (pinned, from pip-compile)
fastapi==0.104.1
uvicorn==0.25.0
click==8.1.7
...
Vulnerability Management
1. Automated Scanning
name: Dependency Review
on:
pull_request:
schedule:
- cron: '0 0 * * 0'
jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install UV
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Sync dependencies
run: uv sync --dev
- name: Dependency Review
uses: actions/dependency-review-action@v3
with:
fail-on-severity: moderate
- name: Pip Audit
run: |
uv add --dev pip-audit
pip-audit
- name: Safety Check
run: |
uv add --dev safety
safety check --json
2. Dependabot Configuration
version: 2
updates:
- package-ecosystem: "pip"
directory: "/backend"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
reviewers:
- "your-team"
labels:
- "dependencies"
- "python"
versioning-strategy: increase
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-major"]
3. Manual Review Process
#!/bin/bash
echo "📦 Dependency Review Starting..."
echo "\n1️⃣ Checking outdated packages..."
pip list --outdated
echo "\n2️⃣ Scanning for vulnerabilities..."
pip-audit
echo "\n3️⃣ Checking licenses..."
pip-licenses --format=markdown
echo "\n4️⃣ Checking for conflicts..."
pip check
echo "\n5️⃣ Dependency tree..."
pipdeptree --warn conflict
echo "\n✅ Review complete!"
Update Strategies
1. Safe Update Process (UV 사용)
cp uv.lock uv.lock.backup
uv tree --outdated
uv add fastapi@latest
uv run pytest
git add pyproject.toml uv.lock
git commit -m "chore: update fastapi"
cp uv.lock.backup uv.lock
uv sync
2. Batch Update (UV)
uv lock --upgrade
uv sync
uv run pytest
git add pyproject.toml uv.lock
git commit -m "chore: update all dependencies"
3. Security-only Updates
uv add --dev pip-audit
pip-audit --format json > vulns.json
pip-audit --fix
pip-audit
Dependency Optimization
1. Remove Unused Dependencies
uv remove <unused-package>
uv add --dev pipreqs
pipreqs backend/src --force --savepath actual_requirements.txt
uv remove <unused-package>
2. Minimize Dependencies
import pandas as pd
df = pd.DataFrame([1, 2, 3])
data = [1, 2, 3]
3. Alternative Packages
Consider lighter alternatives:
httpx instead of requests (async support)
orjson instead of json (faster)
uvloop instead of asyncio (faster)
Best Practices
1. Version Control
git add pyproject.toml uv.lock
git commit -m "deps: update dependencies"
2. Development vs Production
[project]
dependencies = [
"fastapi>=0.104.0",
"uvicorn[standard]>=0.25.0",
]
[dependency-groups]
dev = [
"pytest>=7.4.0",
"pytest-asyncio>=0.21.0",
"ruff>=0.1.0",
"mypy>=1.7.0",
]
uv sync --no-dev
uv sync --dev
uv sync
3. Docker Optimization
# UV를 사용한 최적화된 Dockerfile
FROM python:3.12-slim
# UV 설치
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app
# 의존성 파일만 먼저 복사 (캐시 최적화)
COPY pyproject.toml uv.lock ./
# Production 의존성만 설치
RUN uv sync --frozen --no-dev
# 애플리케이션 코드 복사
COPY . .
# UV로 실행
CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0"]
장점:
- 단일 스테이지로 간소화
- UV의 빠른 설치 속도 활용
- uv.lock으로 정확한 재현성 보장
--frozen 플래그로 lock 파일 불일치 방지
Monitoring & Alerts
1. GitHub Security Alerts
Enable Dependabot alerts:
- Settings → Security & analysis → Dependabot alerts
2. Snyk Integration
name: Snyk Security
on: [push, pull_request]
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: snyk/actions/python@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: test
3. Regular Audits
0 0 * * 0 cd /path/to/project && pip-audit | mail -s "Dependency Audit" team@example.com
Quick Commands
uv tree
uv tree --outdated
uv add --dev pip-audit && pip-audit
uv add --dev safety && safety check
uv add --dev pip-licenses && pip-licenses
uv lock --upgrade
uv sync
uv run pytest
uv add --dev pip-audit && pip-audit --fix
Dependency Review Checklist
References