Understanding uv init Project Types

Understanding uv init Project Types

The uv init command creates different types of Python projects through various flags, each optimized for specific use cases. Here’s how they compare:

FlagBuild SystemStructureEntry PointDistributionUse Case
--app (default)Flatmain.pyNot intendedWeb apps, scripts
--libsrc/ layoutPyPI packagesReusable libraries
--packagesrc/ layoutConsole scriptInstallable appsCLI tools
--bareMinimalManual setupCustom projects
--no-packageFlatmain.pyExplicitly blockedInternal apps

The Four Main Project Types

Applications (--app)

Applications are standalone programs like web servers, CLI tools, or scripts. This is the default when you run uv init.

Application projects use a flat structure with main.py and no build system configuration since they aren’t distributed as packages. The pyproject.toml focuses on runtime dependencies without packaging metadata.

Libraries (--lib)

Libraries are designed for distribution and reuse. They use the src/package_name/ layout for better testing isolation and include a py.typed file for type checking support.

The pyproject.toml includes complete build system configuration with hatchling as the default backend, enabling wheel and source distribution creation for PyPI.

Packageable Applications (--package)

Some applications benefit from being installable as packages, like CLI tools distributed through PyPI.

The --package flag combines application and library features - using the src/ layout but adding [project.scripts] entry points that create executable commands when installed.

Minimal Projects (--bare)

The --bare flag creates only a pyproject.toml file with essential metadata. This suits existing projects or situations requiring complete structural control.

No sample code, README, or directory structure gets generated.

How Project Types Differ

The key differences between project types lie in three areas:

Build System: Libraries and packageable applications include [build-system] configuration for creating distributions. Applications and bare projects omit this unless you need packaging capabilities.

Project Structure: Libraries and packageable applications use the src/ layout for better testing isolation. Applications use flat structures for simplicity.

Entry Points: Packageable applications define console scripts that become executable commands when installed. Other project types handle execution differently.

Last updated on

Please submit corrections and feedback...