Confirm successful installation by checking the skill directory location:
.cursor/skills/python-code-style
Restart Cursor to activate python-code-style. Access via /python-code-style in your agent's command palette.
โ
Security Notice
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your environment. Always review source, verify the publisher, and test in isolation before production.
Consistent code style and clear documentation make codebases maintainable and collaborative. This skill covers modern Python tooling, naming conventions, and documentation standards.
When to Use This Skill
Setting up linting and formatting for a new project
Writing or reviewing docstrings
Establishing team coding standards
Configuring ruff, mypy, or pyright
Reviewing code for style consistency
Creating project documentation
Core Concepts
1. Automated Formatting
Let tools handle formatting debates. Configure once, enforce automatically.
2. Consistent Naming
Follow PEP 8 conventions with meaningful, descriptive names.
3. Documentation as Code
Docstrings should be maintained alongside the code they describe.
4. Type Annotations
Modern Python code should include type hints for all public APIs.
Quick Start
# Install modern toolingpip install ruff mypy
# Configure in pyproject.toml[tool.ruff]line-length =120target-version ="py312"# Adjust based on your project's minimum Python version[tool.mypy]strict =true
Fundamental Patterns
Pattern 1: Modern Python Tooling
Use ruff as an all-in-one linter and formatter. It replaces flake8, isort, and black with a single fast tool.
# pyproject.toml[tool.ruff]line-length=120target-version="py312"# Adjust based on your project's minimum Python version[tool.ruff.lint]select=["E",# pycodestyle errors"W",# pycodestyle warnings"F",# pyflakes"I",# isort"B",# flake8-bugbear"C4",# flake8-comprehensions"UP",# pyupgrade"SIM",# flake8-simplify]ignore=["E501"]# Line length handled by formatter[tool.ruff.format]quote-style="double"indent-style="space"
Run with:
ruff check --fix.# Lint and auto-fixruff format.# Format code
Pattern 2: Type Checking Configuration
Configure strict type checking for production code.
Group imports in a consistent order: standard library, third-party, local.
# Standard libraryimport os
from collections.abc import Callable
from typing import Any
# Third-party packagesimport httpx
from pydantic import BaseModel
from sqlalchemy import Column
# Local importsfrom myproject.models import User
from myproject.services import UserService
Write docstrings for all public classes, methods, and functions.
Simple Function:
defget_user(user_id:str)-> User:"""Retrieve a user by their unique identifier."""...
Complex Function:
defprocess_batch( items:list[Item], max_workers:int=4, on_progress: Callable[[int,int],None]|None=None,)-> BatchResult:"""Process items concurrently using a worker pool.
Processes each item in the batch using the configured number of
workers. Progress can be monitored via the optional callback.
Args:
items: The items to process. Must not be empty.
max_workers: Maximum concurrent workers. Defaults to 4.
on_progress: Optional callback receiving (completed, total) counts.
Returns:
BatchResult containing succeeded items and any failures with
their associated exceptions.
Raises:
ValueError: If items is empty.
ProcessingError: If the batch cannot be processed.
Example:
>>> result = process_batch(items, max_workers=8)
>>> print(f"Processed {len(result.succeeded)} items")
"""...
Class Docstring:
classUserService:"""Service for managing user operations.
Provides methods for creating, retrieving, updating, and
deleting users with proper validation and error handling.
Attributes:
repository: The data access layer for user persistence.
logger: Logger instance for operation tracking.
Example:
>>> service = UserService(repository, logger)
>>> user = service.create_user(CreateUserInput(...))
"""def__init__(self, repository: UserRepository, logger: Logger)->None:"""Initialize the user service.
Args:
repository: Data access layer for users.
logger: Logger for tracking operations.
""" self.repository = repository
self.logger = logger
Pattern 6: Line Length and Formatting
Set line length to 120 characters for modern displays while maintaining readability.
# Good: Readable line breaksdefcreate_user( email:str,
Implementation Guide
Prerequisites
โบClaude Desktop or compatible AI client with skill support
โบClear understanding of task or problem to solve
โบWillingness to iterate and refine outputs
Time Estimate
15-45 minutes depending on use case complexity
Steps
1Install skill using provided installation command
2Test with simple use case relevant to your work
3Evaluate output quality and relevance
4Iterate on prompts to improve results
5Integrate into regular workflow if valuable
Common Pitfalls
โ Expecting perfect results without iteration
โ Not providing enough context in prompts
โ Using skill for tasks outside its intended scope
โ Accepting outputs without review and validation
Best Practices
โ Do
+Start with clear, specific prompts
+Provide relevant context and constraints
+Review and refine all outputs before using
+Iterate to improve output quality
+Document successful prompt patterns
โ Don't
โDon't use without understanding skill limitations
โDon't skip validation of outputs
โDon't share sensitive information in prompts
โDon't expect skill to replace human judgment
๐ก Pro Tips
โ Be specific about desired format and style
โ Ask for multiple options to choose from
โ Request explanations to understand reasoning
โ Combine AI efficiency with human expertise
When to Use This
โ Use when
Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.
โ Avoid when
Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.
Learning Path
1Familiarize yourself with skill capabilities and limitations
2Start with low-risk, non-critical tasks
3Progress to more complex and valuable use cases
4Build expertise through regular use and experimentation