Python uv : 패키지 관리 도구Python uv: A Package Management Tool

Rust로 작성된 매우 빠른 Python 패키지 및 프로젝트 관리 도구An extremely fast Python package and project manager written in Rust

written by tiaz0128

uv 소개

uv logo

uv는 astral에서 Rust로 만든 파이썬 패키지 및 프로젝트 관리 도구 입니다. 가장 큰 장점은 패키지 설치가 엄청나게 빠르다는 것입니다.

기존의 pip를 비롯해 여러 패키지 관리도구와 Trio 파이썬 패키지 설치 속도를 비교한 그래프를 참고해보면, uv가 얼마나 빠른지 알수 있습니다.

uv speed

> 출처 : Installing Trio’s dependencies with a warm cache.

또한 의존성 관리를 더 효율적으로 도와줍니다. MCP(Model Context Protocol) 개발에 공식적으로 사용을 권장하면서 더욱 큰 관심을 받고 있습니다.

uv 설치

Installing uv 페이지를 참고해서 설치를 진행합니다.

설치 방법은 크게 두가지로 나눠집니다. 기존의 패키지 관리 도구를 통해 설치하는 방법과 단독으로 독립형(standalone) 설치가 가능합니다.

독립형(standalone) 설치

MCP를 사용할 목적이면 독립형으로 설치할 것을 추천합니다!
# On Windows.
> powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# On macOS and Linux.
$ curl -LsSf https://astral.sh/uv/install.sh | sh

기존 패키지 관리 도구로 설치

# With pip.
$ pip install uv

# Or pipx.
$ pipx install uv

설치 확인

설치가 제대로 됐는지 아래의 명령으로 uv 버전을 확인합니다.

$ uv --version
uv 0.6.3 (a0b9f22a2 2025-02-24)

버전 업데이트

독립형(standalone)으로 설치한 경우에만 아래의 명령으로 uv 버전을 업데이트를 할 수 있습니다.

$ uv self update

uv 명령어 구조

기본적인 사용법은 아래와 같습니다. 몇가지 주요한 명령어를 알아보겠습니다.

사용법: uv [옵션] <명령어>

명령어:
  run      명령어나 스크립트 실행
  init     새 프로젝트 생성
  add      프로젝트에 의존성 추가
  remove   프로젝트에서 의존성 제거
  sync     프로젝트의 환경 업데이트
  lock     프로젝트의 락파일 업데이트
  export   프로젝트의 락파일을 다른 형식으로 내보내기
  tree     프로젝트의 의존성 트리 표시
  tool     Python 패키지가 제공하는 명령어 실행 및 설치
  python   Python 버전 및 설치 관리
  pip      pip 호환 인터페이스로 Python 패키지 관리
  venv     가상 환경 생성
  build    Python 패키지를 소스 배포판 및 휠로 빌드
  publish  배포판을 인덱스에 업로드
  cache    uv의 캐시 관리
  self     uv 실행 파일 관리
  version  uv 버전 표시
  help     명령어에 대한 문서 표시

주요 명령어

CLI Reference 페이지에서 모든 명령어의 옵션과 설명을 확인 할 수 있습니다.

  • python
  • run
  • venv
  • init
  • add / remove
  • sync / pip / export
  • tree

uv 주요 기능

파이썬 설치: uv python

uv python 명령어를 통해서 원하는 버전의 파이썬을 한번에 설치 가능합니다.

$ uv python install 3.12 3.13

가상환경에서 실행: uv run

uv run 명령어를 사용하여 설치되지 않은 파이썬 버전을 자동으로 설치하고, 필요한 패키지를 포함시켜 스크립트를 실행할 수 있습니다.

$ uv run --python 3.10 --with fastapi,pytest main.py
  • python 3.10이 설치되어 있지 않다면 자동으로 다운로드하고 설치
  • fastapi와 pytest 패키지를 설치
  • main.py 파일을 실행

가상 환경: uv venv

uv venv로 가상 환경을 생성하고 관리합니다. 특정 Python 버전을 사용하여 가상 환경을 생성할 수 있습니다. 설치되지 않은 파이썬 버전이면 자동으로 설치합니다.

$ uv venv --python 3.10 .venv

uv로 프로젝트 관리

프로젝트 초기화: uv init

uv init 명령어는 프로젝트 구조를 자동으로 설정하고 필요한 기본 파일들을 생성해 줍니다.

$ uv init my-app --app --python 3.10
└── my-app
   ├── .venv
   ├── README.md
   ├── main.py
   ├── pyproject.toml
   └── uv.lock
  • --app: 애플리케이션용 프로젝트 생성
  • --python <PYTHON>: 지원할 최소 파이썬 버전 지정

필요에 따라서 기존의 프로젝트에 pyproject.toml 파일만 추가해서 패키지를 설치하고 관리 할 수도 있습니다.

