Fundamentals 7 min read

Master Python Project Setup: From Git Init to uv Automation

This guide walks you through building a Python project from scratch, covering Git initialization, virtual environment creation, version management with pyenv, dependency handling with Poetry and the all‑in‑one tool uv, plus commands for installing, adding packages, running tests, and formatting code.

Code Mala Tang
Code Mala Tang
Code Mala Tang
Master Python Project Setup: From Git Init to uv Automation

How to start a Python project from zero? Follow this typical workflow:

Initialize a local Git repository with git init.

Create a remote GitHub repository and link it.

Commit the initial code using git add and git commit.

Git and GitHub Repository

Set up the repository and push your code to GitHub.

Virtual Environment

Activate a virtual environment:

Windows: .\venv\Scripts\activate Linux/macOS: source .venv/bin/activate Create the environment with python -m venv venv and then activate it.

Using Pyenv

Manage Python versions with Pyenv and set the project version:

pyenv local 3.12.0

Using Poetry

Initialize and manage the project with Poetry:

poetry init
poetry install

Create a virtual environment and set Python version using poetry shell and

poetry env use 3.12.0

Configuration Files

Create a .gitignore to exclude unwanted files.

Create a .env to store environment variables (do not commit).

Why Try uv?

uv combines the functionality of pip, Poetry, pyenv, and virtualenv, and is 10‑100× faster than pip, dramatically reducing dependency‑management time.

Installation

Install uv using one of the following methods:

Linux/macOS: curl -LsSf https://astral.sh/uv/install.sh | sh Windows (PowerShell): irm https://astral.sh/uv/install.ps1 | iex Key project files include .python-version, hello.py, pyproject.toml, and README.md.

Using uv

Install uv via pip if preferred: pip install uv Initialize a new project: uv init This creates four files: .gitignore, .env, pyproject.toml, and README.md.

Virtual Environment

Create and activate a virtual environment:

uv venv
. venv/Scripts/activate

Adding Dependencies

Add packages easily:

uv add typer
uv add pytest --dev

(development dependency) uv add fastapi jupyter pandas (multiple packages)

Remove a package:

uv remove fastapi

Running

Run tests with: uv run pytest Execute a script such as hello.py:

uv run .\hello.py

Managing Python Versions

Check the current Python version: uv run python --version Install specific Python versions:

uv python install 3.12.3
uv python install 3.9 3.10 3.11

Recreate a virtual environment with a chosen Python version: uv venv --python 3.12.3 Or sync the environment:

uv sync

Using Ruff for Code Formatting

Check code style: uv run ruff check Format code automatically: uv run ruff format Ruff is a fast Python linter and formatter that helps keep the codebase clean and consistent.

Conclusion

These are the basic commands and features of uv. For more details, refer to the official documentation.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonPoetryproject setup
Code Mala Tang
Written by

Code Mala Tang

Read source code together, write articles together, and enjoy spicy hot pot together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.