--- id: pyupgrade version: "3.21.2" license: MIT license_treatment: permissive maintenance: active --- # pyupgrade — A tool to automatically upgrade syntax for newer versions. License: permissive · Maintenance: active · Downloads: 1.9M/mo ## What it is and what it does pyupgrade is a command-line tool and pre-commit hook that scans Python source files and automatically rewrites code to use modern syntax patterns. It handles a wide range of modernizations: converting old-style set and dict construction to comprehensions, replacing printf-style string formatting with `.format()` calls, removing unnecessary `u''` prefixes, simplifying `super()` calls, removing Python 2 compatibility code and six library usage, and eliminating deprecated unittest method aliases. The tool is driven by command-line flags that control which Python version's features to target, allowing gradual modernization of codebases. It runs as a standalone tool on individual files or directories, or integrates into pre-commit hooks to enforce modernization on every commit. The single runtime dependency is tokenize-rt, which handles Python tokenization. The tool requires Python 3.10 or later to run, though it can modernize code written for older Python versions by removing version-specific compatibility patterns. Use it for: - Automatically upgrade a legacy codebase from Python 2 to Python 3 by removing six imports and compatibility shims - Enforce consistent modern syntax in CI/CD pipelines via pre-commit hooks to catch outdated patterns before merge - Batch-modernize string formatting from printf-style to `.format()` across thousands of lines of code - Remove deprecated unittest method aliases (e.g., `failUnlessEqual` → `assertEqual`) from test suites - Simplify class definitions by removing unnecessary `object` inheritance and rewriting metaclass declarations ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Automatically rewrites Python source code to use newer syntax patterns, removing deprecated constructs and modernizing code style across set literals, comprehensions, string formatting, and class definitions. Yes. pyupgrade is actively maintained, has no known vulnerabilities, installs with minimal friction, and solves a real problem for teams modernizing Python codebases. Its permissive MIT license and broad adoption (top 5000 PyPI packages) make it a low-risk addition to development workflows, especially when integrated as a pre-commit hook to enforce syntax consistency automatically. ## Install pip install pyupgrade uv add pyupgrade poetry add pyupgrade ## Installing pyupgrade Before you install: Low friction install with a single runtime dependency (tokenize-rt). Active maintenance with recent releases; last commit 2026-08-13 and 4113 repository stars indicate steady use and support. License in practice: MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal restrictions. Quickstart: pip install pyupgrade # Run on a single file pyupgrade myfile.py # Or add to .pre-commit-config.yaml: # - repo: https://github.com/asottile/pyupgrade # rev: v3.21.2 # hooks: # - id: pyupgrade Requires Python 3.10 or later to run the tool itself; the code being upgraded can target older Python versions via command-line flags. Verify before relying: - Whether all syntax rewrites are safe to apply automatically without manual review in large codebases - Performance characteristics when processing very large Python files or projects - Specific Python version targets supported by command-line flags beyond those shown in examples ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 1.9M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags python syntax modernizer, automatic code upgrader, deprecated syntax fixer, python modernization tool, code style updater, python linter upgrade, syntax rewriter, code-modernization, pre-commit-hook, syntax-rewriter [View on SkillFed](https://skillfed.io/packages/pyupgrade) · [View on PyPI](https://pypi.org/project/pyupgrade/)