Skip to content
Back to skills

Python

ASecurity

Python programming with type hints, async/await, decorators, and package management. Use for .py files and data science.

  • 57 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added May 31, 2026
developmentpythongofastapidjangoapi

Works with

  • cli
  • api

Security analysis

A92/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned May 31, 2026

npx -y skills add diegosouzapw/awesome-omni-skill --skill python --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Python?

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

Security grade badge for Python
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/diegosouzapw-python/badge)](https://www.skillsdirectory.com/skills/diegosouzapw-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: python
description: Python programming with type hints, async/await, decorators, and package management. Use for .py files and data science.
---

# Python

Modern Python development with type hints, async/await, and best practices.

## When to Use

- Working with `.py` files
- Building APIs with FastAPI/Django
- Data analysis with pandas/numpy
- Scripting and automation

## Quick Start

```python
from typing import Optional, List

def process_items(
    items: list[str],
    transform: Optional[callable] = None,
) -> list[str]:
    if transform:
        return [transform(item) for item in items]
    return items
```

## Core Concepts

### Type Hints

```python
from typing import TypeVar, Generic
from collections.abc import Callable, Iterator

def process_items(
    items: list[str],
    transform: Callable[[str], str] | None = None,
) -> list[str]:
    if transform:
        return [transform(item) for item in items]
    return items

# Use TypeVar for generics
T = TypeVar('T')

def first(items: list[T]) -> T | None:
    return items[0] if items else None
```

### Dataclasses & Pydantic

```python
from dataclasses import dataclass, field
from pydantic import BaseModel, Field

# Dataclass for simple data containers
@dataclass
class User:
    name: str
    email: str
    tags: list[str] = field(default_factory=list)

# Pydantic for validation
class UserCreate(BaseModel):
    name: str = Field(..., min_length=1, max_length=100)
    email: str = Field(..., pattern=r'^[\w\.-]+@[\w\.-]+\.\w+$')
```

## Common Patterns

### Async Patterns

```python
import asyncio

async def fetch_all(urls: list[str]) -> list[Response]:
    async with aiohttp.ClientSession() as session:
        tasks = [fetch_one(session, url) for url in urls]
        return await asyncio.gather(*tasks)

# Use TaskGroup for structured concurrency (3.11+)
async def process_batch(items: list[Item]) -> list[Result]:
    results = []
    async with asyncio.TaskGroup() as tg:
        for item in items:
            tg.create_task(process_item(item, results))
    return results
```

### Context Managers

```python
from contextlib import contextmanager, asynccontextmanager

@contextmanager
def managed_resource() -> Iterator[Resource]:
    resource = Resource()
    try:
        yield resource
    finally:
        resource.cleanup()
```

## Best Practices

**Do**:

- Use type hints for function signatures
- Use `pyproject.toml` for project configuration
- Use virtual environments (`venv`, `poetry`)
- Use generators for large datasets

**Don't**:

- Use mutable default arguments (`def f(x=[]`)
- Use `import *` (pollutes namespace)
- Catch bare `except:` (catch specific exceptions)
- Use `assert` for input validation

## Troubleshooting

| Error                        | Cause                  | Solution                           |
| ---------------------------- | ---------------------- | ---------------------------------- |
| `ModuleNotFoundError`        | Package not installed  | Run `pip install package`          |
| `IndentationError`           | Mixed tabs/spaces      | Use consistent 4-space indentation |
| `TypeError: unhashable type` | Using list as dict key | Use tuple instead                  |

## References

- [Python Official Docs](https://docs.python.org/3/)
- [Real Python](https://realpython.com/)

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.

Comments

Loading comments…

Newsletter

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