Skip to content
Back to skills

Writing Python

ASecurity

Use when writing or editing Python 3.12+ for APIs, data processing, scripts, or tooling. Triggers on `.py` files and prompts about async code, type hints, dataclasses, pathlib, pytest, generators, or context managers, even when the user doesn't say 'Python'.

  • 6 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 30, 2026
ai-agentspythongoapiperformance

Works with

  • api

Security analysis

A100/100

Pro scans all 13 files and shows the line behind each finding

Scanned November 30, 2026

npx -y skills add xonovex/platform --skill writing-python --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Writing Python?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Writing Python
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/xonovex-writing-python/badge)](https://www.skillsdirectory.com/skills/xonovex-writing-python)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: writing-python
description: "Use when writing or editing Python 3.12+ for APIs, data processing, scripts, or tooling. Triggers on `.py` files and prompts about async code, type hints, dataclasses, pathlib, pytest, generators, or context managers, even when the user doesn't say 'Python'."
---

# Python Coding Guidelines

Write typed Python with focused functions, explicit errors, and tests that check observable behavior.

## Requirements

- Python ≥ 3.12; pytest ≥ 8.

## Essentials

- **Data models** - Use dataclasses and type hints, see [references/dataclasses-type-hints.md](references/dataclasses-type-hints.md), [references/type-checking.md](references/type-checking.md)
- **Iteration** - Prefer generators/comprehensions for data processing, see [references/generators-comprehensions.md](references/generators-comprehensions.md)
- **Performance** - Cache pure functions with `@cache`, see [references/caching-functions.md](references/caching-functions.md)
- **Resource management** - Use context managers for cleanup, see [references/resource-management.md](references/resource-management.md)
- **Modern syntax** - Use pathlib, f-strings, specific exceptions, see [references/pathlib-file-ops.md](references/pathlib-file-ops.md), [references/string-formatting.md](references/string-formatting.md), [references/exception-handling.md](references/exception-handling.md)
- **Paradigm** - Functional style → **applying-fp**; class/OO design → **applying-oop**

## Gotchas

- Mutable default arguments (`def f(x=[]):`) share state across calls: use `None` and assign inside
- The GIL serializes pure-Python execution: threads only help on I/O; CPU-bound work needs `multiprocessing` or compiled extensions
- `is` checks identity, not equality: small-int caching means `a is b` works for `1` but fails for `300`
- `__init__.py` is no longer required for packages (PEP 420), but mixing namespace and regular packages causes silent import-shadowing bugs

## Progressive disclosure

- Read [references/dataclasses-type-hints.md](references/dataclasses-type-hints.md) - Load when defining structured data models or adding type annotations
- Read [references/type-checking.md](references/type-checking.md) - Load when using Protocols, type aliases, or complex Union types
- Read [references/resource-management.md](references/resource-management.md) - Load when working with files, connections, or resources needing cleanup
- Read [references/caching-functions.md](references/caching-functions.md) - Load when optimizing expensive computations or repeated function calls
- Read [references/generators-comprehensions.md](references/generators-comprehensions.md) - Load when processing large datasets or streaming data
- Read [references/string-formatting.md](references/string-formatting.md) - Load when formatting output, building messages, or templating
- Read [references/pathlib-file-ops.md](references/pathlib-file-ops.md) - Load when reading/writing files or traversing directories
- Read [references/exception-handling.md](references/exception-handling.md) - Load when defining error handling or creating custom exceptions

Files in this skill

  • SKILL.md3.1 KB
  • eval-output.json2.8 KB
  • eval-trigger.json5.4 KB
  • moon.yml86 B
  • references/caching-functions.md531 B
  • references/dataclasses-type-hints.md546 B
  • references/exception-handling.md634 B
  • references/generators-comprehensions.md644 B
  • references/pathlib-file-ops.md542 B
  • references/resource-management.md564 B
  • references/string-formatting.md348 B
  • references/type-checking.md579 B
  • sources.json1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.