Automated Python refactors for cleaner code assistants
Sourcery is an AI-driven code assistant that suggests automated Python refactors inline and in pull requests; it’s ideal for individual Python developers and engineering teams who want consistent style, fewer micro-PRs, and faster code reviews. The core capability is automated, reviewable refactoring suggestions; pricing includes a free tier for personal use and paid team plans for CI and organization-wide enforcement.
Sourcery is an AI code assistant focused on automated refactorings and style improvements for Python code. It plugs into editors and CI to produce suggested edits, diffs, and automated pull request comments that remove boilerplate and simplify logic. Sourcery’s key differentiator is repo-wide, automated refactoring rules combined with IDE and Git integration that surface actionable changes rather than generating new code from scratch. It’s aimed at Python developers, code reviewers, and engineering teams seeking consistent style and fewer micro-fixes. A free tier exists for personal use, with paid plans unlocking team features and CI enforcement.
Sourcery is a specialist code-assistant built to analyze Python code and propose targeted refactorings rather than generate large swathes of new code. Founded to reduce repetitive review work, Sourcery positions itself as a developer-centric refactoring engine that integrates into the editor, Git hosting, and CI. Its core value proposition is automated, reviewable changes: give your repo to Sourcery and it will suggest small, focused edits (like simplifying conditionals, extracting variables, and replacing loops with comprehensions) that can be accepted as diffs. The product emphasizes minimal, safe edits that preserve behavior while improving readability and maintainability.
Under the hood, Sourcery offers several concrete features. The in-editor extensions for VS Code and JetBrains IDEs show inline suggestions and quick-fix actions that can be applied file-by-file. The GitHub/GitLab pull request integration posts suggested edits as review comments or creates suggested commits so reviewers can accept changes directly. Sourcery also provides a CLI and GitHub Action that scan repositories and produce a report of refactor suggestions across the codebase, enabling automated checks in CI. Configuration files let teams enable or disable specific rule types and ignore files or directories, so refactor suggestions match team style and standards.
Pricing follows a freemium model. A Free tier covers individual developers with editor extensions and basic PR suggestions for public and private repos at no cost. Paid plans add organization features: a Pro/Team tier (approximate pricing varies by seat) unlocks repo scanning in CI, organization-wide configuration, and priority support. Enterprise plans are custom-priced and include SSO, dedicated onboarding, and on-prem or private deployment options for strict compliance needs. Note: exact per-seat prices and seat minimums are subject to change and should be confirmed on Sourcery’s pricing page.
Sourcery is used by individual Python developers who want to reduce manual refactors and by teams that want consistent code style enforced automatically. For example, a Senior Python Engineer uses Sourcery to reduce code-review time by accepting small, verified refactors before human review, while a DevOps engineer adds the Sourcery GitHub Action to prevent style-drift across microservices. Compared with a general code generator like GitHub Copilot, Sourcery focuses on incremental, behavior-preserving refactors and CI enforcement rather than full-line generative completions.
Three capabilities that set Sourcery apart from its nearest competitors.
Current tiers and what you get at each price point. Verified against the vendor's pricing page.
| Plan | Price | What you get | Best for |
|---|---|---|---|
| Free | Free | Editor suggestions and basic PR comments for individual use | Solo developers and hobby projects |
| Pro / Team | Approx $10–25/user/mo | CI scans, org config, repo-wide reports, per-seat billing | Small teams enforcing consistent refactors |
| Enterprise | Custom | SSO, dedicated onboarding, on-prem or private deployment | Large orgs with compliance requirements |
Copy these into Sourcery as-is. Each targets a different high-value workflow.
You are Sourcery, an AI refactoring assistant for Python. Task: refactor a single Python function that I will paste below. Constraints: preserve public API and runtime behavior; keep the original signature and docstring; do not introduce third-party libraries; prefer comprehensions, builtins, short-circuiting, and clearer control flow; keep variable names intact unless renaming increases clarity. Output format: 1) the complete refactored function code block only, 2) a 2–3 bullet terse explanation of the key changes and why they are safer/cleaner. Example input (for style): def process(items): ... — I will paste my function now.
You are Sourcery, an automated refactoring engine. Task: analyze the Python file text I will provide and remove unused imports and unused local/module-level variables. Constraints: do not change runtime semantics (avoid removing imports used by import hooks or string-evaluated names), preserve __all__ and exported names, respect conditional imports (keep if used in platform-specific blocks). Output format: 1) a unified diff (git-style) showing removed lines, 2) a short list of removed identifiers and the reason (unused, shadowed, or false-positive risk). Example: provide full file content after this prompt.
You are Sourcery advising an engineering manager. Input: a short repo summary (number of Python files, total LOC, test coverage percent, critical microservices list). Task: produce a prioritized 5-item refactor plan tailored to that repo. Constraints: include estimated LOC affected, estimated review effort (Low/Med/High), risk level (Low/Med/High), required test or migration steps, and an expected CI metric improvement. Output format: JSON array of five objects with fields: rule_name, rationale, loc_affected_estimate, effort, risk, tests_required, expected_impact. Example input: {"py_files":120,"loc":35000,"coverage":62}.
You are Sourcery generating a CI configuration for GitHub Actions. Task: output a ready-to-paste .github/workflows/sourcery.yml file that scans Python files, posts PR comments for suggestions, and fails the job when new issues exceed a configurable threshold. Constraints: include inputs for API token (secrets.SOURCERY_TOKEN), exclude paths (tests/, vendor/), and allow a numeric threshold parameter; use a matrix for python versions 3.8-3.11. Output format: the complete YAML workflow file content followed by a 2–3 line explanation of how to adjust threshold and exclusions. Example: show the workflow content only, then the explanation.
You are a Senior Engineer designing Sourcery-driven PR comment templates and acceptance rules. Task: produce a JSON object containing three templated PR comments (style, refactor-risky, rename/behavioral) with placeholders, plus matching acceptance criteria and reviewer guidance. Constraints: include examples (few-shot) illustrating one comment filled for a simple list-comprehension suggestion and one for a risky refactor requiring a test; each template must include: title, body_template, actionable checklist, required approvals, and suggested labels. Output format: a single JSON object with keys 'style', 'risky', 'rename' each mapping to the described template object. Example: show how the 'style' template looks when filled for converting a loop to a comprehension.
You are Sourcery's rules engineer. Task: design three custom refactoring rules for repository automation. For each rule, provide: rule_id, human-readable description, AST match pattern or regex, transformation pseudocode, before/after code examples, unit-test snippet demonstrating expected change, priority (Low/Med/High), and rollback notes if behavior changes. Constraints: every rule must preserve behavior unless explicitly marked 'behavioral' and must include a short risk mitigation plan. Output format: a JSON array of three rule objects. Example: include one rule converting manual index loops to enumerate-based loops.
Choose Sourcery over GitHub Copilot if you prioritize automated, reviewable Python refactors and CI enforcement rather than broad generative completions.
Head-to-head comparisons between Sourcery and top alternatives: