python-packaging-and-tooling
Skill1 starsChanged 2 months agoMITView on GitHub
Set up and ship a modern Python project - pyproject.toml, src-layout, dependency groups and lockfiles (uv by default, poetry/pdm when forced), editable installs, ruff and mypy, entry points, and building/writing to a package index. Use when a user says "set up a new Python project", "requirements.txt vs pyproject", "uv/poetry/pdm", "ModuleNotFoundError: No module named", "import fails after pip install -e", "publish to PyPI", "expose a CLI". Triggers on "pyproject.toml", "setup.py", "lockfile", "editable install", "src layout", "entry point", "console_script".
- Installs packages
In this repository126 other files it gives its agents.
- eu-data-backend-job-hunterSkill
- job-application-matcherSkill
- llm-agents-and-tool-useSkill
- llm-application-architectureSkill
- llm-cost-and-latency-optimizationSkill
- llm-evaluationSkill
- llm-fine-tuning-and-adaptersSkill
- llm-privacy-and-safetySkill
- llm-prompt-engineeringSkill
- llm-rag-systemsSkill
- structured-output-and-jsonSkill
- graphql-api-designSkill
- pagination-and-filteringSkill
- rest-api-designSkill
- webhooks-and-integrationsSkill
- caching-architecture-multi-layerSkill
- resilience-patternsSkill
- service-boundaries-and-monolithsSkill
- system-design-interviewSkill
- go-concurrencySkill
- go-error-handlingSkill
- java-spring-patternsSkill
- nodejs-server-performanceSkill
- python-async-patternsSkill
- python-data-modelingSkill
- python-performanceSkill
- rest-api-implementationSkill
- rust-error-handlingSkill
- rust-ownership-patternsSkill
- typescript-type-safetySkill
- ci-caching-and-speedupSkill
- ci-pipeline-designSkill
- deployment-strategiesSkill
- github-actions-hardeningSkill
- release-versioning-and-changelogsSkill
- reproducible-buildsSkill
- aws-iam-and-securitySkill
- aws-serverless-architectureSkill
- azure-fundamentalsSkill
- cloud-cost-optimizationSkill
- cloud-networking-and-vpcSkill
- gcp-cloud-architectureSkill
- code-review-skillsSkill
- design-review-and-refactoring-architectureSkill
- refactoring-techniqueSkill
- understanding-unknown-codebaseSkill
- buildkit-and-cacheSkill
- container-image-debuggingSkill
- container-runtime-securitySkill
- docker-compose-workflowsSkill
- dockerfile-authoringSkill
- docker-image-optimizationSkill
- database-connection-managementSkill
- database-transactionsSkill
- distributed-databasesSkill
- nosql-data-modelingSkill
- postgres-query-tuningSkill
- redis-and-cachingSkill
- schema-migrationsSkill
- data-modeling-for-analyticsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 172
Test the installed artefact before shipping:
- Very specific: line 182
Put both in pyproject.toml.
- Very specific: line 213
Run ruff check . and ruff format .
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Python Packaging & Tooling
Modern Python is one file. pyproject.toml holds metadata, dependencies, and
tool configuration; there is no setup.py and no setup.cfg unless you are
maintaining something old. Pick uv for a new project, src/ layout always,
and make the import name match what you publish.
Workflow
- 1.
uv init --package myproject(creates pyproject, src layout,.gitignore) - 2. Set
[project] name,requires-python,dependencies - 3. Put dev tooling in
[dependency-groups] dev = [...](PEP 735) - 4. Configure
[tool.ruff]and[tool.mypy]in the same file - 5.
uv syncthenuv run pytest— verify the install before writing code - 6.
uv buildthenuv publish(or twine) once tests pass
The default: uv, src layout, one file
uv init --package myproject # pyproject.toml + src/myproject/ + .gitignore
cd myproject
uv add httpx # runtime dep -> [project.dependencies]
uv add --dev ruff mypy pytest # dev dep -> [dependency-groups].dev
uv sync # creates .venv + uv.lock from pyproject
uv run pytest # run in the venv, no activation danceuv init --package already produces the src layout and a working
[build-system]. Everything below is what to make correct in the file it
generates.
pyproject.toml
[build-system]
requires = ["hatchling"] # or "setuptools>=68", "poetry-core", "pdm-backend"
build-backend = "hatchling.build"
[project]
name = "myproject" # the DISTRIBUTION name (what you pip install)
version = "0.1.0"
description = "One line, shown on PyPI."
readme = "README.md"
requires-python = ">=3.11" # hard floor; refuse installs below it
license = "MIT" # SPDX expression ("MIT", "Apache-2.0")
authors = [{ name = "Ada Lovelace" }]
dependencies = [
"httpx>=0.27,<1.0", # range: >= lower, < upper cap
"pydantic>=2.7", # no upper cap is fine for a library
]
[project.optional-dependencies] # pip install myproject[redis]
redis = ["redis>=5"]
[project.scripts] # console_scripts entry points
myproject = "myproject.cli:main" # the VALUE is import:func, not the package
myp-admin = "myproject.admin:entrypoint"
[project.entry-points."myproject.plugins"]
example = "myproject.plugins:ExamplePlugin"
[project.urls]
Repository = "https://github.com/you/myproject"
[dependency-groups] # PEP 735; dev-only, NOT published
dev = ["pytest>=8", "mypy>=1.10", "ruff>=0.5"]
# hatchling needs to know where the package is when the import name differs
# from the distribution name:
[tool.hatch.build.targets.wheel]
packages = ["src/myproject"] # only needed for a renamed import nameThree dependency fields, three audiences — do not mix them up:
| Field | Published? | Installed by | Use for |
dependencies | Yes | anyone, always | what the code imports at runtime |
optional-dependencies | Yes (as extras) | pip install x[extra] | genuine optional features, a user choice |
dependency-groups (PEP 735) | No | pip install -e .[dev]? No — uv sync / pip with the group flag only | dev tooling: pytest, mypy, ruff, coverage |
dependency-groups are never installed when someone installs your package, and
are not PEP 621 extras. Do not put pytest in dependencies — it makes
your package heavier for every consumer and is the single most common packaging
mistake. A dev extra in [project.optional-dependencies] is the older
equivalent and still works; groups are the current answer.
Lockfiles
A lockfile pins exact resolved versions so every environment is reproducible.
| Tool | Lockfile | Install with groups | Publish backend |
| uv (default) | uv.lock | uv sync (default group dev is auto-installed) | any PEP 517 backend |
| poetry | poetry.lock | poetry install | poetry-core |
| pdm | pdm.lock | pdm install | pdm-backend |
Rules that matter:
- Commit the lockfile for applications and services. For libraries, do not — pin nothing and let the consumer resolve; a pinned transitive dep in a library is a constraint you impose on everyone.
- The lockfile is not portable across operating systems or Python
versions by default;
uvandpoetrykeep per-platform resolution so regenerate rather than copying between them. Never hand-edit one. - In CI, install from the lockfile so tests run against the same versions as
production:
uv sync --frozen(uv) orpoetry install --sync(poetry, 1.2+;poetry install --no-rootin CI so the project itself is not installed into the runner). Verify the exact flags with your version.
src-layout and the import-name trap
myproject/ # repo root
pyproject.toml
src/
myproject/ # the importable package
__init__.py
cli.pyWhy src/ matters: without it, pytest adds the repo root to sys.path, so
import myproject resolves to the working directory copy, not the
installed one. You get tests that pass against files you are not shipping, and
ModuleNotFoundError for anyone who installed the wheel (which has the package
under site-packages/myproject, but the CWD shadows it). src/ makes the
local dir unimportable, so imports always come from the installed dist.
The trap
The distribution name (what you pip install) and the import name
(the package under src/) are different namespaces and are allowed to differ —
but the build backend must be told, or it will ship an empty wheel.
[project]
name = "acme-tools" # distribution
[tool.hatch.build.targets.wheel]
packages = ["src/acme_tools"] # import name; hatchling needs the hintMismatches and their symptoms:
name = "my-project"but the folder ismy_project, with nopackages = [...]hint →pip install -e .succeeds andimport my_projectraisesModuleNotFoundError: No module named 'my_project'.- Entry point
myproject = "myproject.cli:main"but the distribution ismy-projectis fine — the script name and the distribution name are independent; only the module path in the value must be importable. - A hyphen is fine in a distribution name (they are normalised to
_in wheel filenames) but a hyphen is illegal in a Python import name.
Rule: import name with underscores, distribution name with hyphens, and if they differ, give the backend the mapping.
Editable installs
- uv:
uv sync(oruv pip install -e .) installs the project editable by default in the venv. Useuv sync --no-editableto test the real wheel. - pip:
pip install -e .needs a PEP 660-capable backend. Modern setuptools, hatchling, poetry-core, and pdm-backend all support it. An old setuptools without PEP 660 falls back to a legacysetup.py developshim and can silently not reflect source edits. - Test the installed artefact before shipping:
Editable passes but the wheel is missing a package or data file is the most common release bug.uv build # writes dist/*.whl and dist/*.tar.gz uv run --isolated --with ./dist/<wheel> python -c "import myproject"
ruff and mypy
Put both in pyproject.toml; do not keep ruff.toml/mypy.ini split across
files.
[tool.ruff]
line-length = 100
target-version = "py311"
src = ["src", "tests"]
[tool.ruff.lint]
select = ["E", "F", "I", "UP", "B", "SIM", "RUF", "ASYNC", "S", "ANN"]
ignore = ["ANN101", "ANN102"] # `self`/`cls` don't need annotations
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101"] # asserts are fine in tests
[tool.ruff.format]
quote-style = "double"
[tool.mypy]
python_version = "3.11"
strict = true # the single highest-value line here
warn_return_any = true
disallow_untyped_defs = true
plugins = ["pydantic.mypy"] # makes BaseModel fields type-check
[[tool.mypy.overrides]]
module = ["some_untyped_lib.*"]
ignore_missing_imports = true # per-module escape hatch, not global- Run
ruff check .andruff format .— the formatter is opinionated, do not fight it.ruff check --fixapplies safe fixes;--unsafe-fixesmay change behaviour. mypy --stricton a codebase with no annotations is a mountain. Start withwarn_return_anyanddisallow_untyped_defsand ratchet; do not setignore_errorsper file to make CI green, that defeats it.- The
S(bandit) rules catch real issues:S+ASYNCwill flagexcept:, blocking calls insideasync def(ASYNC210— blocking HTTP call in async function), andtime.sleepin async code. These are the single highest-value Python lint set; seepython-async-patterns. - Wire all three into one pre-commit / CI step:
uv run ruff check . && uv run ruff format --check . && uv run mypy src && uv run pytest.
Publishing to an index
# 1. build
uv build # or: python -m build
# 2. smoke-test the built artefact in a clean env (not editable!)
uv run --isolated --with dist/myproject-0.1.0-py3-none-any.whl python -c "import myproject; print(myproject.__version__)"
# 3. dry run against PyPI's staging, then publish
uv publish --check-url https://test.pypi.org/legacy/
twine upload --repository testpypi dist/* # to TestPyPI first, always
uv publish dist/* # or: twine upload dist/*- Build artifacts belong in
.gitignore(dist/,build/,*.egg-info). - TestPyPI first: it verifies upload + metadata without consuming a real version number. A version can only be published to a given index once, ever.
- Interactive TOTP-based uploads are deprecated. Use a PyPI API token stored as
__token__/pypi-…in the environment asUV_PUBLISH_TOKEN(uv) orTWINE_USERNAME/TWINE_PASSWORD(twine). Never commit a token. - Version numbers are immutable on an index. To ship again, bump the version.
- Include a
LICENSEfile and setlicense; do not rely only on metadata.
Gotchas
requirements.txtis not the source of truth for a new project. Keep it only as a generatedpip freezeexport for legacy consumers.sys.pathand CWD: runningpythonfrom the repo root of a non-src project imports the CWD copy first. This is the #1 "works on my machine" Python import bug;src/layout eliminates the class.- A
[build-system] requireslist is not your dependency list. It is the build tooling; keep it minimal and unpinned-ish. requires-pythonis enforced at install; setting it too low then using 3.12 syntax givesSyntaxErroron the installer's 3.10, not a friendly error. Set it to your real floor and use Ruff/target-versionto match.- Cython/Rust extensions need a backend that compiles them; hatchling does
not out of the box. If you ship compiled wheels, verify
buildproduces one wheel per platform tag. poetryandpdmare still fine for existing projects; do not migrate a working build just to be modern. uv is the recommendation for greenfield and for consolidating a Makefile/CI into one tool.uvdoes not install your project by default unless it is a package;uv init(without--package) creates a script project with no installable package, anduv run python -c "import x"will fail. Use--package.- Duplicate dependency in both
dependenciesand the dev group is resolved once, not twice — no conflict, but it hides a mistake about which one a runtime import actually needs.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

