python-refactor

Refactor Python modules and services into modular, testable structures without changing behavior.

Updated Sep 14, 2026
One-click install
npx skills add https://github.com/Lawrence908/chiron --skill python-refactor-lawrence908
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-refactor
Source: https://github.com/Lawrence908/chiron/tree/main/plugins/dev/skills/python-refactor
Command: npx skills add https://github.com/Lawrence908/chiron --skill python-refactor-lawrence908

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Python codebases accumulate structural debt over time: duplicated logic, oversized files, business logic tangled in views, and missing type hints. This Skill restructures modules, services, and scripts into cleaner, modular, testable code while preserving existing behavior and API contracts. ## Core Features & Use Cases - Structured Refactoring Workflow: Analyzes existing code for duplication, side effects, and async/sync mixing, then applies minimal safe transformations such as extracting functions, splitting files, and adding service layers. - Behavior Preservation: Enforces guardrails against breaking API changes, unnecessary dependencies, and unrequested behavior changes, with before/after diff summaries. - Use Case: Given a Django view containing direct database calls, the Skill extracts a service layer (e.g., a PlayerService class), converts to async where appropriate, adds type hints, and leaves the view as a thin wrapper. ## Quick Start Refactor this Python service module to be more modular and testable without changing its public API.

Frequently Asked Questions about python-refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor a Python module without breaking existing behavior?▼

Analyze the code for duplication and side effects first, then apply minimal safe transformations like extracting functions or splitting files while preserving the public API. Verify with a before/after diff summary and tests confirming behavior is unchanged.

How to move business logic out of Django views into a service layer?▼

Extract database operations and business rules into a dedicated service class, leaving the view as a thin wrapper that calls the service. For example, move Player.objects.create calls into a PlayerService with typed static or async methods.

When should I convert sync Python functions to async during refactoring?▼

Convert only when the surrounding framework and call sites support async, such as Django async views or FastAPI endpoints. Converting without understanding implications can break callers, so preserve existing async/sync patterns by default.

What are common Python refactoring anti-patterns to avoid?▼

Avoid overengineering simple scripts, adding excessive abstraction, breaking existing APIs without permission, and removing code that seems redundant but serves a purpose. Refactoring should not change behavior unless explicitly requested.

Can refactoring add type hints to legacy Python code?▼

Yes, adding type hints is a standard part of refactoring for clarity and IDE support. Apply them where they improve readability, alongside consistent naming conventions and organized imports following PEP8.