Sourcery Command Line Interface
Installation and usage
Installation
Sourcery command line interface can be installed by running:
pip install sourcery
Login
Once installed you need to log in with:
sourcery login
which will open up a browser tab and ask for confirmation. This is only needed once per computer.
You can also log in via providing your token:
sourcery login --token YOUR_TOKEN
Usage
To review a file or a directory (recursively) with Sourcery, use the
sourcery review command:
sourcery review example_file.py
To apply the changes suggested by Sourcery, use the --fix option:
sourcery review --fix {file_or_directory}
Command Line Options
Sourcery provides a few options for running. You can list them by running
sourcery review --help
sourcery review --help
Usage: sourcery review [OPTIONS] [SRC]...
Review SRC files/directories. Reads from stdin when SRC is -
Options:
--diff TEXT Run only on changed code with diff command (e.g.
"git diff")
--enable TEXT Only run the specified rule or tag. This option
can be used multiple times.
--disable TEXT Skip the specified rule or tag. This option can
be used multiple times.
--check Return exit code 1 if unsolved issues found.
--fix Automatically fix issues where possible.
--config FILE Location of the Sourcery YAML config file. Can be
a file or URL.
--csv Output in CSV format
--verbose Verbose output with explanation and code
snippets.
--summary / --no-summary Flag to determine whether to print a summary of
the review. Default: true.
-h, --help Show this message and exit.
Configuration
Sourcery reads configuration settings from .sourcery.yaml in the project
directory. The
JSON schema
lists every field it accepts.
Pre-commit Hook
Sourcery works great with pre-commit. Once you
have it installed, add this to the
.pre-commit-config.yaml in your repository:
repos:
- repo: https://github.com/sourcery-ai/sourcery
rev: v1.46.0
hooks:
- id: sourcery
# The best way to use Sourcery in a pre-commit hook:
# * review only changed lines:
# * omit the summary
args: [--diff=git diff HEAD, --no-summary]
To review all changes compared to the main branch:
args: [--diff=git diff main]
If you want Sourcery to automatically apply the suggested changes,add the
--fix option:
args: [--diff=git diff HEAD, --fix]
If Sourcery is the first pre-commit hook that you've added to your project,
you'll also need to run pre-commit install.
Continuous Integration
For the majority of projects, the best usage of Sourcery in the CI is to review only the code of the current PR.
You can use the script below to detect Sourcery violations that are present in
the current code but not in the main branch:
pip install sourcery
# Store your Sourcery token as a secret in your CI environment.
sourcery login --token $SOURCERY_TOKEN
sourcery review --diff "git diff main" .
Instead of main, you can pick another branch as well. For example, in GitHub
Actions you can use
--diff="git diff ${{ github.event.pull_request.base.sha }}"
Release files for sourcery 1.46.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| sourcery-1.46.0-py2.py3-none-win_amd64.whl | Python 3, Python 2 | none | Windows x86-64 | Details |
| sourcery-1.46.0-py2.py3-none-manylinux1_x86_64.whl | Python 2, Python 3 | none | Linux glibc 2.5+ x86-64 | Details |
| sourcery-1.46.0-py2.py3-none-macosx_11_0_arm64.whl | Python 2, Python 3 | none | macOS 11.0+ ARM64 | Details |
| sourcery-1.46.0-py2.py3-none-macosx_10_9_x86_64.whl | Python 3, Python 2 | none | macOS 10.9+ x86-64 | Details |
Total release size: 440.8 MB
Release files / sourcery-1.46.0-py2.py3-none-win_amd64.whl
| Download URL | sourcery-1.46.0-py2.py3-none-win_amd64.whl |
|---|---|
| Size | 95.0 MB |
| Tags | Python 2 Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
790f5c8d5567f41a68a339c17e8947c235a83bb6d27d9880b8ccdd53d1305ade
|
|
BLAKE2b-256 checksum How to use checksums |
8d8859f2da728768fd462b52ed06b2ce5831648e46d218e2cd1da9c108a732e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.
Transparency logRelease files / sourcery-1.46.0-py2.py3-none-manylinux1_x86_64.whl
| Download URL | sourcery-1.46.0-py2.py3-none-manylinux1_x86_64.whl |
|---|---|
| Size | 137.5 MB |
| Tags | Linux glibc 2.5+ x86-64 Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b6bbf53acfd21d12399a74ce891b40ddf4a9fdcc56a8511f5f237923dfdb2fa2
|
|
BLAKE2b-256 checksum How to use checksums |
3c4b1d50091efe83de343bc7e93177f9475b7d4fec870eb78ed4b6b465d78afe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.
Transparency logRelease files / sourcery-1.46.0-py2.py3-none-macosx_11_0_arm64.whl
| Download URL | sourcery-1.46.0-py2.py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 96.8 MB |
| Tags | Python 2 Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f3da3536158c5acd3fc8462e8e58ee96538f12f36c9f1deafcadf1af8d6875dd
|
|
BLAKE2b-256 checksum How to use checksums |
2695754a136c08cbc15f9180406ca125d18fcf95804d345c24cede7ae0f9adaa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.
Transparency logRelease files / sourcery-1.46.0-py2.py3-none-macosx_10_9_x86_64.whl
| Download URL | sourcery-1.46.0-py2.py3-none-macosx_10_9_x86_64.whl |
|---|---|
| Size | 111.6 MB |
| Tags | Python 2 Python 3 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
0a0a96e4241c786eb98f304835e20788cf539c646744def58ee03ce744360b05
|
|
BLAKE2b-256 checksum How to use checksums |
a7735c811ec03285b869f564f710458c9ec4e95f6e1838aad9bff0fa5f61edf5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.
Transparency log