$ uv init --bare
  • --bare: pyproject.toml 파일만 생성
  • --script: 스크립트 생성
  • --package: 파이썬 패키지로 프로젝트 설정
  • --lib: 라이브러리용 프로젝트 생성

패키지 관리

uv add를 통해 원하는 패키지를 추가할 수 있습니다.

  • --extra <EXTRA>: 패키지의 선택적 의존성(extras)을 설치하는 데 사용
  • --dev: 개발 의존성으로 추가
  • --group <GROUP>: 특정 그룹으로 의존성 추가
$ uv add fastapi

$ uv add uvicorn --extra standard

$ uv add ruff --dev

$ uv add pytest --group test
pyproject.toml
[project]
name = "my-app"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
    "fastapi>=0.115.12",
    "uvicorn[standard]>=0.34.0",
]

[dependency-groups]
dev = [
    "ruff>=0.11.4",
]
test = [
    "pytest>=8.3.5",
]

의존성 패키지를 삭제할 때는 uv remove 명령어를 사용합니다. add와 유사한 옵션을 사용할 수 있습니다.

$ uv remove fastapi uvicorn
$ uv remove --dev
$ uv remove --group test

패키지 설치 및 동기화

pyproject.toml 파일이 있는 경우에는 uv sync를 사용 할 수 있습니다. 다양한 옵션으로 그룹을 지정하여 패키지를 설치 할 수 있습니다.

# 모든 의존성 설치 (기본값)
$ uv sync

# 개발 의존성을 제외하고 설치
$ uv sync --no-dev

# 개발 의존성만 설치
$ uv sync --only-dev

# 명시적으로 특정 의존성 포함하여 설치
$ uv sync --group test

또는 uv pip install를 통해 requirements.txt에서 패키지를 설치할 수 있습니다.

$ uv pip install -r requirements.txt

반대로 uv export 명령어를 통해 현재 설치된 패키지를 requirements.txt 파일로 만들수 있습니다.

$ uv export -o requirements.txt

의존성 시각화

uv tree로 프로젝트의 의존성 구조를 확인할 수 있습니다.

$ uv tree
my-app v0.1.0
└── fastapi v0.115.12
    ├── pydantic v2.11.3
    │   ├── annotated-types v0.7.0
    │   ├── pydantic-core v2.33.1
    │   │   └── typing-extensions v4.13.1
    │   ├── typing-extensions v4.13.1
    │   └── typing-inspection v0.4.0
    │       └── typing-extensions v4.13.1
    ├── starlette v0.46.1
    │   └── anyio v4.9.0
    │       ├── exceptiongroup v1.2.2
    │       ├── idna v3.10
    │       ├── sniffio v1.3.1
    │       └── typing-extensions v4.13.1
    └── typing-extensions v4.13.1

마무리

uv는 차세대 파이썬 패키지 및 프로젝트 관리 도구로 이미 자리를 잡고있습니다. 게다가 MCP 활용으로 인해 더욱 인지도가 높아지고 있습니다.

  • 속도: 기존 도구들보다 몇 배 더 빠른 패키지 설치 속도
  • 통합 관리: 파이썬 버전 관리부터 패키지 설치, 가상 환경 생성
  • 사용 편의성: pip와 호환되는 인터페이스로 쉽게 적응 가능
  • 프로젝트 관리: 프로젝트 초기화, 의존성 관리, 락파일 지원으로 일관된 환경 유지

파이썬을 사용하고 있다면 지금 바로 uv를 설치하고 사용해보세요! 감사합니다! 😊

참고 문헌

Introducing uv

uv logo

uv is a Python package and project management tool built in Rust by Astral. Its biggest advantage is that installing packages is incredibly fast.

Take a look at the graph comparing how long pip and other package managers take to install the Trio Python package, and you’ll see just how fast uv is.

uv speed

> Source : Installing Trio’s dependencies with a warm cache.

It also helps you manage dependencies more efficiently. It’s getting even more attention now that it’s officially recommended for MCP (Model Context Protocol) development.

Installing uv

Follow the Installing uv page to install it.

There are two main ways to install it: through an existing package manager, or as a standalone installation.

Standalone Installation

If you plan to use it for MCP, I recommend the standalone installation!
# On Windows.
> powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# On macOS and Linux.
$ curl -LsSf https://astral.sh/uv/install.sh | sh

Installing with an Existing Package Manager

# With pip.
$ pip install uv

# Or pipx.
$ pipx install uv

Verifying the Installation

Check the uv version with the command below to make sure it installed correctly.

$ uv --version
uv 0.6.3 (a0b9f22a2 2025-02-24)

Updating the Version

You can update uv with the command below only if you installed it as standalone.

$ uv self update

uv Command Structure

The basic usage looks like this. Let’s go over a few key commands.

Usage: uv [OPTIONS] <COMMAND>

