https://github.com/jtgsystems/python-best-practices-2025
๐ Python best practices guide 2025 - Modern coding standards, patterns & optimization techniques
https://github.com/jtgsystems/python-best-practices-2025
ai automation fastapi llm nlp python rag tools web
Last synced: about 1 month ago
JSON representation
๐ Python best practices guide 2025 - Modern coding standards, patterns & optimization techniques
- Host: GitHub
- URL: https://github.com/jtgsystems/python-best-practices-2025
- Owner: jtgsystems
- Created: 2025-05-28T03:08:49.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-04-13T17:36:51.000Z (2 months ago)
- Last Synced: 2026-04-13T18:24:48.877Z (2 months ago)
- Topics: ai, automation, fastapi, llm, nlp, python, rag, tools, web
- Language: PowerShell
- Homepage:
- Size: 873 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Agents: AGENTS.md
Awesome Lists containing this project
README

# ๐ Python Best Practices 2025
Comprehensive guide to writing reliable, maintainable, and high-performance Python code.
---
## ๐ Supported Python Versions
- โก๏ธ **Python 3.14.0** (Oct 7, 2025) โ Latest stable with official free-threaded builds, template strings, deferred annotations, and bundled `compression.zstd` module
- ๐ก๏ธ **Python 3.13.9** (latest bugfix on Oct 14, 2025) โ Conservative choice with extended support through Oct 2029
- ๐ฆ **Security-only**: 3.12 LTS receives fixes until Oct 2028; upgrade plans should target 3.13+
---
## ๐ New & Experimental Features
- ๐ **Free-Threaded CPython** (PEP 779) โ official tier-2 builds enable real multi-core scaling
- ๐ค **Template String Literals** (PEP 750) โ safer templating for SQL, shell, and i18n use cases
- ๐ **Deferred Annotations** (PEP 649) โ annotation evaluation happens on demand for faster imports
- ๐งต **Multiple Interpreters API** (PEP 734) โ `concurrent.interpreters` brings low-overhead parallelism
- ๐ฆ **`compression.zstd` Module** (PEP 784) โ native Zstandard support across stdlib tools
- ๐ฅ **JIT & REPL Enhancements** โ experimental JIT binaries ship for macOS/Windows; REPL ships with colorized output and smarter hints
---
## ๐ Repository Structure
```
01-CORE-PRINCIPLES/ # PEP guidelines, naming conventions, SOLID & design patterns
02-LINTING-FORMATTING/ # Ruff, Black & MyPy configs + style guide
03-TESTING-FRAMEWORKS/ # pytest, unittest, coverage examples
04-PROJECT-STRUCTURE/ # src layout, module vs. package best practices
05-PERFORMANCE-SECURITY/ # Profiling tips, optimizations & security checks
06-CI-CD-TEMPLATES/ # GitHub Actions, pre-commit hooks & YAML samples
07-EXAMPLES/ # Data pipelines, FastAPI demos, real-world code
output/ # Generated docs, reports, artifacts
```
---
## ๐ ๏ธ Essential Tools & Setup
### Toolchain
- ๐ **Linter & Formatter**: [Ruff 0.14.3](https://github.com/astral-sh/ruff) โ bundles linting, formatting, and rule sets
- ๐จ **Formatter**: Ruff format (or [Black 25.9.0](https://github.com/psf/black) for parity with legacy pipelines)
- ๐ข **Type Checking**: [MyPy 1.18.2](http://mypy-lang.org/) or [Pyright](https://github.com/microsoft/pyright) depending on ecosystem
- ๐งช **Testing**: [pytest](https://docs.pytest.org/) + [pytest-cov](https://github.com/pytest-dev/pytest-cov) for coverage
- ๐ฆ **Package Manager**: [uv 0.9.7](https://github.com/astral-sh/uv) for fast, secure dependency workflows; [Poetry](https://python-poetry.org/) remains a solid alternative
### Installation
```powershell
# Install core development tools with pip
pip install "ruff>=0.14.3" "black>=25.9.0" "mypy>=1.18.2" pytest pytest-cov
# Or using uv (recommended for speed and lockfiles)
uv tool upgrade "uv>=0.9.7"
uv add --dev ruff>=0.14.3 black>=25.9.0 mypy>=1.18.2 pytest pytest-cov
# Optional security & automation
pip install pre-commit bandit safety
```
### Pre-Commit Hooks
Create a `.pre-commit-config.yaml`:
```yaml
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.3
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format
- repo: https://github.com/psf/black
rev: 25.9.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.18.2
hooks:
- id: mypy
```
Enable by running:
```bash
pre-commit install
```
---
## ๐ Learning Path
1. **01-CORE-PRINCIPLES** โ PEP standards, naming, SOLID & design patterns
2. **02-LINTING-FORMATTING** โ Configure and enforce lint & format rules
3. **03-TESTING-FRAMEWORKS** โ Write robust tests & measure coverage
4. **04-PROJECT-STRUCTURE** โ Organize code for maintainability
5. **05-PERFORMANCE-SECURITY** โ Profile, optimize, and secure applications
6. **06-CI-CD-TEMPLATES** โ Automate linting, testing & deployment pipelines
7. **07-EXAMPLES** โ Explore real-world scripts and template projects
---
## ๐งฉ Examples & Templates
- **data-science-pipeline.py** โ ETL workflow with logging, error handling & tests
- **fastapi-app.py** โ Minimal FastAPI service with Pydantic models & security checks
---
## ๐ฏ Quick Commands Reference
```bash
# Linting & Formatting
ruff check . # Fast linting
ruff format . # Fast formatting
black . # Alternative formatting
mypy . # Type checking
# Testing
pytest # Run all tests
pytest --cov=src # With coverage
pytest -x -vs # Stop on first failure, verbose
# Security
bandit -r src/ # Security scan
safety check # Dependency vulnerabilities
# Project setup
ruff init # Initialize ruff config
pre-commit install # Setup git hooks
```
---
## โญ Contributing
Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) and follow our code style guidelines.
---
## ๐ License
This project is licensed under MIT. See [LICENSE](LICENSE) for details.