Pyrefly Configuration
Pyrefly has a basic configuration that can (or will) allow you to customize your Pyrefly runs without having to specify all of your arguments on the command line.
NOTE: this is early in its development, so the options listed here are subject to change in name, usage, type, quantity, and structure.
Configurations can be specified in a TOML file at the root of
your project (or elsewhere, as long as the path-based config options point to the right place) named
pyrefly.toml, with all configuration options in the top-level of the document.
You can also specify a configuration in a pyproject.toml under a [tool.pyrefly]
section. Other config names can be used when explicitly passing in the config file
name with the --config/-c flag, but they will not be automatically found by
Configuration Finding.
Both absolute and config-relative paths are supported.
Want type error squiggles to show up in your editor by default? Try setting python.pyrefly.displayTypeErrors to "force-on" in your editor settings, create a pyrefly.toml file in your project root, or add a [tool.pyrefly] section to your pyproject.toml (can be empty).
Simple Configuration Example
Here's an example of a simple config. To see more complex examples,
including in a pyproject.toml, look at
Example Configurations, which show Pyrefly's default
config, as well as other ways you can set your configuration.
# set the directory Pyrefly will search for files to type check
project-includes = [
"a", "b/c/d", "e"
]
# manually set the `sys.platform` Pyrefly will assume when type checking
python-platform = "linux"
# a table mapping error codes to an `is-enabled` boolean
[errors]
# disable `bad-assignment` errors
bad-assignment = false
# disable `bad-return` errors
bad-return = false
Precedence in Options
Configuration options are selected in the following order
- CLI flags
- Examples:
--project-excludes <value>,--python-version <value>
- Examples:
- Configuration options
- Examples: (in a
pyrefly.toml)project-excludes = <value>,python-version = <value>
- Examples: (in a
- Pyrefly defaults
- See Default
pyrefly.tomlfor the default values used
- See Default
Type Checking Modes
Pyrefly has two different modes it can run in when type checking your project, which correspond to different but useful ways we expect most people to interact with Pyrefly:
- Project mode: attempt to load a config, falling back to Pyrefly's default config when
none can be found, and type check using that one config. This involves getting the
project-includesandproject-excludesfrom the file, expanding the patterns, and type checking on those files.- Project mode is used whenever no files are provided with the CLI invocation.
- Per-file or Single-file mode: when given
FILES...(and optionally--project-excludes) during a CLI invocation, expand the patterns and find the relevant config file for each file listed.project-includesandproject-excludesare ignored from the config file, but it is used for all remaining config options.
Configuration Finding
In both project checking mode and single-file checking mode (see Type Checking Modes for more info), we attempt to find a project root from which to check each file, both for reading config options and for import resolution. The project root is typically the directory containing the configuration file. More precisely:
- If a configuration file is provided with
-c/--config, we use the directory the file is located in as the directory to check. - If no configuration file is passed, we perform an upward file search from the 'start location' to the filesystem root,
looking in each directory for any of the following files:
pyrefly.toml,pyproject.toml,setup.py,mypy.ini, andpyrightconfig.json. If we find one, we use the directory it's found in as the containing directory. - If no configuration file is found, we will still attempt to resolve imports by walking up the tree looking for a matching import. For example: when
importing
from a.b.c import q, if our project structure looks like/x/y/z/a/b/c, we can walk up the components ofa.b.cto find a root at/x/y/z.
Note that only pyrefly.toml and pyproject.toml are parsed for config options, but we look for
additional files that mark the root of a project to aid import resolution.
For project checking mode, the 'start location' is current working directory. For single-file checking mode, the start location is the directory containing each file to be type checked, and we find the config for each file matched by the pattern provided.
If a pyrefly.toml is found, it is parsed and used for type checking, and will
return an error to the user on invalid types, syntax, values, or unknown config options.
If a pyproject.toml is found, Pyrefly will use the [tool.pyrefly]
section if it exists, otherwise it will assume a default config.
The same errors will be returned as when loading a pyrefly.toml if
the config is invalid.
Providing a Config in Single-File Mode
Providing -c/--config in single-file checking mode disables the upward file search for config
files. All options are read from the provided config file except project-includes and
project-excludes, which are ignored.
Configuration Options
The following section lists all recognized options that can be specified in a config
file or pyproject.toml Pyrefly config section.
project-includes
The glob patterns used to describe which files to type check, typically understood as user-space files.
This does not specify
Import Resolution priority or the path an
import should be resolved from. See search-path instead.
- Type: list of filesystem glob patterns
- Default:
["**/*.py*"] - Flag equivalent:
FILES...argument - Equivalent configs:
includein Pyright,files/modules/packagesin mypy - Notes:
- When overridden by passing in
FILES..., we do not consult the relevant config file for what to use forproject-excludes. Ifproject-excludesshould not use the default value, override it with the flag as well. This is because if multiple configs are loaded that conflict withproject-includes, determining how to resolve checkable files gets complicated, and might become confusing to anyone attempting a type check if they're unaware of all the configs that will be used in the type check. Also, we get into a chicken-and-egg problem, where we don't know which files to exclude until we load all the configs we'll need, which requires loading all files, and imposes a large performance burden. - When a
project-includespattern does not match any files, we will return an error. - If you get an error about no matches for a directory when passing a glob as a CLI argument, try wrapping the glob in quotes to prevent eager shell glob expansion.
- When overridden by passing in
project-excludes
The glob patterns used to describe which files to avoid
type checking as way to filter files that match project-includes,
but we don't want to type check.
The default value is appended to your project-excludes unless disable-project-excludes-heuristics
is set. See disable-project-excludes-heuristics to fully replace
or remove project-excludes.
- Type: list of filesystem glob patterns
- Default:
["**/node_modules", "**/__pycache__", "**/venv/**", "**/.[!/.]*/**"]+ anything in yoursite-package-path(even from the interpreter) unless it would exclude items in yoursearch-path. - Flag equivalent:
--project-excludes - Equivalent configs:
excludein Pyright and mypy - Notes:
- While not explicitly part of
project-excludes, there are several patterns that are filtered out of type checked files at our glob-implementation layer.- Dotfiles (any files that begin with a dot (
.<stuff>) - Any files that don't end in
.pyor.pyi - Your
site-package-path(including paths queried from the interpreter)
- Dotfiles (any files that begin with a dot (
- It is an error if no files are returned from any
project-includesbecause they are filtered out byproject-excludesentries. We differentiate between an error from aproject-includesthat doesn't match any files, and an error from allproject-includesgetting filtered byproject-excludes. - When overridden by passing in
FILES..., we do not consult the relevant config file for what to use forproject-excludes. Ifproject-excludesshould not use the default value, override it with the flag as well. See reasoning inproject-includesnotes. - Your
site-package-pathis added to yourproject-excludesautomatically. If you are trying to perform type checking on a dependency in yoursite-package-path(i.e.cd <site-package-path>/some_dependency && pyrefly check), we recommend you pull and set up your dependency from GitHub, but you can achieve this on files in yoursite-package-pathby settingsite-package-path = []in your config.
- While not explicitly part of
disable-project-excludes-heuristics
By default, Pyrefly includes several items in your project-excludes
(see project-excludes for the default values). These items are path patterns we've
determined rarely have files that should be type checked, but can require a very long
time to crawl while enumerating files, or contain third-party code that you likely
don't care about errors in. When specifying project-excludes, we always append
these defaults to whatever is specified by CLI or in your configuration.
Sometimes, these preselected settings can interfere with your project's setup.
disable-project-excludes-heuristics lets you start from scratch, setting that default to [],
so you can fully specify your project-excludes in case we get it wrong.
- Type:
bool - Default:
false - Flag equivalent:
--disable-project-excludes-heuristics
search-path
A file path describing the roots from which imports should be
found and imported from (including modules in project-includes). This takes
the highest precedence in import order,
before typeshed and site-package-path. When a project-includes
type checked file is imported by another type checked file, we check all search roots to
determine how to import it.
- Type: list of directories specifying the root
- Default: import root
- Flag equivalent:
--search-path - Equivalent configs:
extraPathsin Pyright,mypy_pathin mypy - Notes:
- We automatically apply some heuristics to improve your experience, especially
when no configuration is provided. See
disable-search-path-heuristicsto disable this behavior, and Search Path Heuristics for the additional paths we add to yoursearch-path. - Libraries should not be listed here, since they may override
typeshedvalues for your whole project, and have different import semantics with respect to typing. See Import Resolution for more information about how modules are imported.
- We automatically apply some heuristics to improve your experience, especially
when no configuration is provided. See
disable-search-path-heuristics
Disable any search path heuristics/additional search path behavior that Pyrefly will attempt to do for you. This can be useful if Pyrefly is picking up the wrong import paths for your project, for example, if you have multiple projects in the same directory or use a monorepo setup with the import root outside of the directory your configuration is defined in.
See Search Path Heuristics for more information on the search paths that are automatically added, and are affected by this flag. For more information on import resultion in general see the import resolution docs.
- Type: bool
- Default: false
- Flag equivalent:
--disable-search-path-heuristics - Equivalent configs: none
- Notes
- To see what search path we find for your a given file in your project, or
your project overall, you can run
pyrefly dump-config [<file>...].
- To see what search path we find for your a given file in your project, or
your project overall, you can run
Search Path Heuristics
Pyrefly adds extra search paths to your configuration behind-the-scenes to handle
the most common ways of setting up and configuring your project, on top of any
search-path entries you may pass in through the CLI or
set in your config.
The two heuristics that are currently supported are:
- Adding your import root to the end of your search path. Your import root is
a
src/directory in the same directory as a config file, the parent directory containing your config file if there's an__init__.pyor__init__.pyipresent or the config file's directory itself if none of the previously mentioned directories or files can be found. See Configuration Finding for more information on what we'll find as a config file. - If no config can be found, each directory from the given file to
/will be added as a fallback search path.
See more on how Pyrefly does import resolution.
site-package-path
A file path describing a root from which imports should
be found and imported from. This takes the lowest priority in import
resolution, after search-path and typeshed.
See more on how Pyrefly does import resolution.
- Type: list of directories
- Default:
./typings+ the result from Environment Autoconfiguration, or[]if the Python interpreter cannot be queried - Flag equivalent:
--site-package-path - Equivalent configs: none
- Notes:
- The queried interpreter's site package paths will always be included in addition to any user-specified value, unless environment auto-configuration is turned off.
- Ideally, this should not be set manually, unless you're using a venv, running one-off tests, testing specific behavior, or having trouble with Environment Autoconfiguration. Setting this explicitly, especially when not using a venv, will make it difficult for your configuration to be reused between different systems and platforms.
- If you're running into problems with editiable installations in your project, please read up on editable installs with static analysis tools.
python-platform
The value used with conditions based on type checking
against
sys.platform
values.
- Type: string
- Default: result from Environment Autoconfiguration, or "linux" if the Python interpreter cannot be queried
- Flag equivalent:
--python-platform - Equivalent configs:
pythonPlatformin Pyright,platformin mypy
python-version
The value used with conditions based on type checking
against
sys.version
values. The format should be <major>[.<minor>[.<micro>]], where minor and
micro can be omitted to take the default positional value.
- Type: string of the format
<major>[.<minor>[.<micro>]] - Default: result from Environment Autoconfiguration, or
3.13.0if the Python interpreter cannot be queried - Flag equivalent:
--python-version - Equivalent configs:
pythonVersionin Pyright,python_versionin mypy
conda-environment
The name of the Conda environment to query when attempting to autoconfigure
Python environment values (site-package-path, python-platform, python-version).
See the Environment Autoconfiguration section for more
information. We query Conda with conda info --envs, then find the environment's interpreter in Environment Autoconfirugration.
We will query Conda for information about this environment, even when it's not sourced,
unless a Python environment (venv, Conda) is activated or --python-interpreter-path or
--conda-environment are passed in through the CLI.
conda-environment, fallback-python-interpreter-name, conda-environment,
and skip-interpreter-query are mutually exclusive with each other.
- Type: string of existing Conda environment name
- Default: none
- Flag equivalent:
--conda-environment - Equivalent configs: none
- Notes:
- This enables the use of a non-local but customizable global environment without having to hard-code a path, which is not preferable on a shared project.
python-interpreter-path
The Python interpreter to query when attempting to autoconfigure
Python environment values (site-package-path, python-platform, python-version).
See the Environment Autoconfiguration section for more information.
conda-environment, fallback-python-interpreter-name, conda-environment,
and skip-interpreter-query are mutually exclusive with each other.
- Type: path to executable
- Default:
$(which python3), then$(which python), or none - Flag equivalent:
--python-interpreter-path - Equivalent configs:
python_executablein mypy - Notes:
- This executes the value present in the
python-interpreter-pathfield without any checks. It could be a security risk if yourpython-interpreter-pathis an arbitrary executable. - If you don't have a Python interpreter installed on your machine, we'll output an
error letting you that we couldn't appropriately configure your environment.
Configure
skip-interpreter-queryto skip the check and avoid the error.
- This executes the value present in the
NOTE: Ideally, this should not be set manually, unless you're using a venv, running one-off tests, testing specific behavior, or having trouble with Environment Autoconfiguration. Setting this explicitly, especially when not using a venv, will make it difficult for your configuration to be reused between different systems and platforms.
fallback-python-interpreter-name
The Python interpreter, available on your $PATH, to use. Pyrefly will perform
which <your command>, and automatically fill in python-interpreter-path for you with
the found path. Pyrefly will automatically search for python3 and python on your
path when this option and python-interpreter-path are unset if
skip-interpreter-query = false,
so this should primarily be used when you have a non-standard Python executable you want to
use.
conda-environment, fallback-python-interpreter-name, conda-environment,
and skip-interpreter-query are mutually exclusive with each other.
- Type: string of command to use
- Default:
python3, thenpython, or none - Flag equivalent:
--fallback-python-interpreter-name - Notes:
- This executes the value present in the
fallback-python-interpreter-namefield without any checks. It could be a security risk if yourfallback-python-interpreter-nameis an arbitrary executable. - If you don't have a Python interpreter installed on your machine, we'll output an
error letting you that we couldn't appropriately configure your environment.
Configure
skip-interpreter-queryto skip the check and avoid the error.
- This executes the value present in the
skip-interpreter-query
Skip querying any interpreters and do not do any
Environment Autoconfiguration. This means that
Pyrefly will take hard-coded defaults for python-version
and python-platform, and will use an empty
site-package-path. It's likely you'll want to override
these to match the environment you'll be running in.
conda-environment, fallback-python-interpreter-name, conda-environment,
and skip-interpreter-query are mutually exclusive with each other.
- Type: bool
- Default:
false - Flag equivalent:
--skip-interpreter-query
typeshed-path
Override the version of typeshed that's being used for type checking. The provided path should point to the root of typeshed.
Typeshed contains the type information for Python's
standard library, which Pyrefly uses for type checking and resolving both the most basic
types (like object, str, ...) and types/type signatures from stdlib modules.
- Type: path to typeshed
- Default: none (resolves to bundled typeshed)
- Flag equivalent:
--typeshed-path
baseline
Path to a baseline JSON file for comparing type errors. Errors matching the baseline are suppressed, so only newly-introduced errors are reported. This is useful when introducing type checking to a project for the first time, or when rolling out changes that would otherwise produce many new errors at once.
To generate (or re-generate) the baseline file, run:
pyrefly check --baseline="<path to baseline file>" --update-baseline
See the Error Suppressions docs for more details on how baseline files work.
- Type: path to a JSON file
- Default: none (no baseline)
- Flag equivalent:
--baseline - Notes:
baselineis a project-level setting and cannot be overridden insub-configsections.- Errors suppressed by the baseline file are still shown in the IDE.
- Errors are matched with the baseline by file, error code, and column number.
errors
Configure the severity for each kind of error that Pyrefly emits: error, warn, ignore.
Want type error squiggles to show up in your editor by default? Try setting python.pyrefly.displayTypeErrors to "force-on" in your editor settings, create a pyrefly.toml file in your project root, or add a [tool.pyrefly] section to your pyproject.toml (can be empty).
- Type: Table of error code to boolean representing enabled status
- Default:
errors = {}/[errors] - Flag equivalent:
--error,--warn,--ignore - Equivalent configs:
type check rule overrides
and type evaluation settings
in Pyright,
enable_error_codeanddisable_error_codein mypy - Notes:
- Setting
<error-code> = truemeans the error will be shown at default severity (or severityERRORif the error is off by default). Setting<error-code> = falsewill disable the error for type checking. - If you want to disable type errors in IDE mode, you can also set
disable-type-errors-in-ide, which will automatically disable all type errors and Pyrefly diagnostics in the IDE.
- Setting
disable-type-errors-in-ide
Disables type errors from showing up when running Pyrefly in an IDE. This is primarily used when Pyrefly is acting in a language-server-only mode, but some kind of manual configuration is necessary for it to work properly, or when you would only want to see type errors on CLI/CI runs.
- Type:
bool - Default:
false - Flag equivalent: none
- Notes: if you want to disable errors on CLI/CI runs as well, or if you're looking
to turn on/off specific errors, you may be looking for the
errorsconfig option instead.