Skip to content

CLI usage

The codeanalyzer command runs static analysis on a Python project and emits a PyApplication artifact. This guide walks through the common invocations; for the full flag table see the CLI reference.

The only required flag is --input (-i), the project root:

Terminal window
codeanalyzer --input ./my-python-project

With no --output, the analysis is printed to stdout as compact JSON. Add --output (-o) to write it to a file instead:

Terminal window
codeanalyzer --input ./my-python-project --output ./out
# -> ./out/analysis.json

The default format is JSON. Pass --format msgpack (-f) for a gzip-compressed MessagePack artifact — smaller and faster to load for large projects:

Terminal window
codeanalyzer --input ./my-python-project --output ./out --format msgpack
# -> ./out/analysis.msgpack

The CLI logs the compression ratio relative to JSON when it writes msgpack. The schema is identical across formats; only the serialization differs.

By default the call graph comes from Jedi’s lexical analysis. Add --codeql to resolve additional edges — including RPC, third-party, and dynamically-dispatched targets — and merge them with the Jedi edges. CodeQL also backfills resolved callees on Jedi call sites it couldn’t resolve.

Terminal window
codeanalyzer --input ./my-python-project --codeql

Analysis is lazy by default: codeanalyzer caches results under .codeanalyzer/ and reuses the entries for files that haven’t changed (detected by mtime, size, and content hash). Pass --eager to rebuild everything from scratch:

Terminal window
# Lazy (default) — reuse unchanged files from cache
codeanalyzer --input ./my-python-project
# Eager — rebuild the analysis and the virtual environment
codeanalyzer --input ./my-python-project --eager

Control where the cache lives with --cache-dir (-c). If unset, it defaults to .codeanalyzer in the input project directory:

Terminal window
codeanalyzer --input ./my-python-project --cache-dir /tmp/ca-cache
# -> /tmp/ca-cache/.codeanalyzer

By default the cache is kept after a run. Pass --clear-cache to delete it on exit (useful in CI):

Terminal window
codeanalyzer --input ./my-python-project --clear-cache

To analyze one file rather than the whole project, pass --file-name relative to --input:

Terminal window
codeanalyzer --input ./my-python-project --file-name src/app/routes.py

The path must exist under --input and end in .py.

Test files are skipped by default — any file under a test/tests directory, or named test_*.py / *_test.py. Include them with --include-tests:

Terminal window
codeanalyzer --input ./my-python-project --include-tests

For large projects, --ray distributes symbol-table construction across workers:

Terminal window
codeanalyzer --input ./large-project --ray

The tool is quiet by default. Stack -v for progressively more logging:

Terminal window
codeanalyzer --input ./my-python-project -v # info
codeanalyzer --input ./my-python-project -vv # debug
codeanalyzer --input ./my-python-project -vvv # trace

A typical CI invocation — eager rebuild, CodeQL on, msgpack out, cache discarded:

Terminal window
codeanalyzer \
--input ./my-python-project \
--output ./artifacts \
--format msgpack \
--codeql \
--eager \
--clear-cache \
-v