Skip to content

Getting Started

Installing Sourcery

Welcome to Sourcery!

If you haven't already installed Sourcery, the first step is to add it to your IDE of choice or your GitHub repo. Follow these instructions to install Sourcery for:

Installing Sourcery

You can run Sourcery in your IDE, in your GitHub repos, or through our CLI. To install Sourcery follow the instructions for the platform of your choice below:

IDE Installation

Code Hosting Tool Installation

CLI Installation

Note: Sourcery CLI, CI, & pre-commit usage are only currently available for use with a Team subscription.

Finding Your First Refactoring

Sourcery continually checks your code and looks for opportunties to refactor it to make it clearer, cleaner, and easier to work with. In your IDE, Sourcery will underline or highlight any section of code where it can make a refactoring. In GitHub it can refactor your entire repo or can act as a code review tool for every new pull request.

In Your IDE

Sourcery will scan any Python files you have open to try to find potential refactorings. If you aren't seeing any refactorings in your current Python file, try pasting in this example:

def refactoring_example(spellbook):
    result = []
    for spell in spellbook:
        if spell.is_awesome:
            result.append(spell)
    return result

You should see Sourcery immediately highlight the result = [] line with a refactoring suggestion.

Hover your mouse over the underlined section to see a description of the change and a diff of Sourcery's refactoring.

To accept one of Sourcery's changes, bring up the code actions/quick fix menu, and choose to apply the changes. Or you can click on the lightbulb icon to apply the changes.

Accepting Changes In VS Code

You can also bring up all of the changes Sourcery is suggesting to your open files by opening up the Problems window in VS Code or the Sourcery window in PyCharm.

In GitHub

Once you've added Sourcery to your GitHub repo, Sourcery will automatically scan your repo to find opportunties to improve your code. If Sourcery can make refactorings, it will automatically open a pull request with suggestions.

Check out your GitHub dashboard to see Sourcery's pull requests on your repos.

To accept Sourcery's suggestions all you need to do is merge the PR.

Creating an account

To use Sourcery's advanced features you need a Sourcery account. You can create a free account using your email address, Gmail account, or GitHub account to try out all of the Sourcery Pro features for 30 days. If you are planning on using Sourcery within GitHub you'll need to use your GitHub account.

Back to top