Pants v2: Fast, consistent builds for Python and more

Welcome to the Pants v2 documentation hub!

Pants v2 is a fast, scalable build system for growing codebases. It's currently focused on Python, with support for other languages coming soon.

Here you'll find guides to help you get started with Pants v2, comprehensive documentation on how to configure, run and customize Pants v2, and information on how to get help from the Pants community.

Get Started

Project introspection

Finding insights in your project.

Pants provides several goals to provide insights into your project's structure.


Tip: Use xargs to pipe these goals into other Pants commands

For example:

$ ./pants dependees project:lib | xargs ./pants test

See Advanced target selection for more info and other techniques to use the results.

list - find your project's targets

list will find all targets that match the arguments.

For example, to show all targets in your project:

$ ./pants list ::

filter - find targets that match a predicate

filter is like list, but will only include targets that match the predicate(s).

Specify a predicate by using one of the below filter options, like --target-type. You can use a comma to OR multiple values, meaning that at least one member must be matched. You can repeat the option multiple times to AND each filter. You can prefix the filter with - to negate the filter, meaning that the target must not be true for the filter.

Some examples:

# Only `python_library` targets.
./pants filter --target-type=python_library ::

# `python_library` or `python_tests` targets.
./pants filter --target-type='python_library,python_tests' ::

# `python_library` targets which have "type_checked" in their `tags` field.
./pants filter --target-type=python_library --tag-regex=type_checked ::

# Any target except for `python_library` targets
./pants filter --target-type='-python_library' ::

filter --target-type

Each value should be the name of a target type, e.g. python_library or resources. Run ./pants help targets to see what targets are registered.

filter --address-regex

Regex strings for the address, such as ^dir or :util$.

filter --tag-regex

Regex strings for the tags field. Alternatively, you can use the global --tags option, which uses exact string matches instead of regex. See Advanced target selection.

dependencies - find a target's dependencies

Use dependencies to list all targets used directly by a target.

$ ./pants dependencies helloworld/util

To include transitive dependenciesβ€”meaning the dependencies of the direct dependenciesβ€”use --transitive:

$ ./pants dependencies --transitive helloworld/util

You can also output your 3rdparty requirements (e.g. Python requirement strings) by using --type=3rdparty or --type=source-and-3rdparty:

$ ./pants dependencies --type=3rdparty helloworld/util

dependees - find which targets depend on a target

The dependees goal finds all targets that directly depend on the target you specify.

$ ./pants dependees helloworld/util

To include transitive dependeesβ€”meaning targets that don't directly depend on your target, but which depend on a target that does directly use your targetβ€”use --transitive:

$ ./pants dependees --transitive helloworld/util

To include the original target itself, use --closed:

$ ./pants dependees --closed helloworld/util

Finally, we recommend --output-format=json when using multiple input targets:

$ ./pants dependees --output-format=json helloworld/util helloworld/protos
    "helloworld/protos:protos": [
    "helloworld/util:util": [


Tip: use dependees when starting a big migration

Running ./pants dependees --transitive --output-format=json :: will allow you to find the most-depended on code in your project, such as util code. Often, you will want to convert these targets first.

For example, do this when migrating from Python 2 to Python 3, or adding an incremental type checker like MyPy or TypeScript to your project.

filedeps - find which files a target owns

filedeps outputs all of the files belonging to a target, based on its sources field.

$ ./pants filedeps --no-absolute helloworld/util

To output absolute paths, use the option --absolute:

$ ./pants filedeps --absolute helloworld/util

To include the files used by dependencies (including transitive dependencies), use --transitive:

$ ./pants filedeps --transitive helloworld/util

count-loc - count lines of code

count-loc counts the lines of code of the specified files by running the Succinct Code Counter tool.

$ ./pants count-loc '**/*.py' '**/*.proto'
Language                 Files     Lines   Blanks  Comments     Code Complexity
Python                      13       155       50        22       83          5
Protocol Buffers             1        11        3         2        6          0
Total                       14       166       53        24       89          5

SCC has dozens of options. You can pass through options by either setting --scc-args or using -- at the end of your command, like this:

./pants count-loc '**' -- --no-cocomo


See unexpected results? Set pants_ignore.

By default, Pants will ignore all globs specified in your .gitignore, along with dist/ and any hidden files.

To ignore additional files, add to the global option pants_ignore in your pants.toml, using the same syntax as .gitignore files.

For example:

pants_ignore.add = ["/ignore_this_dir/"]

Updated 24 days ago

Project introspection

Finding insights in your project.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.