uv ?
uv는 python 프로젝트와 package를 매니징할 수 있는 도구이다.
uv
An extremely fast Python package and project manager, written in Rust. Installing Trio's dependencies with a warm cache. 🚀 A single tool to replace pip, pip-tools, pipx, poetry, pyenv, virtualenv, and more. ⚡️ 10-100x faster than pip. 🐍 Installs
docs.astral.sh
python에는 기본적으로 venv라는 내장 라이브러리가 존재한다.
https://docs.python.org/3/library/venv.html
venv — Creation of virtual environments
Source code: Lib/venv/ The venv module supports creating lightweight “virtual environments”, each with their own independent set of Python packages installed in their site directories. A virtual en...
docs.python.org
보통 python으로 가벼운 task를 진행하거나, 개인 공부를 할 때는 venv를 활용하여 프로젝트를 진행했다.
아래 command 들이 보통 활용하는 것들이다.
# 파이썬 가상환경 생성
python -m venv 가상환경이름
# 가상환경 활성화
source ./venv/bin/activate
# pip 패키지 설치
pip3 install 패키지이름
# pip로 설치된 package 관리
pip3 freeze > requirements.txt
# requirements로 설치된 package 설치
pip3 install -r requirements.txt
하지만, venv 만을 사용하는 경우에 project가 커지면서 dependency들을 관리하기 어려워지면서, poetry, pipenv 와 같은 가상환경으로 프로젝트를 관리하고 있다.
uv에서도 위와 같은 작업을 진행할 수 있고, 또한 빠르게 진행할 수 있다고 하여 직접 사용해봤다.
사용 방법 mac 기준으로 작성했다.
# brew를 사용하여 uv 설치
brew install uv
uv를 설치하고 나면, python을 특정 버전으로 설치할 수 있고, 가상환경을 생성할 수 있다.
# python 설치
uv python install {설치할 python 버전}
# 가상환경 생성
uv venv
# 가상환경을 생성할 파이썬 버전 지정
uv venv --python 사용할 버전
# 가상환경 활성화
source .venv/bin/activate
이제 필요한 package들을 설치하면 된다.
# 패키지 설치
uv pip install 패키지명
해당 방법 외에도 pyproject.toml 과 함께 프로젝트를 관리할 수 있다.
https://docs.astral.sh/uv/guides/projects/
# 프로젝트 생성
uv init 디렉토리이름
해당 command를 통해 프로젝트를 생성할 수 있고, 아래와 같은 프로젝트 구조로 관리할 수 있다.

아래 커맨드로 package를 설치할 수 있다.
uv add 패키지명
uv 로 프로젝트를 구성하는 방식은 poetry와 비슷하여.. sync, lock 과 같은 command로 프로젝트 의존성을 관리할 수 있다.
또한 해당 프로젝트 패키지를 배포하고 싶을 때는 uv build로 .whl을 만들 수 있다!
Docker와 함께 관리
대개 프로젝트 배포의 용이성을 위해 Docker를 사용하는데, 이때 아래와 같이 Dockerfile을 작성하여 활용할 수 있다.
해당 프로젝트에서는 requirements.txt를 활용하고 있고, venv를 사용할 때와 비슷하게,
uv pip freeze 라는 커맨드를 통해 관리할 수 있다.
FROM python:3.12-slim-bookworm
# The installer requires curl (and certificates) to download the release archive
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates
# Download the latest installer
ADD https://astral.sh/uv/install.sh /uv-installer.sh
# Run the installer then remove it
RUN sh /uv-installer.sh && rm /uv-installer.sh
# Ensure the installed binary is on the `PATH`
ENV PATH="/root/.cargo/bin/:$PATH"
ADD . /app
WORKDIR /app
RUN uv pip install -r requirements.txt --system
EXPOSE 8000
CMD [ "uv", "run", "main.py"]
실제 서버에서 배포하는 과정에서 uv를 사용했을 때, image를 빌드하는 시간이 훨씬 단축되었다.
ruff
astral에서 uv와 함께 ruff라는 linter/code formatter 오픈소스가 있다.
기존 프로젝트에서 black, flake8으로 linting과 formatting을 하고 있었다.
https://github.com/astral-sh/ruff
GitHub - astral-sh/ruff: An extremely fast Python linter and code formatter, written in Rust.
An extremely fast Python linter and code formatter, written in Rust. - astral-sh/ruff
github.com
README.md에 나와있는 것처럼 flake8을 사용할 때 보다 성능이 더욱 빠른 것으로 확인되어, 적용해보기로 결정했다.

가상환경을 poetry로 사용하고 있어, pyproject.toml에서 프로젝트 설정을 관리하고 있었고,
https://docs.astral.sh/ruff/tutorial/
Tutorial - Ruff
Tutorial This tutorial will walk you through the process of integrating Ruff's linter and formatter into your project. For a more detailed overview, see Configuring Ruff. Getting Started To start, we'll install Ruff through PyPI (or with your preferred pac
docs.astral.sh
ruff의 튜토리얼이 어렵지 않아 쉽게 적용할 수 있었다.
ruff check
ruff format
두 커맨드로 코드 포매팅을 할 수 있었고, 기존 .pre-commit-hooks.yaml로 대체할 수 있었다 ..!
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.8
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
적용후에 동일하게 formatting 했을 때 기존 방법보다 확실히 빨라진 것을 체감할 수 있었다 ...! 현재는 로컬에서만 적용된 상태인데, github action의 CI 과정에서도 추가하여 적용해볼 계획이다.