agentleFS
extractumioextractumio/extractum-skills/.cursor/rules/10-python-standards.mdc

extractum-skills / rules

Cursor rule47 starsChanged 10 months agoMITView on GitHub

Python coding standards and best practices

  • Reads credentials

The file

We split this 10-python-standards.mdc into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    All imports must be at the beginning of the file, never inline.

    line 13
  2. Very specific:

    Use SCREAMING_SNAKE_CASE for constants:

    line 81

≈ “Common” is an estimate: at least 1 in 5 of the 7,111 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
10-python-standards.mdc
---
description: "Python coding standards and best practices"
globs:
  - "**/*.py"
alwaysApply: false
priority: 20
---

# Python Coding Standards

## Imports Organization

All imports must be at the **beginning of the file**, never inline.

### Import Order

1. Standard library imports
2. Third-party imports
3. Local application imports

Separate each group with a blank line.

```python
# Standard library
import asyncio
import logging
import os
import sys
from datetime import datetime
from pathlib import Path
from typing import Any, TypedDict

# Third-party
from dotenv import load_dotenv

# Local application
from claude_agent_sdk import ClaudeAgentOptions, query
```

---

## Constants

### Numerical Values

Define constants for all magic numbers:

```python
# ✅ Good
DEFAULT_MAX_TURNS: int = 50
DEFAULT_MAX_BUDGET_USD: float = 1.0
LOG_PREVIEW_LENGTH: int = 200

# ❌ Bad
options = ClaudeAgentOptions(max_turns=50, max_budget_usd=1.0)
```

### String Values

Define constants for repeated strings. Use multiline `"""..."""` for long strings:

```python
# ✅ Good
ENV_API_KEY: str = "ANTHROPIC_API_KEY"
LOGGER_NAME: str = "claude_agent"

ERROR_API_KEY_MISSING: str = """
ANTHROPIC_API_KEY not found in environment variables.
Please ensure it is set in your .env file.
"""

# ❌ Bad
api_key = os.getenv("ANTHROPIC_API_KEY")
raise ValueError("ANTHROPIC_API_KEY not found...")
```

---

## Constants Naming

Use SCREAMING_SNAKE_CASE for constants:

```python
# Configuration
DEFAULT_MAX_TURNS: int = 50
LOG_ENCODING: str = "utf-8"

# Paths and directories
LOGS_DIR_NAME: str = "logs"
LOG_FILE_PREFIX: str = "agent_"

# Format strings
LOG_DATE_FORMAT: str = "%Y-%m-%d %H:%M:%S"
```

---

## Code Organization

Organize code into logical sections with separator comments:

```python
# =============================================================================
# Constants
# =============================================================================

# ... constants here ...

# =============================================================================
# Type Definitions
# =============================================================================

# ... types here ...

# =============================================================================
# Main Functions
# =============================================================================

# ... functions here ...
```

---

## Function Extraction

Extract repeated logic into helper functions (prefix private helpers with `_`):

```python
# ✅ Good - Extracted helper
def _log_separator(logger: logging.Logger) -> None:
    """Log a separator line."""
    logger.info(SEPARATOR_CHAR * SEPARATOR_LENGTH)

# ❌ Bad - Repeated inline
logger.info("=" * 50)
logger.info("SUMMARY")
logger.info("=" * 50)
```

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.