skillZs
★ LIVE SKILL TAGS ★
>>> LIVE SKILLS INDEX <<<
* OPEN SOURCE *
NO LOGIN, NO TRACKING
※ REAL INSTALL DATA ※
← back to all skills
eyadsibai/ltk0 installs

Python Patterns

This skill should be used when the user asks about "Python best practices", "Pythonic code", "Python patterns", "Python idioms", "type hints", "dataclasses", "async Python", "Python decorators", "context managers"

How do I install this agent skill?

npx skills add https://github.com/eyadsibai/ltk --skill python-patterns
view source ↗

Is this agent skill safe to install?

  • Gen Agent Trust Hubpass

    The skill provides educational information on modern Python best practices and idioms. No security issues were detected.

  • Socketpass

    No alerts

  • Snykpass

    Risk: LOW · No issues

  • Runlayerpass

    1 file scanned · No issues

What does this agent skill do?

Python Patterns

Guidance for writing idiomatic, modern Python code.

Modern Python Features (3.9+)

FeaturePurposeKey Concept
Type hintsStatic analysisdef func(x: str) -> int:
DataclassesStructured dataAuto __init__, __repr__, etc.
Context managersResource cleanupwith statement guarantees cleanup
DecoratorsCross-cutting concernsWrap functions to add behavior
Async/awaitConcurrent I/ONon-blocking operations

Type Hints

Modern syntax (3.10+): Use | for unions, built-in types for generics.

OldModern
Optional[str]str | None
Union[str, int]str | int
List[str]list[str]
Dict[str, int]dict[str, int]

Key concept: Type hints are for tooling (mypy, IDEs) - no runtime enforcement.


Dataclasses vs Alternatives

UseFor
@dataclassMutable data with methods
@dataclass(frozen=True)Immutable, hashable
NamedTupleLightweight, tuple semantics
TypedDictDict with known keys
PydanticValidation, serialization

Context Managers

Use for any resource that needs cleanup: files, connections, locks, transactions.

Pattern: Acquire in __enter__, release in __exit__ (or use @contextmanager with yield)


Decorators

PatternUse Case
Simple decoratorLogging, timing
Decorator with argsConfigurable behavior
Class decoratorModify class definition
@functools.wrapsPreserve function metadata

Async Python

When to use: I/O-bound operations (HTTP requests, DB queries, file I/O)

When NOT to use: CPU-bound operations (use multiprocessing instead)

ConceptPurpose
async defDefine coroutine
awaitSuspend until complete
asyncio.gather()Run multiple concurrently
async withAsync context manager
async forAsync iteration

Pythonic Idioms

Instead ofUse
if len(x) > 0:if x:
for i in range(len(x)):for item in x: or enumerate()
d.has_key(k)k in d
try/if exists (LBYL)try/except (EAFP)
Manual swapa, b = b, a

Project Structure

my_project/
├── src/my_package/     # Source code
├── tests/              # Test files
├── pyproject.toml      # Project config
└── README.md

Key concept: Use src/ layout to prevent import confusion.


Tooling

ToolPurpose
ruffFast linter + formatter
mypyType checking
pytestTesting
uv/pipDependencies

Resources

Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.

<a href="https://skillzs.dev/skills/eyadsibai/ltk/python-patterns">View Python Patterns on skillZs</a>