python-project-structure
What it does
Helps organize your Python code projects to make them easier to understand and manage. This includes how to name files, where to put code, and how to define what's public or private.
When to use it
- βWhen starting a new Python project.
- βWhen reorganizing existing code.
- βWhen deciding how to split your code into smaller parts.
Skill link
https://github.com/wshobson/agents/blob/main/plugins/python-development/skills/python-project-structure/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow should I organize the folder structure for a new Python web project?β
5 new skills a week. 1 minute to read.
How it works
The AI suggests how to group related code into files and folders, defines which parts of the code can be used by others, and how to organize tests.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Python Project Structure & Module Architecture
Design well-organized Python projects with clear module boundaries, explicit public interfaces, and maintainable directory structures. Good organization makes code discoverable and changes predictable.
When to Use This Skill
- Starting a new Python project from scratch
- Reorganizing an existing codebase for clarity
- Defining module public APIs with
__all__ - Deciding between flat and nested directory structures
- Determining test file placement strategies
- Creating reusable library packages
Core Concepts
1. Module Cohesion
Group related code that changes together. A module should have a single, clear purpose.
2. Explicit Interfaces
Define what's public with __all__. Everything not listed is an internal implementation detail.
3. Flat Hierarchies
Prefer shallow directory structures. Add depth only for genuine sub-domains.
4. Consistent Conventions
Apply naming and organization patterns uniformly across the project.
Quick Start
myproject/
βββ src/
β βββ myproject/
β βββ __init__.py
β βββ services/
β βββ models/
β βββ api/
βββ tests/
βββ pyproject.toml
βββ README.md
Fundamental Patterns
Pattern 1: One Concept Per File
Each file should focus on a single concept or closely related set of functions. Consider splitting when a file:
- Handles multiple unrelated responsibilities
- Grows beyond 300-500 lines (varies by complexity)
- Contains classes that change for different reasons
# Good: Focused files
# user_service.py - User business logic
# user_repository.py - User data access
# user_models.py - User data structures
# Avoid: Kitchen sink files
# user.py - Contains service, repository, models, utilities...
Pattern 2: Explicit Public APIs with __all__
Define the public interface for every module. Unlisted members are internal implementation details.
# mypackage/services/__init__.py
from .user_service import UserService
from .order_service import OrderService
from .exceptions import ServiceError, ValidationError
__all__ = [
"UserService",
"OrderService",
"ServiceError",
"ValidationError",
]
# Internal helpers remain private by omission
# from .internal_helpers import _validate_input # Not exported
Pattern 3: Flat Directory Structure
Prefer minimal nesting. Deep hierarchies make imports verbose and navigation difficult.
# Preferred: Flat structure
project/
βββ api/
β βββ routes.py
β βββ middleware.py
βββ services/
β βββ user_service.py
β βββ order_service.py
βββ models/
β βββ user.py
β βββ order.py
βββ utils/
βββ validation.py
# Avoid: Deep nesting
project/core/internal/services/impl/user/
Add sub-packages only when there's a genuine sub-domain requiring isolation.
Pattern 4: Test File Organization
Choose one approach and apply it consistently throughout the project.
Option A: Colocated Tests
src/
βββ user_service.py
βββ test_user_service.py
βββ order_service.py
βββ test_order_service.py
Benefits: Tests live next to the code they verify. Easy to see coverage gaps.
Option B: Parallel Test Directory
src/
βββ services/
β βββ user_service.py
β βββ order_service.py
tests/
βββ services/
β βββ test_user_service.py
β βββ test_order_service.py
Benefits: Clean separation between production and test code. Standard for larger projects.
Advanced Patterns
Pattern 5: Package Initialization
Use __init__.py to provide a clean public interface for package consumers.
# mypackage/__init__.py
"""MyPackage - A library for doing useful things."""
from .core import MainClass, HelperClass
from .exceptions import PackageError, ConfigError
from .config import Settings
__all__ = [
"MainClass",
"HelperClass",
"PackageError",
"ConfigError",
"Settings",
]
__version__ = "1.0.0"
Consumers can then import directly from the package:
from mypackage import MainClass, Settings
Pattern 6: Layered Architecture
Organize code by architectural layer for clear separation of concerns.
myapp/
βββ api/ # HTTP handlers, request/response
β βββ routes/
β βββ middleware/
βββ services/ # Business logic
βββ repositories/ # Data access
βββ models/ # Domain entities
βββ schemas/ # API schemas (Pydantic)
βββ config/ # Configuration
β¦
FAQ
What is `__all__`?
It's a list you define in a Python file to explicitly state which parts of your code are public and can be used by other programs. Anything not in the list is considered internal.
Is it better to have many folders or few?
Generally, it's better to have few folders (a 'flat' structure). Add more folders only if truly necessary to separate large parts of the project.
Where should I put test files?
You can place them alongside the code they test or in a separate 'tests' folder. The key is to be consistent.
Details
Original description by the author
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.
repo: wshobson/agents
Popularity
- GitHub stars
- 41k
- Ranking position
- #6765
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
screen-reader-testing
41kHas your agent test websites using screen readers to ensure they are accessible.
wcag-audit-patterns
41kHelps your agent audit websites for accessibility and fix issues according to WCAG guidelines.
multi-reviewer-patterns
41kEnables your agent to coordinate parallel code reviews, deduplicating findings and consolidating reports.
parallel-debugging
41kAllows the agent to debug complex issues with parallel investigations and root cause analysis.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.