Skip to content
Back to skills

Prefer Pathlib Over Os Path

ASecurity

When a function handles filesystem paths, build them with pathlib.Path

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added October 17, 2026
ai-agents

Security analysis

A100/100

Scanned October 17, 2026

npx -y skills add samugit83/cortex --skill prefer-pathlib-over-os-path --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Prefer Pathlib Over Os Path?

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

Security grade badge for Prefer Pathlib Over Os Path
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/samugit83-prefer-pathlib-over-os-path/badge)](https://www.skillsdirectory.com/skills/samugit83-prefer-pathlib-over-os-path)

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: prefer-pathlib-over-os-path
description: When a function handles filesystem paths, build them with pathlib.Path
---

# Paths

`pathlib.Path` reads better than string joining and carries its own helpers.

1. Take `Path` objects in signatures that accept a path, and accept `str` only
   at the edge where a caller hands one in.
2. Build a child path with the `/` operator: `root / "data" / "catalog.json"`.
3. Read and write through `Path.read_text()` and `Path.write_text()` with an
   explicit `encoding="utf-8"` rather than opening a file by hand.
4. Use `Path.resolve()` once, at the boundary, and pass the resolved path down
   instead of resolving it again in every function that receives it.

A signature that accepts both a string and a Path should say so in its
annotation (`str | Path`) so a reader knows which forms are handled.

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.