npx skills add ...
npx skills add wshobson/agents --skill python-project-structure
Python project organization, module architecture, and public API design. Use when setting up new projects, organizing modules, defining public interfaces with __all__, or planning directory layouts.
npx skills add wshobson/agents --skill python-project-structure
Design well-organized Python projects with clear module boundaries, explicit public interfaces, and maintainable directory structures. Good organization makes code discoverable and changes predictable.
__all__Group related code that changes together. A module should have a single, clear purpose.
Define what's public with __all__. Everything not listed is an internal implementation detail.
Prefer shallow directory structures. Add depth only for genuine sub-domains.
Apply naming and organization patterns uniformly across the project.
Each file should focus on a single concept or closely related set of functions. Consider splitting when a file:
__all__Define the public interface for every module. Unlisted members are internal implementation details.
Prefer minimal nesting. Deep hierarchies make imports verbose and navigation difficult.
Add sub-packages only when there's a genuine sub-domain requiring isolation.
Choose one approach and apply it consistently throughout the project.
Option A: Colocated Tests
Benefits: Tests live next to the code they verify. Easy to see coverage gaps.
Option B: Parallel Test Directory
Benefits: Clean separation between production and test code. Standard for larger projects.
Use __init__.py to provide a clean public interface for package consumers.
Consumers can then import directly from the package:
Organize code by architectural layer for clear separation of concerns.
Each layer should only depend on layers below it, never above.
For complex applications, organize by business domain rather than technical layer.
snake_case for all file and module names: user_repository.pyuser_repository.py not usr_repo.pyUserService in user_service.pyUse absolute imports for clarity and reliability:
Relative imports can break when modules are moved or reorganized.
__all__ explicitly - Make public interfaces clear