Commands:
  run      Run a command or script
  init     Create a new project
  add      Add dependencies to the project
  remove   Remove dependencies from the project
  sync     Update the project's environment
  lock     Update the project's lockfile
  export   Export the project's lockfile to an alternate format
  tree     Display the project's dependency tree
  tool     Run and install commands provided by Python packages
  python   Manage Python versions and installations
  pip      Manage Python packages with a pip-compatible interface
  venv     Create a virtual environment
  build    Build Python packages into source distributions and wheels
  publish  Upload distributions to an index
  cache    Manage uv's cache
  self     Manage the uv executable
  version  Display uv's version
  help     Display documentation for a command

Key Commands

You can find the options and descriptions for every command on the CLI Reference page.

  • python
  • run
  • venv
  • init
  • add / remove
  • sync / pip / export
  • tree

Key Features of uv

Installing Python: uv python

With the uv python command, you can install whichever Python versions you want in one go.

$ uv python install 3.12 3.13

Running in a Virtual Environment: uv run

With the uv run command, you can run a script while automatically installing any Python version that isn’t installed yet and including the packages it needs.

$ uv run --python 3.10 --with fastapi,pytest main.py
  • Automatically downloads and installs Python 3.10 if it isn’t installed
  • Installs the fastapi and pytest packages
  • Runs the main.py file

Virtual Environments: uv venv

uv venv creates and manages virtual environments. You can create a virtual environment with a specific Python version. If that version isn’t installed, it’s installed automatically.

$ uv venv --python 3.10 .venv

Managing Projects with uv

Initializing a Project: uv init

The uv init command automatically sets up the project structure and generates the basic files you need.

$ uv init my-app --app --python 3.10
└── my-app
   ├── .venv
   ├── README.md
   ├── main.py
   ├── pyproject.toml
   └── uv.lock
  • --app: Create a project for an application
  • --python <PYTHON>: Set the minimum supported Python version

If needed, you can also add just a pyproject.toml file to an existing project to install and manage packages.

$ uv init --bare
  • --bare: Create only the pyproject.toml file
  • --script: Create a script
  • --package: Set up the project as a Python package
  • --lib: Create a project for a library

Managing Packages

You can add packages with uv add.

  • --extra <EXTRA>: Install the package’s optional dependencies (extras)
  • --dev: Add as a development dependency
  • --group <GROUP>: Add the dependency to a specific group
$ uv add fastapi

$ uv add uvicorn --extra standard

$ uv add ruff --dev

$ uv add pytest --group test
pyproject.toml
[project]
name = "my-app"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
    "fastapi>=0.115.12",
    "uvicorn[standard]>=0.34.0",
]

[dependency-groups]
dev = [
    "ruff>=0.11.4",
]
test = [
    "pytest>=8.3.5",
]

To remove dependencies, use the uv remove command. It takes options similar to add.

$ uv remove fastapi uvicorn
$ uv remove --dev
$ uv remove --group test

Installing and Syncing Packages

If you have a pyproject.toml file, you can use uv sync. Various options let you choose which groups of packages to install.

# Install all dependencies (default)
$ uv sync

# Install without development dependencies
$ uv sync --no-dev

# Install only development dependencies
$ uv sync --only-dev

# Install including a specific group explicitly
$ uv sync --group test

Or you can install packages from requirements.txt with uv pip install.

$ uv pip install -r requirements.txt

Conversely, the uv export command turns the currently installed packages into a requirements.txt file.

$ uv export -o requirements.txt

Visualizing Dependencies

You can check your project’s dependency structure with uv tree.

$ uv tree
my-app v0.1.0
└── fastapi v0.115.12
    ├── pydantic v2.11.3
    │   ├── annotated-types v0.7.0
    │   ├── pydantic-core v2.33.1
    │   │   └── typing-extensions v4.13.1
    │   ├── typing-extensions v4.13.1
    │   └── typing-inspection v0.4.0
    │       └── typing-extensions v4.13.1
    ├── starlette v0.46.1
    │   └── anyio v4.9.0
    │       ├── exceptiongroup v1.2.2
    │       ├── idna v3.10
    │       ├── sniffio v1.3.1
    │       └── typing-extensions v4.13.1
    └── typing-extensions v4.13.1

Wrapping Up

uv has already established itself as the next-generation Python package and project management tool. On top of that, it’s gaining even more recognition thanks to its use with MCP.

  • Speed: Installs packages several times faster than existing tools
  • All-in-one management: From Python version management to package installation and virtual environment creation
  • Ease of use: A pip-compatible interface makes it easy to pick up
  • Project management: Keeps environments consistent with project initialization, dependency management, and lockfile support

If you use Python, install uv and give it a try right now! Thank you! 😊

References

python uv

tiaz0128

Eat Sleep Coding.

Never Never GiveUp.

Security  |  BackEnd  |  Multi Cloud