CodexDoctor
CodexDoctor is a lightweight, dependency-free command-line tool and Python API for static diagnostics of Python projects. It checks source syntax, likely missing imports, selected risky APIs, and a few project-structure conventions.
CodexDoctor is an early static-analysis tool, not a replacement for a test suite, type checker, linter, dependency scanner, or professional security audit. Its security and import checks are heuristic and can produce false positives or miss issues.
Features
- Scans Python source without importing or executing project code.
- Reports syntax errors with file and line information.
- Checks likely missing imports against the active interpreter and a conservative local-module index, including common
src/layouts and relative imports. - Recognizes imports guarded by
try/except ImportErroras optional. - Flags selected risky patterns:
eval,exec, unsafe pickle/dill deserialization, potentially unsafeyaml.load, shell-enabled subprocess calls,os.system/os.popen, andtempfile.mktemp. - Reports missing README, tests, or packaging metadata as informational findings.
- Supports readable terminal output and JSON output for CI pipelines.
- Skips common generated and environment directories and symbolic links by default; supports explicit exclusions, hidden-file inclusion, and a maximum source-file size.
- Does not modify scanned source files. The CLI writes a report only when
--outputis explicitly supplied.
Requirements
- Python 3.10 or newer.
- No runtime third-party dependencies.
Install from source
python -m pip install .
For development:
python -m pip install -e ".[dev]"
python -m pytest
Command-line usage
Scan the current directory:
codexdoctor scan .
Scan another project:
codexdoctor scan path/to/project
Get JSON output:
codexdoctor scan . --format json
Save a report (the destination file is created or replaced):
codexdoctor scan . --format json --output codexdoctor-report.json
Exclude directories, increase the file-size limit to 5 MiB, or disable selected checks:
codexdoctor scan . --exclude-dir examples --exclude-dir generated --max-file-size 5
codexdoctor scan . --no-import-check --no-security-check
Control the process exit code for CI. The default only fails on errors:
codexdoctor scan . --fail-on warning
codexdoctor scan . --fail-on never
You can also use the module form:
python -m codexdoctor scan .
Python API
from codexdoctor import ScanOptions, scan
options = ScanOptions(
exclude_dirs=("examples", "generated"),
max_file_size=3 * 1024 * 1024,
)
report = scan(".", options=options)
print(report.summary())
for finding in report.findings:
print(finding.severity, finding.code, finding.path, finding.line)
For a quick scan with defaults:
from codexdoctor import scan
report = scan(".")
The API returns a ScanReport; it does not write files or execute the project.
Diagnostic codes
| Code | Meaning |
|---|---|
PY_SYNTAX |
Python source could not be parsed. |
IMPORT_NOT_FOUND |
An import could not be located in the active environment or project index. |
SEC_EVAL / SEC_EXEC |
Dynamic evaluation or execution call detected. |
SEC_UNSAFE_DESERIALIZATION |
Pickle/dill load operation detected. |
SEC_UNSAFE_YAML |
yaml.load detected without a recognized safe loader. |
SEC_SUBPROCESS_SHELL |
A supported subprocess function uses shell=True. |
SEC_OS_SHELL |
os.system or os.popen detected. |
SEC_TEMPFILE_MKTEMP |
Race-prone tempfile.mktemp detected. |
PROJECT_NO_README |
No common README file at the project root. |
PROJECT_NO_TESTS |
No conventional tests directory or test filename found. |
PROJECT_NO_PACKAGING |
No common Python packaging configuration found. |
FILE_ENCODING |
Source encoding could not be detected/decoded. |
FILE_READ_ERROR |
Source could not be read. |
FILE_TOO_LARGE |
Source skipped because it exceeded the configured size limit. |
Scope and limitations
- Import resolution is static and deliberately conservative. Dynamic imports, plugin systems, generated modules, editable installs, namespace packages, platform-specific dependencies, and some complex monorepos may not be fully understood.
- Import availability is checked in the Python environment running CodexDoctor, which may differ from the project's target environment.
- Optional imports inside a recognized
try/except ImportErrorare skipped. Other optional-import conventions may still be reported. - Security checks detect selected AST patterns. They do not prove that a project is safe or vulnerable; aliases, wrappers, dynamic execution, data flow, and custom APIs can evade or confuse these heuristics.
- Syntax parsing uses the Python version running CodexDoctor. Code targeting a different Python version may produce different results.
- The scanner does not install packages, run tests, format code, or change source files. Hidden files can be included explicitly, but hard-excluded cache/repository folders (such as
.git,.venv, and__pycache__) remain skipped.
Development
python -m pip install -e ".[dev]"
python -m pytest
python -m build
python -m twine check dist/*
See CONTRIBUTING.md for contribution guidance, SECURITY.md for reporting security concerns, and PUBLISHING.md for the release process.
License
MIT. See LICENSE.
Metadata
Release files for codexdoctor 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| codexdoctor-0.2.0.tar.gz | 26.1 kB | Without provenance | Details for codexdoctor-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| codexdoctor-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for codexdoctor-0.2.0-py3-none-any.whl |
Total release size: 44.8 kB
Release files / codexdoctor-0.2.0.tar.gz
| Download URL | codexdoctor-0.2.0.tar.gz |
|---|---|
| Size | 26.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
51975184a6493d5ab2ede3dc678dabf01983beb17a16c7786645e76d58bcaeb1
|
|
BLAKE2b-256 checksum How to use checksums |
d7141c6cd29712a5504005f3bc979ff0ec2c39fa6898373a52e28d55df9c37f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Release files / codexdoctor-0.2.0-py3-none-any.whl
| Download URL | codexdoctor-0.2.0-py3-none-any.whl |
|---|---|
| Size | 18.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
507edd744cd4ac8021042034d6473b25f4e77884d906e531e11f5aec3911301b
|
|
BLAKE2b-256 checksum How to use checksums |
340305112afa1f30ca9e47278fe0f4cda3e356bd49188baf3b3f04892aa58244
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Security for codexdoctor 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.