Skip to main content

AI-powered code review engine for pull requests

Project description

🔍 Inspectra

AI-powered code review engine for pull requests.

CI PyPI version Python License: MIT Code style: ruff

Inspectra reviews your git diffs using LLMs — locally via Ollama (free, private) or via OpenAI / Anthropic — and posts structured, actionable feedback directly on your GitHub PR.

$ inspectra review --provider ollama

Found 3 reviewable files.

🔴 [CRITICAL] SQL Injection
  File: auth/service.py — Line 42
  User input is directly concatenated into the SQL query.
  Suggested fix: Use parameterised queries instead of string interpolation.

🟠 [HIGH] Missing Error Handling
  File: api/client.py — Line 88
  Network request does not handle timeout or connection failures.
  Suggested fix: Wrap in try/except and add retry logic.

Features

  • Reviews only changed code — parses the git diff, never sends your whole repo
  • Multi-provider — Ollama (local/free), OpenAI, Anthropic; all behind one interface
  • Structured findings — every issue has severity, category, explanation, and a fix
  • GitHub integration — posts PR comments, submits reviews (approve / request changes)
  • SARIF export — compatible with GitHub Code Scanning
  • Response caching — skip re-reviewing unchanged hunks (--cache)
  • Token-safe chunking — large diffs are split at hunk boundaries
  • GitHub Actions ready — self-hosted (Ollama) and cloud (OpenAI) workflows included

Quick Start

Install

pip install inspectra

Review with Ollama (free, local)

# Install and start Ollama
curl -fsSL https://ollama.com/install.sh | sh
ollama serve
ollama pull qwen2.5-coder:14b

# Review your uncommitted changes
inspectra review

Review with OpenAI

export OPENAI_API_KEY=sk-...
inspectra review --provider openai --model gpt-4o-mini

Review a GitHub PR

export GITHUB_TOKEN=ghp_...
export GITHUB_REPOSITORY=myorg/myrepo

inspectra review --pr 42 --post-comment

Generate config file

inspectra init     # creates .inspectra.yml in the current directory

CLI Reference

Commands:
  review        Review the current git diff or a GitHub PR
  init          Create a default .inspectra.yml
  models        List available Ollama models
  cache-clear   Clear the local LLM response cache
  version       Show version

review options:
  -p, --provider          ollama | openai | anthropic  [default: ollama]
  -m, --model             Model name
  -c, --config            Path to .inspectra.yml
  -o, --output            Write Markdown report to file
      --sarif             Write SARIF report (for GitHub Code Scanning)
      --pr                GitHub PR number
      --post-comment      Post review as a GitHub PR comment
      --pr-summary        Generate AI PR-level summary  [default: on]
      --staged            Review staged changes only
      --cache             Cache LLM responses to .inspectra_cache/
      --dry-run           Parse diff without calling the LLM
      --fail-on-high      Exit 1 when critical/high issues found  [default: on]
  -v, --verbose           Enable verbose logging

GitHub Actions

Option A — Ollama on a Self-Hosted Runner (Recommended)

Free, private — your code never leaves your network.

# .github/workflows/inspectra.yml
name: Inspectra Review

on:
  pull_request:

jobs:
  inspectra:
    runs-on: self-hosted   # your machine with Ollama installed

    permissions:
      pull-requests: write
      contents: read

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - run: pip install inspectra

      - run: ollama serve & sleep 3

      - run: |
          inspectra review \
            --provider ollama \
            --model qwen2.5-coder:14b \
            --post-comment \
            --pr ${{ github.event.pull_request.number }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_REPOSITORY: ${{ github.repository }}

Self-hosted runner setup: Repo/Org → Settings → Actions → Runners → New runner. Follow the install script, then run ./svc.sh install && ./svc.sh start to keep it alive across reboots.

Option B — OpenAI on GitHub-Hosted Runner

      - run: |
          inspectra review \
            --provider openai \
            --model gpt-4o-mini \
            --post-comment \
            --pr ${{ github.event.pull_request.number }}
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_REPOSITORY: ${{ github.repository }}

SARIF + GitHub Code Scanning

      - run: inspectra review --sarif inspectra.sarif

      - uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: inspectra.sarif

Configuration

Create .inspectra.yml in your repository root (or run inspectra init):

provider: ollama
model: qwen2.5-coder:14b

ollama:
  host: http://localhost:11434
  timeout: 300

review:
  security: true
  bugs: true
  performance: true
  maintainability: true
  architecture: true
  concurrency: true
  scalability: true

exclude:
  - "*.lock"
  - "dist/*"
  - "*.min.js"
  - "vendor/*"

max_tokens: 12000
max_chunk_tokens: 3000
temperature: 0.2

Environment Variables

Variable Description
OPENAI_API_KEY OpenAI API key
ANTHROPIC_API_KEY Anthropic API key
GITHUB_TOKEN GitHub token for PR comments
GITHUB_REPOSITORY Repository in owner/repo format
PR_NUMBER PR number (alternative to --pr)

Copy .env.example to .env and fill in your values — it is gitignored.


Recommended Ollama Models

Model RAM needed Best for
qwen2.5-coder:7b 8 GB Fast, lightweight CI
qwen2.5-coder:14b 16 GB Default — best balance
deepseek-coder:16b 20 GB Deeper analysis
qwen2.5-coder:32b 40 GB Enterprise-grade reviews

Development

git clone https://github.com/iamakashsoni/inspectra
cd inspectra
pip install -e ".[dev]"

make test        # run tests
make lint        # lint
make check       # lint + types + tests
make review      # dry-run review of the repo itself

See CONTRIBUTING.md for full contribution guide.


Architecture

git diff
  └─► diff parser (unidiff)
        └─► file filter (skip locks, minified, binary)
              └─► token chunker (hunk-level splitting)
                    └─► LLM provider (Ollama / OpenAI / Anthropic)
                          └─► response parser → ReviewResult[]
                                └─► output (console / Markdown / SARIF / PR comment)

See docs/architecture.md for the full diagram.


License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inspectra-0.1.1.tar.gz (40.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inspectra-0.1.1-py3-none-any.whl (38.8 kB view details)

Uploaded Python 3

File details

Details for the file inspectra-0.1.1.tar.gz.

File metadata

  • Download URL: inspectra-0.1.1.tar.gz
  • Upload date:
  • Size: 40.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for inspectra-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d7b96e3b8fa407fd6ae71a9737474091fe46cd28827e025cfd66b992b944272b
MD5 f045b891f6e933c1f990aa2b01c105d6
BLAKE2b-256 dc5517528bf7abb6c61efb5896eb75c90ea71d17f701115a7ff2e69f7344b9b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for inspectra-0.1.1.tar.gz:

Publisher: publish.yml on iamakashsoni/inspectra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file inspectra-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: inspectra-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 38.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for inspectra-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3275317a45aa57634c662a3793cedd0536f4a15c762b9ae99522d166b3117554
MD5 e3f63cdb6877cef111c70946f955d783
BLAKE2b-256 a5f711b04b8fd97295bff1258e2bb8565a9384cdc911262fb9a34cb8781df58e

See more details on using hashes here.

Provenance

The following attestation bundles were made for inspectra-0.1.1-py3-none-any.whl:

Publisher: publish.yml on iamakashsoni/inspectra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page