Python API
The root exports below are the package's external Python surface. Rule implementation modules, formatters, tools and the witness are separately importable but are not re-exported at the root.
The monorepo build already generates per-module pages under
reference/axm_audit/. This curated page renders in both standalone and
monorepo builds and makes the entry points discoverable in navigation.
Audit entry points
audit_project(project_path, category=None, quick=False, framework=None)
Audit a project against its ecosystem's 2026 standards.
Rules execute in parallel via ThreadPoolExecutor for speed.
Each rule is isolated — one failure does not prevent others.
An ASTCache is shared across rules to avoid redundant parsing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
Path
|
Root directory of the project to audit. |
required |
category
|
str | None
|
Optional category filter. |
None
|
quick
|
bool
|
If True, run only lint + type checks. |
False
|
framework
|
Framework | str | None
|
Ecosystem to audit against. |
None
|
Returns:
| Type | Description |
|---|---|
AuditResult
|
AuditResult containing all check results. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If project_path does not exist. |
Source code in packages/axm-audit/src/axm_audit/core/auditor.py
get_rules_for_category(category, quick=False, framework=Framework.PYTHON)
Get rules for a specific category or all rules, scoped to framework.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
str | None
|
Filter to specific category, or None for all. |
required |
quick
|
bool
|
If True, only lint + type checks. |
False
|
framework
|
Framework
|
Ecosystem whose rules to return (default |
PYTHON
|
Returns:
| Type | Description |
|---|---|
list[ProjectRule]
|
List of rule instances to run. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If category is not valid. |
Source code in packages/axm-audit/src/axm_audit/core/auditor.py
Result models
AuditResult
Bases: BaseModel
Aggregated result of a project audit.
Contains all individual check results and computed summary.
quality_score and grade may be passed explicitly (e.g. in
tests); otherwise they are computed from checks automatically.
Source code in packages/axm-audit/src/axm_audit/models/results.py
| Python | |
|---|---|
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
crashed_rules
property
rule_ids whose check raised, in encounter order.
Crashed rules contribute score=0 to their scored category (they
are never silently dropped); this field makes a degraded audit
traceable rather than silent.
failed
property
Number of failed checks.
grade
property
Letter grade derived from quality_score.
A >= 90, B >= 80, C >= 70, D >= 60, F < 60. Returns None if quality_score is None.
quality_score
property
Weighted average across 9 code-quality categories.
Categories and weights
Linting (15%), Type Safety (15%), Complexity (15%), Testing (10%), Test Quality (10%), Security (10%), Dependencies (10%), Architecture (10%), Practices (5%).
Structure and tooling emit findings but are NOT scored (structure is handled by axm-init; tooling is informational). Returns None if no scored checks are present.
success
property
True if all checks passed.
total
property
Total number of checks.
CheckResult
Bases: BaseModel
Result of a single compliance check.
Designed for machine parsing by AI Agents.
Source code in packages/axm-audit/src/axm_audit/models/results.py
Severity
Bases: StrEnum
Severity level for check results.
Source code in packages/axm-audit/src/axm_audit/models/results.py
axm_audit.__version__ is a string supplied by the build's VCS version hook.
Formatters and exceptions
formatters
Output formatters for audit results — human-readable and JSON.
format_report(result)
Format audit result as human-readable category-grouped report.
Source code in packages/axm-audit/src/axm_audit/formatters.py
format_json(result)
Format audit result as JSON-serializable dict.
The score/grade pair is resolved through the single serialization
source (:func:axm_audit.score.resolve_score_grade): the payload always
carries a numeric score, and when a score cannot be computed at all it
raises :class:axm_audit.score.ScoreIncalculableError rather than emit a
success payload without a score key.
Source code in packages/axm-audit/src/axm_audit/formatters.py
format_agent(result)
Agent-optimized output: passed=summary, failed=full detail.
Minimizes tokens for passing checks while giving full context on
failures. For failed checks, text and details are both included
when present (None values are omitted). Passed checks that
carry actionable detail (e.g. missing docstrings) are promoted to dicts.
Rule-specific metadata (e.g. tautology verdicts, duplicate clusters,
pyramid mismatches) is propagated verbatim under the metadata key
on both passed and failed entries when non-empty.
Score/grade derive from the single serialization source
(:func:axm_audit.score.score_grade_or_none); this lax surface tolerates
an incalculable score as None rather than failing loud.
Source code in packages/axm-audit/src/axm_audit/formatters.py
format_agent_text(data, category=None)
Render agent-format audit data as compact text for LLM consumption.
Consumes the dict produced by format_agent and returns a minimal
text representation optimised for token count.
Source code in packages/axm-audit/src/axm_audit/formatters.py
format_test_quality_text(result, mismatches_only=False)
Render test-quality findings grouped by rule.
Order: private imports → pyramid → duplicates → tautologies.
With mismatches_only=True only the pyramid section is emitted,
filtered to entries whose folder differs from the classified level.
Source code in packages/axm-audit/src/axm_audit/formatters.py
format_test_quality_json(result)
JSON superset: clusters + verdicts + pyramid + private violations.
Source code in packages/axm-audit/src/axm_audit/formatters.py
ScoreIncalculableError
Bases: RuntimeError
Raised when an audit yields no measurable scored signal (N/A).
Covers both an audit with no scored-category check at all and one whose
scored-category checks are every one not-applicable (score=None).
Signals that a success payload without a score must NOT be emitted; the
strict callers (audit --json) fail loud instead of dropping the key
silently or reporting a misleading 0/F.
Source code in packages/axm-audit/src/axm_audit/score.py
Tool implementations
execute(*, path='.', category=None, **kwargs)
Audit a Python project's code quality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to project root. |
'.'
|
category
|
str | None
|
Optional category filter. One of: |
None
|
Returns:
| Type | Description |
|---|---|
ToolResult
|
ToolResult with audit scores and details ( |
ToolResult
|
and a compact |
Source code in packages/axm-audit/src/axm_audit/tools/audit.py
execute(*, path='.', mode='failures', files=None, markers=None, stop_on_first=True, include_cases=False, **kwargs)
Run tests with structured output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to project root. |
'.'
|
mode
|
str
|
|
'failures'
|
files
|
list[str] | None
|
Specific test files to run. |
None
|
markers
|
list[str] | None
|
Pytest markers to filter. |
None
|
stop_on_first
|
bool
|
Stop on first failure. |
True
|
include_cases
|
bool
|
Include lossless per-item pytest verdicts. |
False
|
Returns:
| Type | Description |
|---|---|
ToolResult
|
ToolResult with structured test report. |
Source code in packages/axm-audit/src/axm_audit/tools/audit_test.py
execute(*, path='.', apply=False, rules=None, **kwargs)
Run the fix pipeline on a project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to project root. |
'.'
|
apply
|
bool
|
If True, mutate the tree; otherwise dry-run. |
False
|
rules
|
list[str] | None
|
Optional list of rule ids to filter the pipeline. |
None
|
Returns:
| Type | Description |
|---|---|
ToolResult
|
ToolResult with a JSON-serializable |
ToolResult
|
human-readable |
Source code in packages/axm-audit/src/axm_audit/tools/audit_fix.py
execute(*, path='.', timeout=_DEFAULT_TIMEOUT, **kwargs)
Run the documentation gate on the target package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the package root holding |
'.'
|
timeout
|
int
|
Hard wall-clock bound (seconds) for the mkdocs subprocess. |
_DEFAULT_TIMEOUT
|
Returns:
| Type | Description |
|---|---|
ToolResult
|
ToolResult with structured findings ( |
ToolResult
|
( |
ToolResult
|
mkdocs is absent, times out, or the build fails without findings. |
Source code in packages/axm-audit/src/axm_audit/doc_gate/tool.py
Witness
AuditQualityRule
dataclass
Run audit checks and return structured feedback.
Attributes:
| Name | Type | Description |
|---|---|---|
categories |
list[str]
|
Audit categories to run (default: lint + type). |
working_dir |
str
|
Project root to audit. |
guidance |
str | None
|
Optional extra guidance appended on failure. |
Source code in packages/axm-audit/src/axm_audit/witnesses/audit_quality.py
| Python | |
|---|---|
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
validate(content, **kwargs)
Run audit categories and aggregate results.
Each category runs independently — failures in one do not prevent execution of the others.
Source code in packages/axm-audit/src/axm_audit/witnesses/audit_quality.py
For exact transport behavior, parameter tables and known limits, use the CLI/tools reference, results guide and framework reference. Source docstrings can lag the runtime; the narrative describes the checked behavior.