https://github.com/programmer-yar/fastapi
Fastapi with uv
https://github.com/programmer-yar/fastapi
Last synced: 8 months ago
JSON representation
Fastapi with uv
- Host: GitHub
- URL: https://github.com/programmer-yar/fastapi
- Owner: Programmer-yar
- Created: 2025-10-23T06:50:36.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-10-23T06:51:34.000Z (8 months ago)
- Last Synced: 2025-10-23T09:21:04.203Z (8 months ago)
- Language: Python
- Size: 40 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FastAPI with UV
## Project Setup with UV
- setup simple python project structure within existing directory: `uv init`
- create project structure alongwith directory: `uv init my_app --app`
- create python package designed and distributed (rarely used): `uv init my_app --lib`
- automatically creates:
- git repository
- .gitignore (typical python files to ignore)
- .python-version
- main.py
- pyproject.toml (modern way to configure python projects)
- install packages with `uv add`:
- automatically creates and activates virtual environment if not already created & activated and install dependencies
- `uv add fastapi requests`
- updates lock file automatically
- `uv remove [package_name]` removes the package + dependency and also removes it from .lock file
- `uv.lock` strictly records package versions
- also records dependencies with sub dependencies `uv tree`
- Run `main.py` in uv with `uv run main.py`:
- it automatically activates VE and runs the code, no need to keep v env on all time
- `uv sync` install dependencies on any machine
- smart global caching system
- compatible with pip commands:
- uv pip install flask
- uv pip list
## Migrate old project to UV:
- first do `uv init`
- `uv add -r requirements.txt`
- install packages used globally like `ruff` linter with `uv tool install ruff`
- it will be installed as a tool and available everywhere
- even do ruff check without installing the ruff tool:
- `uv tool run ruff check` it will install ruff, run the check and then remove it
- `uvx ruff check` shortcut
- get tools list:
- `uv tool list`
- `uv tool upgrade --all`
- can manage multiple python versions
## Local setup
- start the fastapi server using `uv run uvicorn main:app --reload`