Panduan Backend Engineer: Ekosistem Tooling Python Modern dengan uv, Ruff, Mypy & Pytest

Repositori Python lama yang masih mengandalkan pip install -r requirements.txt, flake8, dan black sering kali mengalami waktu build CI hingga belasan menit serta ketidaksesuaian versi dependensi antara lingkungan lokal dan kontainer produksi. Dengan bermigrasi ke pyproject.toml terpadu menggunakan uv, ruff, mypy --strict, dan pytest, tim backend dapat memangkas waktu build hingga 85% sekaligus mendeteksi bug tipe sebelum kode masuk ke produksi. Sebagai Senior Backend Engineer, berikut adalah standar konfigurasi yang saya terapkan.

1. Multi-Stage Docker Build Deterministik dengan uv sync --frozen

Menggunakan lockfile lintas platform uv.lock dan kompilasi bytecode (UV_COMPILE_BYTECODE=1) menghasilkan image Docker yang ringan dan waktu cold-start yang jauh lebih cepat di Cloud Run maupun AWS ECS.

2. Standar Kualitas Kode dengan ruff & mypy

Pemeriksaan lint dan pemformatan kode menggunakan ruff berjalan dalam hitungan milidetik untuk ratusan ribu baris kode Python.

3. Bermitra dengan Senior Python Backend Engineer

Jelajahi Panduan Utama Backend Engineer, baca Panduan Arsitektur CI/CD Monorepo, atau pesan Sprint Modernisasi Python 1 Hari.

Implementasi Kode Produksi & Konfigurasi Teknis

Berikut adalah implementasi kode produksi lengkap dan konfigurasi teknis untuk arsitektur Panduan Backend Engineer: Ekosistem Tooling Python Modern dengan uv, Ruff, Mypy & Pytest:

# syntax=docker/dockerfile:1.7
FROM ghcr.io/astral-sh/uv:0.5-python3.12-bookworm-slim AS builder
WORKDIR /app

ENV UV_COMPILE_BYTECODE=1     UV_LINK_MODE=copy

# Install third-party dependencies first (cached unless pyproject.toml or uv.lock changes)
COPY pyproject.toml uv.lock ./
RUN --mount=type=cache,target=/root/.cache/uv     uv sync --frozen --no-install-project --no-dev

# Copy application source and sync project
COPY . /app
RUN --mount=type=cache,target=/root/.cache/uv     uv sync --frozen --no-dev

FROM python:3.12-slim-bookworm AS runtime
WORKDIR /app
COPY --from=builder /app/.venv /app/.venv
COPY --from=builder /app /app
ENV PATH="/app/.venv/bin:$PATH"
CMD ["gunicorn", "afcom.wsgi:application", "--bind", "0.0.0.0:8080"]

Checklist Arsitektur Produksi (Cloud Engineer)

Dalam menerapkan solusi Panduan Backend Engineer: Ekosistem Tooling Python Modern dengan uv, Ruff, Mypy & Pytest (Backend Engineer, Python, DevOps, Developer Tools, Docker, CI/CD) pada lingkungan produksi berskala enterprise sebagai Cloud Engineer, pastikan standar rekayasa berikut terpenuhi:


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 15+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs