python
Python development with ruff, mypy, pytest - TDD and type safety
pinned to #e8b4af6updated 2 weeks ago
Ask your AI client: “install skills/python”.
Requires the metahub MCP server installed in your client. Set up MCP.
mh install skills/pythonmetahub onboarded this repo on the author's behalf.
If you own github.com/alinaqi/maggy on GitHub, claim the listing to take over publishing. Your claim preserves the existing eval history and badges; only the curator label is replaced with verified-publisher on your next publish.
Stars
702
Last commit
2 weeks ago
Latest release
published
- #ai-coding
- #claude
- #claude-code
- #developer-tools
- #project-initialization
- #python
- #react
- #security
- #typescript
About this skill
Pulled from SKILL.md at publish time.
---
Evaluation report
WarningsAutomated checks the publisher passed at publish time — structure, docs, safety, and whether the artifact behaves as claimed.e8b4af6· 2 weeks ago
Documentation
41Description qualitywarn
11 words · 64 chars — skills use the description as their trigger; aim higher
Aim for 15+ words and include trigger phrases like “use this skill when …”.
README is present and substantial
12,261 chars · 14 sections · 10 code blocks
Tags / topics declared
9 total — ai-coding, claude, claude-code, developer-tools, project-initialization, python (+3)
README has usage / example sections
no labeled section but 10 code blocks document usage
Homepage / docs URL declared
https://www.srooter.ai
Release history
1- releasecurrente8b4af6warn2 weeks ago
Contents
Type Hints
- Use type hints on all function signatures
- Use
typingmodule for complex types - Run
mypy --strictin CI
def process_user(user_id: int, options: dict[str, Any] | None = None) -> User:
...
Project Structure
project/
├── src/
│ └── package_name/
│ ├── __init__.py
│ ├── core/ # Pure business logic
│ │ ├── __init__.py
│ │ ├── models.py # Pydantic models / dataclasses
│ │ └── services.py # Pure functions
│ ├── infra/ # Side effects
│ │ ├── __init__.py
│ │ ├── api.py # FastAPI routes
│ │ └── db.py # Database operations
│ └── utils/ # Shared utilities
├── tests/
│ ├── unit/
│ └── integration/
├── pyproject.toml
└── CLAUDE.md
Tooling (Required)
# pyproject.toml
[tool.ruff]
line-length = 100
select = ["E", "F", "I", "N", "W", "UP"]
[tool.mypy]
strict = true
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "--cov=src --cov-report=term-missing --cov-fail-under=80"
Testing with Pytest
# tests/unit/test_services.py
import pytest
from package_name.core.services import calculate_total
class TestCalculateTotal:
def test_returns_sum_of_items(self):
# Arrange
items = [{"price": 10}, {"price": 20}]
# Act
result = calculate_total(items)
# Assert
assert result == 30
def test_returns_zero_for_empty_list(self):
assert calculate_total([]) == 0
def test_raises_on_invalid_item(self):
with pytest.raises(ValueError):
calculate_total([{"invalid": "item"}])
GitHub Actions
name: Python Quality Gate
on: [push, pull_request]
jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install -e ".[dev]"
- name: Lint (Ruff)
run: ruff check .
- name: Format Check (Ruff)
run: ruff format --check .
- name: Type Check (mypy)
run: mypy src/
- name: Test with Coverage
run: pytest
Pre-Commit Hooks
# .pre-commit-config.yaml
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
additional_dependencies: [pydantic]
args: [--strict]
- repo: local
hooks:
- id: pytest
name: pytest
entry: pytest tests/unit -x --tb=short
language: system
pass_filenames: false
always_run: true
Install and setup:
pip install pre-commit
pre-commit install
Patterns
Pydantic for Data Validation
from pydantic import BaseModel, Field
class CreateUserRequest(BaseModel):
email: str = Field(..., min_length=5)
name: str = Field(..., max_length=100)
Dependency Injection
# Don't import dependencies directly in business logic
# Pass them in
# Bad
from .db import database
def get_user(user_id: int) -> User:
return database.fetch(user_id)
# Good
def get_user(user_id: int, db: Database) -> User:
return db.fetch(user_id)
Result Pattern (No Exceptions in Core)
from dataclasses import dataclass
@dataclass
class Result[T]:
value: T | None
error: str | None
@property
def is_ok(self) -> bool:
return self.error is None
Python Anti-Patterns
- ❌
from module import * - ❌ Mutable default arguments
- ❌ Bare
except:clauses - ❌ Using
type: ignorewithout explanation - ❌ Global variables for state
- ❌ Classes when functions suffice
Reviews
No reviews yet. Be the first.
Related
Frontend Slides
Create beautiful slides on the web using Claude's frontend skills
React Doctor
Your agent writes bad React. This catches it
orchestration-patterns
>
mh install skills/python