uv.lock is a cross-platform lockfile that contains exact information about your project's dependencies. Unlike the pyproject.toml which is used to specify the broad requirements of your project, the lockfile contains the exact resolved versions that are installed in the project environment. This file should be checked into version control, allowing for consistent and reproducible installations across machines.
The .python-version file contains the project's default Python version. This file tells uv which Python version to use when creating the project's virtual environment.
Managing Dependencies
There are many ways to install package, after adding package, pyproject.toml and uv.lock will be updated
uv is compatible to pip
Tool
Tools are Python packages that provide command-line interfaces.
[project]
name = "hello-world"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
dependencies = []
uv add <package>
# install exact version
uv add <package==0.20>
# install based on pip files
uv add -r requirements.txt
# install from pip
uv pip install <package>
uv pip list
# ensure all the package are installed based on uv.lock file
uv sync
uv tool install ruff==0.5.0
ruff --version
// similar with npx
uvx ruff --version
# Use a Python image with uv pre-installed
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
# Install the project into `/app`
WORKDIR /app
# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy
# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev
# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
COPY . /app
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev
ENV PATH="/app/.venv/bin:$PATH"
EXPOSE 80
ENV PORT 80
ENV LLM_MODEL openrouter/openai/gpt-4o-mini
ENV OPENROUTER_API_KEY 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
ENV GOOGLE_API_KEY AIzaSyBUguvUNCxqha21BhH6r3bOcF48ckoxTz8
ENV CHROMA_HOST 34.44.52.123
ENV CHROMA_PORT 8000
# ENTRYPOINT ["tail", "-f", "/dev/null"]
CMD ["fastapi", "run", "main.py", "--port", "80"]