
Python Resource Management
Write Python code that reliably releases connections, file handles and other resources using context managers.
- Repository
- wshobson/agents
- Stars
- 42,095
- Licence
- MIT
- Files
- 2 files
What it does
This skill teaches the agent to write Python code that always cleans up resources such as database connections, file handles and network sockets, even when an error happens partway through. It gives the agent standard patterns to follow: the with statement, class-based and async context managers, the contextlib decorators, and ExitStack for dynamic numbers of resources. Once installed, when you ask for Python code that opens and manages resources, the agent will tend to structure it this way instead of relying on manual close calls.
Great for
- Python developers writing code that opens database connections, files or sockets
- Developers building custom context managers or async resource pools
- Teams reviewing Python code for missing cleanup on error paths
Skip it if
- Non-Python projects, since the patterns are Python-specific
- Experienced developers who already know context managers and only need a quick reference; the skill adds little beyond standard library documentation
- Code that must be verified against your own libraries: examples use psycopg, asyncpg and structlog, which the agent may assume without checking your project's versions
Try asking
- “Write a Python class that wraps a PostgreSQL connection so it closes automatically with a with statement”
- “Refactor this file-processing function so the file and temp files are always cleaned up on exceptions”
- “Create an async context manager for an asyncpg connection pool”
- “Build a streaming response handler in Python that accumulates state and releases resources on failure”
Install in 3 steps
- 1
Download the skill
The ZIP contains the 2 original files, the MIT licence and an attribution note.
python-resource-management.zip - 2
Add it to your agent
Claude Code (all projects)
mkdir -p ~/.claude/skills && unzip python-resource-management.zip -d ~/.claude/skills/Claude Code / Agent SDK (this project only)
mkdir -p .claude/skills && unzip python-resource-management.zip -d .claude/skills/Claude apps (web/desktop): Settings → Capabilities → Skills → Upload skill, and choose the ZIP.
- 3
Ask for the task
No special command needed — the agent reads the skill's description and loads it when your request matches. Try one of the prompts above.
Get better results
- Name your libraries and versions in the request so the agent does not guess the database driver API
- Ask for tests that verify cleanup runs on exceptions, since the skill's own checklist recommends this
- Review any suppression logic (returning True from __exit__) before accepting it, as the skill itself warns against unintended suppression
What's inside
- references/details.md
- SKILL.md
Redistributed unmodified from wshobson/agents under the MIT licence. The assessment was drafted with AI from the skill's files on 2026-10-29. Skills can instruct your agent to run code — read SKILL.md and any scripts before installing.