惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
月光博客
月光博客
人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
Vercel News
Vercel News
MyScale Blog
MyScale Blog
爱范儿
爱范儿
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
H
Help Net Security
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
宝玉的分享
宝玉的分享
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
博客园 - 叶小钗
D
Docker

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
pyproject.toml: Modern Python Dependency Management
Tlaloc-Es · 2026-04-24 · via DEV Community

pyproject.toml is the contract behind modern Python dependency management.
Without it, installers have to execute setup.py or guess build requirements, which leads to fragile builds and non-reproducible environments.

This article breaks down the key PEPs (518/517/621) and how pyproject.toml connects to python -m venv + python -m pip for predictable installs.

The old problem: executable setup.py

Back then, project configuration was executable Python code. Flexible, yes, but it also enabled side effects and fragile builds.

Tooling could not reliably parse metadata statically.

The fix in three key PEPs

PEP 518: declare the build system

It defines [build-system] in pyproject.toml so installers know what they need before building.

[build-system]
requires = ["setuptools>=68", "wheel"]
build-backend = "setuptools.build_meta"

Enter fullscreen mode Exit fullscreen mode

PEP 517: standardized build backend interface

It lets pip work with multiple backends (setuptools, hatchling, flit, poetry-core) through a common API.

PEP 621: project metadata in [project]

It standardizes name, version, dependencies, authors, and more without dynamic code.

Modern pyproject.toml example

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "my-service"
version = "0.1.0"
description = "Internal API example"
requires-python = ">=3.11"
dependencies = [
  "fastapi>=0.110",
  "uvicorn[standard]>=0.29",
  "pydantic>=2.7"
]

[project.optional-dependencies]
dev = [
  "pytest>=8",
  "ruff>=0.5",
  "mypy>=1.10"
]

Enter fullscreen mode Exit fullscreen mode

This improves three critical areas:

  • project clarity
  • reproducible installation
  • sustainable dependency management

How to use it with python venv

python -m venv .venv
source .venv/bin/activate
python -m pip install -e .
python -m pip install -e ".[dev]"

Enter fullscreen mode Exit fullscreen mode

In editable mode, source code changes are reflected without reinstalling every time.

Common mistakes

  • Leaving out [build-system] (or listing the wrong backend), causing builds to fail or behave differently across machines.
  • Duplicating dependency declarations across requirements.txt and pyproject.toml with no “source of truth,” leading to drift.
  • Not setting requires-python, so installs succeed on incompatible interpreters and fail later at runtime.
  • Treating version ranges as “good enough” without a lock file, then getting different dependency graphs in CI vs local.

venv vs virtualenv vs poetry (practical view)

Quick team-level view:

  • venv: simple and standard, great to start
  • virtualenv: more options and speed in some scenarios
  • poetry: integrated workflow for dependencies and publishing

All of them can coexist with pyproject.toml, which is now the common language of Python packaging.

Insight that often saves hours

If an environment starts failing “out of nowhere” after many package experiments, your code may not be the problem; environment state often is.

In many cases, recreating .venv from pyproject.toml is faster than patching inconsistent installs one by one.

Environment hygiene pro tip

Dependency experiments tend to leave behind throwaway environments that later confuse installs and imports. If that keeps happening, KillPy can scan and list stale environments by age/size so you can remove them after confirming they are unused.

Conclusion

pyproject.toml is not a trend. It is the modern foundation of Python environments and dependency management.

If your goal is real reproducibility, less team friction, and predictable builds, this file should be at the center of your workflow.


Has your project fully migrated to pyproject.toml, or are you still transitioning from setup.py? Share your case in the comments; it can help other teams.