Est. time to complete: 20 minutes
This tutorial guides you through the process of setting up a new Python project using this template. By the end, you'll have a fully configured development environment with best-practice tools for code quality, testing, and documentation.
- Python 3.11+ installed on your system
- Git installed on your system
- Basic command-line knowledge
- Either Visual Studio Code or Cursor (recommended) installed
Let's start by installing UV, a blazing-fast Python package manager written in Rust. It's much faster than pip and provides better dependency resolution.
curl -LsSf https://astral.sh/uv/install.sh | shpowershell -c "irm https://astral.sh/uv/install.ps1 | iex"After installation, verify that UV is properly installed:
uv --versionYou should see the UV version number displayed, indicating that UV is ready to use.
Before getting the project code, let's set up a virtual environment to keep our dependencies isolated:
# Create a directory for your project
mkdir my-python-project
cd my-python-project
# Create a virtual environment
uv venv
# Activate the virtual environment
# On macOS/Linux:
source .venv/bin/activate
# On Windows:
.venv\Scripts\activateYou should now see the virtual environment name in your terminal prompt, showing that it's active.
Now that we have our environment ready, let's get the project template:
- Go to the Python Starting Project GitHub: https://github.com/dhkts1/Python-Starting-Project
- Click the green "Use this template" button
- Choose "Create a new repository"
- Fill in your repository details and click "Create repository"
- Clone your new repository into your project directory:
git clone https://github.com/your-username/your-repo-name.git .
The dot at the end of the clone command ensures that the repository is cloned into your current directory.
With our repository set up and virtual environment active, we can now install all the project dependencies:
# Install all dependencies (including development tools)
uv syncThis command installs:
- All production dependencies
- Development tools (linters, formatters, testing tools)
- Documentation tools
You'll see a progress bar and eventually a success message when all packages are installed.
Next, let's set up pre-commit hooks which will automatically check your code quality before each commit:
# Install pre-commit hooks
pre-commit installThese hooks are configured in the .pre-commit-config.yaml file and help maintain code quality by running checks before each commit.
Let's make sure everything is working correctly by running the pre-commit checks manually:
# Run all pre-commit hooks
poe preYou should see a series of checks running, all of which should pass. This confirms that your setup is working correctly and all tools are properly configured.
Now that our project is set up, let's open it in an IDE for easier editing:
code .cursor .When you first open the project, your IDE should recommend installing some extensions. Install these for the best development experience, as they enhance code editing with features like syntax highlighting, code completion, and linting.
The template includes a sample application you can run to verify everything works correctly:
# Run the main script
python -m src.mainYou can also use the Run and Debug button in VSCode/Cursor to run the application. There's a pre-configured launch.json file in the .vscode folder that makes this process seamless.
You should see some log output, confirming that the application is working correctly.
Now that everything is running smoothly, let's make our first change to the project:
- Open
src/main.py - Modify the log message in the main function
- Save the file
- Run the application again to see your changes:
python -m src.main
You should see your modified log message in the output, confirming that your changes were applied successfully.
Finally, let's save our changes to the repository:
# Stage your changes
git add src/main.py
# You can also use "git add ." to stage all changes
# Or use "git status" to see what files were changedIf there are errors in the output or files were automatically formatted, you'll need to run git add again to stage the updated files.
Then, commit your changes:
# Commit your changes
git commit -m "Update log message in main function"Notice how the pre-commit hooks run automatically before the commit is created. These checks ensure your code meets the project's quality standards.
Problem: Missing dependencies when running commands
Solution: Run uv sync again to ensure all dependencies are installed
Problem: Pre-commit hooks failing
Solution: Read the error messages carefully. Most issues can be fixed by running poe lint to lint format and fix errors.
Problem: IDE not showing proper code intelligence
Solution: Make sure you've installed the recommended extensions and configured your IDE to use the project's virtual environment.
Congratulations on setting up your Python project! Here are some next steps you might want to take:
- Learn about the code quality tools to maintain high code standards
- Explore the project structure to understand how everything fits together
- Check out the development workflow for daily development practices
- Add your own code to the project and start building something amazing
-
What command installs all dependencies for the project?
uv sync
-
What command sets up pre-commit hooks?
pre-commit install
-
What command runs all pre-commit checks manually?
poe pre
-
What happens when you run
git commitafter setting up pre-commit hooks?- Pre-commit hooks run automatically to check code quality before creating the commit