📖 About Python
Python is a high-level, interpreted programming language known for its simplicity and readability. It's the #1 most popular language worldwide, excelling in data science, machine learning, web development, automation, and scripting. Python's extensive ecosystem and gentle learning curve make it ideal for both beginners and experts.
🎯 Best For
- Data science and machine learning (NumPy, Pandas, Scikit-learn)
- Web development (Django, FastAPI, Flask)
- Automation and scripting
- Scientific computing and research
- Backend APIs and microservices
🔧 Key Features
- Type hints for static type checking (Python 3.10+)
- Dataclasses for data containers
- List/dict comprehensions for concise code
- Context managers (with statement)
- Decorators for metaprogramming
- Extensive standard library and ecosystem
🛠️ Development Tools
Build
pip install -e .
Test
pytest --cov
Coverage
pytest --cov=src --cov-report=html
Run
python -m myapp
📄 Package Contents (7 files)
AGENTS_RULES.md
Complete AI agent rules (universal)
- PYTHON-specific best practices
- TDD workflow (Red-Green-Refactor)
- DDD principles and patterns
- Git workflow and commit format
- Code quality principles
.cursorrules
Quick reference for Cursor IDE
- Essential rules summary
- Links to full documentation
- Optimized for quick loading
.gitignore
Git exclusions
- PYTHON-specific patterns
- Build artifacts
- IDE configuration files
- Dependency directories
AGENTS.md
Quick reference guide
- Common patterns
- Best practices summary
- Quick troubleshooting
README.md
Project template with examples
- Setup instructions
- Sample code and structure
- Testing examples
- Build and run commands
CODE_QUALITY_PRINCIPLES.md
Quality principles and best practices
- Avoid default values (fail-fast)
- Consistency across code paths
- Extract reusable functions
- PYTHON-specific examples
CONTRIBUTING.md
Contribution guidelines
- TDD workflow (Red-Green-Refactor)
- Git commit format
- Code review process
- Testing requirements (90% coverage)
💻 Code Examples
Type Hints & Dataclasses
from dataclasses import dataclass
from typing import Optional
@dataclass
class User:
name: str
email: str
age: Optional[int] = None
def create_user(name: str, email: str) -> User:
return User(name=name, email=email)
Result Pattern
from typing import Generic, TypeVar, Union
from dataclasses import dataclass
T = TypeVar('T')
E = TypeVar('E')
@dataclass
class Ok(Generic[T]):
value: T
@dataclass
class Err(Generic[E]):
error: E
Result = Union[Ok[T], Err[E]]
def divide(x: float, y: float) -> Result[float, str]:
if y == 0:
return Err("division by zero")
return Ok(x / y)
Context Manager
from contextlib import contextmanager
from typing import Iterator
@contextmanager
def database_transaction() -> Iterator[Connection]:
conn = connect_to_db()
try:
yield conn
conn.commit()
except Exception:
conn.rollback()
raise
finally:
conn.close()
with database_transaction() as conn:
conn.execute("INSERT ...")