Skip to main content

Sourcery Logo

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-nightly 1.46.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for sourcery-nightly 1.46.0
File
sourcery_nightly-1.46.0-py2.py3-none-win_amd64.whl Python 3, Python 2 none Windows x86-64 Details
sourcery_nightly-1.46.0-py2.py3-none-manylinux1_x86_64.whl Python 3, Python 2 none Linux glibc 2.5+ x86-64 Details
sourcery_nightly-1.46.0-py2.py3-none-macosx_11_0_arm64.whl Python 3, Python 2 none macOS 11.0+ ARM64 Details
sourcery_nightly-1.46.0-py2.py3-none-macosx_10_9_x86_64.whl Python 2, Python 3 none macOS 10.9+ x86-64 Details

Total release size: 440.9 MB

Release files / sourcery_nightly-1.46.0-py2.py3-none-win_amd64.whl

Download URL sourcery_nightly-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
73d5d8367a51222cb5302c820452174ce549a5e055eb8eea7d86383cae43fc24
BLAKE2b-256 checksum
How to use checksums
9de74cc803e7fb0a78dd71b9810412ebd95a58c141fd4216eeb495211b15f7c5
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

Release files / sourcery_nightly-1.46.0-py2.py3-none-manylinux1_x86_64.whl

Download URL sourcery_nightly-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
edde833e7b98469589115bce92e92d75d8f62120f417bcb5107f3453b5bc43fd
BLAKE2b-256 checksum
How to use checksums
1afdcf8bb3e10894e9b9b2d1b3b317acccc92aa29e1fbf48863e49cd727ecd9d
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

Release files / sourcery_nightly-1.46.0-py2.py3-none-macosx_11_0_arm64.whl

Download URL sourcery_nightly-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
195da181997b5862a5299657f1fb809c52d226eabe6f1ba9d060a35d716d849d
BLAKE2b-256 checksum
How to use checksums
6834943712176406727b4793b5601e8eee4d4150daae3de9899314670b75fe14
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

Release files / sourcery_nightly-1.46.0-py2.py3-none-macosx_10_9_x86_64.whl

Download URL sourcery_nightly-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
aad164010f612a6ff3de3060d56fe5878334265aa6b19fa41edeaaf05846313b
BLAKE2b-256 checksum
How to use checksums
d089b6892d4a7bb47cb9bba651d4601e91169afb85c1478ea51a60ef763e830b
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

Release history Release notifications | RSS feed

This release

1.46.0 This release

4 release files

1.45.0

4 release files

1.44.0

4 release files

1.40.0

3 release files

1.39.0

3 release files

1.38.0

3 release files

1.37.0

3 release files

1.35.0

3 release files

1.34.0

3 release files

1.33.0

3 release files

1.32.0

3 release files

1.31.0

3 release files

1.30.0

3 release files

1.28.0

3 release files

1.27.0

3 release files

1.26.0

3 release files

1.25.0

3 release files

1.23.0

3 release files

1.22.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page