ams-python-pro
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 0
- Forks
- 1
03 SKILL.md 正文
Python Pro
Overview
Python rewards readability and the standard library: the best Python code looks obvious after you read it and leans on batteries-included modules before reaching for dependencies. This skill covers professional Python — project layout that scales, packaging without pain, type hints as documentation, testing culture, async done right, and performance work that respects how CPython actually executes.
The through-line: write Python like Python, not like Java or C wearing a Python costume.
When to use
- Starting or restructuring a Python project (layout, packaging, tooling).
- Writing or reviewing Python for idiom, correctness, or performance.
- Choosing between sync/async, packaging tools, or test frameworks.
- Debugging packaging issues, import problems, or slow code.
- Adding type hints or linting to an existing codebase.
Core concepts
- Project layout (src layout).
src/mypackage/withpyproject.tomlat root; tests intests/mirroring the package. Src layout prevents the classic bug of tests importing the local directory instead of the installed package. Onepyproject.tomldeclares metadata, dependencies, and tool config —setup.pyis legacy for most projects. - Virtual environments, always. One venv per project (
python -m venv .venv), dependencies pinned via lock file (uv.lock,poetry.lock, orrequirements.txtwith hashes for deploys). Neverpip installinto the system Python. - Type hints as documentation. Annotate public APIs (
def fetch(url: str) -> Response); runmypy/pyrightin strict-ish mode on new code. Hints catch a class of bugs tests miss and make IDE support dramatically better.dataclasses(orattrs/pydanticat boundaries) over dicts for structured data. - The stdlib is deep.
pathliboveros.path,dataclasses,functools,itertools,collections,datetimewith timezones (zoneinfo),argparse,logging,sqlite3,http.serverfor quick needs. Reach for PyPI only after checking the stdlib. - Async is for I/O concurrency.
asyncioshines when awaiting many network/disk operations; it doesn't speed up CPU work (GIL). Don't mix sync blocking calls into async code (userun_in_executorfor blocking libs); don't make everything async "just in case" — async is viral and must be justified by actual concurrency needs. - Testing culture.
pytestwith fixtures andparametrize; test behavior, not internals;coverageto find untested areas, not to chase a number. Doctests for documentation examples.
Practical workflow
- Scaffold:
src/layout,pyproject.toml(build-system, project metadata, tool configs),.venv, lock file,ruff(lint+format — fast, one tool),mypyorpyright. - Write code Pythonically: context managers for resources, comprehensions where readable,
generators for large/streaming data,
pathlib.Pathfor paths, f-strings for formatting, exceptions for exceptional cases (EAFP) with specific except clauses. - Type the boundaries. Public functions fully annotated; internal code annotated where it clarifies. Run the type checker in CI — gradually, ratcheting strictness.
- Test in layers: fast unit tests (pure functions), integration tests with real local
services where feasible (testcontainers for Postgres/Redis), and a few end-to-end tests.
pytest -x -qlocally; full suite in CI. - Profile before optimizing.
cProfile/py-spyto find hotspots; common wins: algorithmic fixes first, then reduce per-item overhead (avoid repeated attribute lookups in loops), use__slots__for millions of small objects, push inner loops to numpy/C extensions, or parallelize CPU work with multiprocessing. - Package for distribution: version in one place, build with
python -m build, publish to an internal index or PyPI; CLIs via entry points ([project.scripts]).
Standard layout:
mypackage/
├── pyproject.toml # metadata, deps, tool config
├── src/mypackage/
│ ├── __init__.py # minimal; don't import heavy deps here
│ ├── core.py
│ └── cli.py
├── tests/
│ ├── test_core.py
│ └── conftest.py # shared fixtures
└── README.md
Common pitfalls
- Mutable default arguments.
def f(items=[])shares one list across calls — the classic Python gotcha. UseNone+ initialize inside. - Bare
except:/ swallowing exceptions. Hides bugs andKeyboardInterrupt. Catch specific exceptions; log with context; let unexpected ones propagate. - Importing the wrong package. Running tests/scripts from the repo root importing local code instead of the installed package — src layout + installed venv fixes this whole class of bug.
- Timezone-naive datetimes.
datetime.now()without tz bites in serialization, scheduling, and DST. Use timezone-aware datetimes everywhere (datetime.now(timezone.utc)). - String concatenation in loops / quadratic joins. Build lists and
''.join(); use generators for streaming; don't load a 2GB file into memory to process it line by line — iterate the file object. pip freezechaos. Unpinned or transitively-bloated requirements cause "works on my machine." Lock files, regenerated deliberately, committed to the repo.- Over-engineering with classes. A module of functions beats a class with one method and no state. Python is multi-paradigm — reach for classes when there's genuine state + behavior.
04 同仓库更多 Skills
web-scrape
Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open/fetch fails on JS-heavy pages, or when you need clean markdown/structured extraction from a site. Requires FIRECRAWL_API_KEY.
design-taste-frontend
tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML/CSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, "AI-made", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.
test-driven-development
Use when implementing any feature or bugfix, before writing implementation code
systematic-debugging
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
requesting-code-review
Use when completing tasks, implementing major features, or before merging to verify work meets requirements
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).