Skip to content
/ python-template Public template

A template with uv for Python projects. Forget dependencies and packaging. Focus on your project.

License

Notifications You must be signed in to change notification settings

kitswas/python-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-template

A template for Python projects.
Includes basic project structure, a test suite, a code formatter and linter, and a dependency manager.

How to use

You need the uv package/project manager to install the dependencies.
You can get uv here.

Note

To change the Python version, change the requires-python field in pyproject.toml and the number in .python-version.
uv will take care of the rest.

Remember to replace the placeholders in the pyproject.toml file and change/remove the LICENSE file.

Set up the environment. (Only once)

uv venv
# .venv/Scripts/activate # Windows
source .venv/bin/activate # Linux/MacOS
uv sync --link-mode=symlink # Install the dependencies, use -U to update

If you want Pytorch (with or without CUDA), you can install it using the --extra flag.

uv sync --link-mode=symlink --extra=torch-cpu   # for CPU only
uv sync --link-mode=symlink --extra=torch-cu124 # for CUDA support

You can add other dependencies use uv add. The following example adds a valid kernel for Jupyter notebooks in VSCode.

uv add ipykernel # Similar to pip install ipykernel

To run any script, append uv run before the python command. (If the environment is inactive)

uv run python src/hello.py

Run tests:

uv run python -m unittest discover

Get rid of temporary files: (Use with caution)

git clean -fdX -n # Remove the -n flag to actually delete the files

Code Formatting and Linting

We have ruff for code formatting and linting. Install the VSCode extension and enable Format on Save for a better experience.

To fix imports:

uv run ruff check --select I --fix # Sort imports
uv run ruff check --select F401 --fix # Remove unused imports

To check for linting errors:

uv run ruff check # Use --fix to fix the errors

To format the code:

uv run ruff format

About

A template with uv for Python projects. Forget dependencies and packaging. Focus on your project.

Topics

Resources

License

Stars

Watchers

Forks

Languages