Skip to content

TEMPLATE PyProject

Felix Staacke edited this page Feb 25, 2026 · 3 revisions

TEMPLATE PyProject

Minimal pyproject.toml für neue Python-Projekte
Vollständige Erklärung: Pythonprojekt Standards

Inhalt

  1. Ordnerstruktur (src-layout)
  2. Minimal pyproject.toml
  3. Setup & Verwendung
  4. Migration von requirements.txt
  5. Häufige Anpassungen
  6. Troubleshooting

Ordnerstruktur (src-layout)

project-name/
├── src/
│   └── your_package/
│       ├── __init__.py
│       ├── main.py
│       └── ...
├── tests/
├── pyproject.toml          # ← Dieses Template
├── README.md
└── .gitignore

Minimal pyproject.toml

# === Build System ===========================
[build-system]
requires = ["setuptools>=68"]
build-backend = "setuptools.build_meta"

# === Project Metadata ====================
[project]
name = "your-project"
version = "0.1.0"
description = "Kurze Projektbeschreibung"
readme = "README.md"
requires-python = ">=3.10"
license = { text = "MIT" }
authors = [
    { name = "Vorname Nachname", email = "email@example.org" }
]

# === Dependencies ========================
dependencies = [
    # Core packages
    "requests>=2.31",
    "pandas>=2.0",
    
    # Git Submodules (Development)
    # "gta @ git+https://github.com/HisQu/GTA.git@main",
    
    # Git Submodules (Production - mit commit hash)
    # "gta @ git+https://github.com/HisQu/GTA.git@abc123def",
]

# === Optional Dependencies ===============
# Requires pip ≥ 25.1, update with `python -m pip install --upgrade pip`
[dependency-groups]
dev = [
    "pytest>=8",
    "black>=24",
    "ruff>=0.5",
    "mypy>=1.10",
]

# === Package Discovery ===================
[tool.setuptools.packages.find]
where = ["src"]
include = ["*"]

Setup & Verwendung

# 1. Virtual environment erstellen
python -m venv .venv
source .venv/bin/activate  # Linux/macOS
# .venv\Scripts\activate   # Windows

# 2. Editable install (Entwicklung)
pip install -e ".[dev]"

# 3. Projekt ausführen
python -m your_package.main

Migration von requirements.txt

# Alt:
pip install -r requirements.txt
pip install -r dev-requirements.txt

# Neu:
pip install -e ".[dev]"

Migrationsschritte:

  1. Pakete aus requirements.txt[project.dependencies]
  2. Dev-Pakete → [dependency-groups.dev]
  3. Code nach src/your_package/ verschieben
  4. __init__.py erstellen

Häufige Anpassungen

# Nur für Webapps:
[project]
dependencies = [
    "fastapi>=0.115",
    "uvicorn[standard]>=0.30",
]

# CLI Tools:
[project.scripts]
mytool = "your_package.cli:main"

# Zusätzliche Dateien einschließen:
[tool.setuptools.package-data]
"your_package" = ["data/*.json", "templates/*.html"]

Troubleshooting

Problem Lösung
ModuleNotFoundError __init__.py in src/your_package/ erstellen
Paket nicht gefunden where = ["src"] in [tool.setuptools.packages.find] prüfen
Import funktioniert nicht from your_package import ... statt from . import ...
Git Submodule SSH-Fehler SSH-Key für GitHub konfigurieren oder HTTPS verwenden

Clone this wiki locally