dmypy command is a client for controlling the mypy daemon (server). Running mypy as a daemon can be 10x or more faster than the regular command-line tool for large codebases, especially for incremental checks.
How it works
The daemon keeps program state cached in memory and uses fine-grained dependency tracking to minimize reprocessing. This makes subsequent type checking runs much faster after the initial run.Each mypy daemon process supports one user and one set of source files, and can only process one type checking request at a time.
Basic usage
Daemon lifecycle commands
Check files, starting or restarting the daemon if needed. This is the recommended command for most workflows.
Start the daemon but do not check any files.
Restart the daemon. Equivalent to stop followed by start.
Stop the daemon.
Kill the daemon process.
Check whether a daemon is running.
Type checking commands
Check a list of files using an already running daemon.
Re-check the same set of files as the most recent check or recheck command.
Inspection commands
Suggest a signature or show call sites for a specific function.
Locate and statically inspect expression(s).
Common flags
Use FILE as the status file for storing daemon runtime state.Default:
.dmypy.json in current directoryServer shutdown timeout in seconds. Automatically shut down after TIMEOUT seconds of inactivity.Available for:
start, restart, run commandsDirect daemon stdout/stderr to FILE. Useful for debugging daemon crashes.Available for:
start, restart, run commandsShow program’s version number and exit.
Check and recheck flags
Print detailed status.
Write junit.xml to the given file.
Write performance information to the given file.
Store types of all expressions in a shared location (useful for inspections).Default:
falseRe-check FILE, or add it to the set of files being checked. May be repeated.Only available for
recheck command.Remove FILE from the set of files being checked. May be repeated.Only available for
recheck command.Status command flags
Collect information about the current file state and write to FILE as JSON.
Suggest command flags
Produce json that pyannotate can use to apply a suggestion.Default:
falseOnly produce suggestions that cause no errors.Default:
falseOnly produce suggestions that don’t contain Any.Default:
falseAllow anys in types if they go above a certain score (0-1).
Find callsites instead of suggesting a type.Default:
falseA dummy name to use instead of Any for types that can’t be inferred.
Set the maximum number of types to try for a function.Default:
64Inspect command flags
What kind of inspection to run.Choices:
type, attrs, definitionDefault: typeIncrease verbosity of the type string representation. Can be repeated.
Return at most NUM innermost expressions (if position is given). 0 means no limit.Default:
0Prepend each inspection result with the span of corresponding expression.Default:
falsePrepend each inspection result with the kind of corresponding expression.Default:
falseInclude attributes of “object” in “attrs” inspection.Default:
falseInclude attributes valid for some of possible expression types.Default:
false (intersection returned)Re-parse and re-type-check file before inspection (may be slow).Default:
falseExamples
Performance tips
- Use
dmypy run: This automatically handles daemon lifecycle and restarts when needed - Enable
--export-types: Pre-compute types for faster inspections - Use
--update/--remove: With an external file watcher for maximum speed on large codebases - Set
--timeout: Automatically clean up idle daemon processes