This repository contains multiple independent script collections, each in its own directory. Each directory is designed to be used independently with its own virtual environment.
Each script directory (e.g., FmiAPI/, AQBurk2IoTHub/, etc.) manages its own dependencies using:
pyproject.toml- Modern Python project configuration with metadata and dependency specificationsrequirements.txt- Lock file with pinned versions (auto-generated, never edit manually)
- Isolation: Scripts run in different environments (dev, production, different servers)
- Minimal Dependencies: Each environment only installs what it needs
- Reproducibility: Lock files ensure consistent installations across environments
- Independence: Each directory can be deployed separately
uv is a fast, modern Python package manager written in Rust.
- Create
pyproject.tomlin your directory:
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "your-script-name"
version = "0.1.0"
description = "Description of your script"
requires-python = ">=3.13"
dependencies = [
"httpx",
"pandas",
# Add your dependencies here
]
[project.optional-dependencies]
dev = [
"pytest",
"ruff",
]- Generate lock file:
cd YourDirectory/
uv pip compile pyproject.toml -o requirements.txt- Create virtual environment and install:
uv venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
uv pip sync requirements.txt- If using
fvhdmsshared module:
uv pip install -e ../fvhdmscd YourDirectory/
pip install pip-tools
pip-compile pyproject.toml -o requirements.txt
pip-sync requirements.txtIf you only have requirements.txt without version pinning:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt- Edit
pyproject.tomland add the package todependencies:
dependencies = [
"existing-package",
"new-package", # Add here
]- Regenerate lock file:
uv pip compile pyproject.toml -o requirements.txt- Update your environment:
uv pip sync requirements.txtTo upgrade all dependencies to their latest compatible versions:
uv pip compile --upgrade pyproject.toml -o requirements.txt
uv pip sync requirements.txtMany scripts use the shared fvhdms module located in the repository root. Install it in editable mode:
pip install -e ../fvhdms
# or with uv:
uv pip install -e ../fvhdmsSome scripts require environment variables or .env files:
# Copy example config
cp config.ini.example config.ini
# Edit with your settings
nano config.iniIn production environments, clone the repo and set up only the needed directory:
git clone <repo-url>
cd DataManagementScripts/FmiAPI/
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e ../fvhdms # if needed
python fmiapi.py --help- Install:
pip install uvorcurl -LsSf https://astral.sh/uv/install.sh | sh - Docs: https://github.com/astral-sh/uv
Configured in root pyproject.toml:
# Lint all files
ruff check .
# Format code
ruff format .
# Auto-fix issues
ruff check --fix .See .pre-commit-config.yaml for automated checks before commits.
To migrate a directory from simple requirements.txt to pyproject.toml:
- Analyze current dependencies:
cd YourDirectory/
pip list --format=freeze > current-deps.txt-
Create
pyproject.tomlwith direct dependencies only (not transitive) -
Generate new lock file:
uv pip compile pyproject.toml -o requirements.txt- Test in fresh environment:
uv venv test-env
source test-env/bin/activate
uv pip sync requirements.txt
python your_script.py --help- Clean up:
deactivate
rm -rf test-env current-deps.txtSee FmiAPI/ as a reference implementation:
- ✅ Modern
pyproject.tomlwith metadata - ✅ Auto-generated
requirements.txtlock file - ✅ Updated
README.mdwith installation instructions - ✅ Optional dev dependencies for testing
- Check existing directories like
FmiAPI/for examples - Review this guide for best practices
- Tools documentation: uv, pip-tools, setuptools