Skip to main content

Local Python code analysis tool - understand architecture, dependencies, and call graphs

Project description

CodeMap

CodeMap is a pure local developer tool that analyzes Python codebases and provides:

  • ๐Ÿ“Š Architecture Analysis - Understand code structure, dependencies, and call graphs
  • ๐Ÿฆบ Call Graph Extraction - Trace function/method calls across your codebase
  • โš ๏ธ Risk Analysis - Identify complex code patterns and potential issues
  • ๐Ÿ“ˆ Symbol Indexing - Search and explore functions, classes, and methods
  • ๐ŸŒ Local Web Dashboard - Visual code analysis interface
  • ๐Ÿ” Privacy First - All analysis runs locally, no data leaves your machine

Requirements

  • Python 3.10+
  • pip (Python package manager)
  • ~5 minutes to get started

Quick Start (3 Steps)

Step 1๏ธโƒฃ: Install CodeMap

# Install from PyPI (easiest)
pip install codemap-python

Verify installation:

codemap --help

You should see:

usage: codemap [-h] {analyze,dashboard,open,cache} ...

For developers: To modify source code or contribute, clone the repository:

git clone https://github.com/ADITYA-kus/codemap_ai.git
cd codemap_ai
pip install -e .

Step 2๏ธโƒฃ: Analyze Your First Repository

IMPORTANT: The analyze command REQUIRES the --path argument pointing to a directory!

# Analyze the demo repo (takes 5-10 seconds)
codemap analyze --path demo_repo

Output: JSON analysis data

{
  "ok": true,
  "cache_dir": ".codemap_cache/...",
  "analysis_version": "2.2",
  "repo_dir": "demo_repo"
}

Analyze your own Python project:

codemap analyze --path /path/to/your/python/project

Analyze a GitHub repository:

codemap analyze --github https://github.com/owner/repo

Step 3๏ธโƒฃ: View in Web Dashboard

# Start the web dashboard
codemap dashboard --port 8000

Open in browser:

http://127.0.0.1:8000

You'll see:

  • List of analyzed repositories
  • Call graphs
  • Architecture metrics
  • Risk analysis
  • Symbol search

Common Commands

Analyze Commands

# โš ๏ธ REQUIRED: Analyze needs --path argument!

# Analyze a local repository
codemap analyze --path <repo_directory>

# Analyze a GitHub repository (public)
codemap analyze --github https://github.com/owner/repo

# Analyze private GitHub repo (requires token)
codemap analyze --github https://github.com/owner/private-repo --token YOUR_GITHUB_TOKEN

# Force rebuild analysis (ignore cache)
codemap analyze --path <repo_directory> --rebuild

# Use API for detailed JSON output
codemap api analyze --path <repo_directory>

Dashboard Commands

# Start web dashboard (default: localhost:8000)
codemap dashboard --port 8000

# Start dashboard with auto-reload (development)
codemap dashboard --port 8000 --reload

# Open dashboard in browser
codemap open --port 8000

Cache Management

# ๐Ÿ“‹ List all analyzed repositories and their cache info
codemap cache list

# ๐Ÿ“Š Show detailed cache information for a specific repository
codemap cache info --path <repo_directory>

# โฑ๏ธ Set cache retention policy (automatically clean old caches)
codemap cache retention --path <repo_directory> --days 30 --yes

# ๐Ÿงน Preview what would be cleaned (safe, no deletion)
codemap cache sweep --dry-run

# ๐Ÿงน Actually clean up expired caches (requires --yes confirmation)
codemap cache sweep --yes

# ๐Ÿ—‘๏ธ Clear cache for a specific repository (preview first)
codemap cache clear --path <repo_directory> --dry-run

# ๐Ÿ—‘๏ธ Actually delete a repository's cache (requires --yes confirmation)
codemap cache clear --path <repo_directory> --yes

Cache Management Tips:

  • โœ… Always use --dry-run first to preview changes
  • โœ… Add --yes flag to skip confirmation (useful in scripts)
  • โœ… Default retention is 14 days; adjust with --days <number>
  • โœ… Cache is stored in: ~/.codemap_cache/ (varies by OS)
  • โœ… Use cache list to see all cached repositories and their sizes

Get GitHub Token (for private repos):

  1. Go to https://github.com/settings/tokens
  2. Click "Generate new token" โ†’ "Generate new token (classic)"
  3. Give it a name (e.g., "CodeMap")
  4. Select repo scope (full control of private repos)
  5. Copy the token and save it somewhere safe
  6. Use in commands: --token ghp_xxxxx

Or pass token via stdin (more secure):

echo "YOUR_TOKEN" | codemap analyze --github https://github.com/owner/repo --token-stdin

Directory Structure

This is the source code structure for developers. If you installed via pip, these files are automatically installed in your Python environment.

codemap_ai/  (source code)
โ”œโ”€โ”€ README.md              # This file
โ”œโ”€โ”€ cli.py                 # Command-line interface
โ”œโ”€โ”€ security_utils.py      # Security & secret redaction
โ”œโ”€โ”€ pyproject.toml         # Package configuration
โ”œโ”€โ”€ analysis/              # Code analysis engine
โ”‚   โ”œโ”€โ”€ core/             # AST parsing, imports
โ”‚   โ”œโ”€โ”€ call_graph/       # Call graph building
โ”‚   โ”œโ”€โ”€ explain/          # Symbol metadata
โ”‚   โ”œโ”€โ”€ architecture/     # Dependency analysis
โ”‚   โ””โ”€โ”€ graph/            # Graph indexing
โ”œโ”€โ”€ ui/                    # Web dashboard
โ”‚   โ”œโ”€โ”€ app.py            # FastAPI server
โ”‚   โ”œโ”€โ”€ templates/        # HTML templates
โ”‚   โ””โ”€โ”€ static/           # CSS, JavaScript
โ”œโ”€โ”€ tests/                 # Test suite
โ””โ”€โ”€ demo_repo/            # Example repository

Features Explained

๐Ÿ” Symbol Search

Find all functions, classes, and methods in your codebase:

codemap api search --path <repo_path> --query "MyClass"
codemap api search --path <repo_path> --query "function_name"

๐Ÿ“Š Call Graph

Understand how functions call each other:

codemap api explain --path <repo_path> --symbol "module.ClassName.method"

โš ๏ธ Risk Radar

Detect complex code patterns and potential issues:

codemap api risk_radar --path <repo_path>

๐Ÿ“ˆ Impact Analysis

See which files/functions are affected by changes:

codemap api impact --path <repo_path> --target "module.function"

Privacy & Security

โœ… 100% Local

  • All analysis happens on your machine
  • No data sent to external servers
  • .env files and secrets are never exposed

โœ… Secure Cache

  • Analysis results cached locally
  • Cache auto-cleared after 14 days (configurable)
  • No credentials stored

โœ… Secret Redaction

  • API keys automatically masked in output
  • GitHub tokens never logged
  • Safe error messages

Example Workflow

Local Project Analysis

# 1. Navigate to your Python project
cd C:\Users\YourName\my_python_project

# 2. Analyze it with CodeMap
codemap analyze --path .
# โœ… Analysis complete! Results cached locally

# 3. Start the web dashboard
codemap dashboard --port 8000
# โœ… Dashboard running at http://127.0.0.1:8000

# 4. Open in browser
codemap open --port 8000

# 5. Explore in browser:
#    - View all repositories
#    - See call graphs
#    - Check architecture metrics
#    - View risk analysis

# 6. Search for a specific class
codemap api search --path . --query "MyClass"

# 7. Check call graph for a function
codemap api explain --path . --symbol "mymodule.MyClass.method"

GitHub Repository Analysis

# 1. Analyze a public GitHub repo
codemap analyze --github https://github.com/owner/awesome-project
# โœ… Downloaded and analyzed

# 2. View in dashboard
codemap dashboard --port 8000
codemap open --port 8000

# 3. Clean up old repos
codemap cache list      # See all cached repos
codemap cache sweep    # Auto-cleanup old ones

Next Steps

  1. ๐ŸŽฏ First analysis - Try the demo:

    codemap analyze --path demo_repo
    
  2. ๐Ÿ“Š View results - Open the dashboard:

    codemap dashboard --port 8000
    
  3. ๐Ÿ“ Analyze your code - Point to your project:

    codemap analyze --path ~/my-project
    
  4. ๐Ÿ”— Try GitHub - Analyze public repos:

    codemap analyze --github https://github.com/owner/repo
    
  5. ๐Ÿš€ Advanced features - Explore search, impact, risk analysis:

    codemap api search --path . --query "YourClass"
    

Quick Reference

# Installation
pip install -e .

# Most common commands
codemap analyze --path <directory>              # Analyze local repo
codemap analyze --github <url>                  # Analyze GitHub repo
codemap dashboard --port 8000                   # Start dashboard
codemap open --port 8000                        # Open in browser
codemap cache list                              # List all analyses
codemap cache clear <hash>                      # Delete one analysis

Support & Help

โœ… Run without arguments to see all available commands:

codemap --help
codemap analyze --help
codemap dashboard --help
codemap api --help

โœ… Check requirements:

python --version          # Should be 3.10+
pip --version             # Should be installed
git --version             # For GitHub repos

โœ… Verify repo path:

# Make sure your repo has Python files
dir <your_repo>                 # Windows
ls <your_repo>                  # Linux/Mac
find <your_repo> -name "*.py"   # Find Python files

Happy coding! ๐Ÿš€


GitHub: https://github.com/ADITYA-kus/codemap_ai

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

codemap_python-0.1.6.tar.gz (123.7 kB view details)

Uploaded Source

Built Distribution

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

codemap_python-0.1.6-py3-none-any.whl (126.3 kB view details)

Uploaded Python 3

File details

Details for the file codemap_python-0.1.6.tar.gz.

File metadata

  • Download URL: codemap_python-0.1.6.tar.gz
  • Upload date:
  • Size: 123.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for codemap_python-0.1.6.tar.gz
Algorithm Hash digest
SHA256 523c067f6d9070acba6f01d86ad26f08837d5d74819fbc528cac0cff11d65987
MD5 97356e66e4792f1e58c25ed47a99fe59
BLAKE2b-256 52052e0686e1f675d5336807ab489526cfdb82e04f5f141c1958eb673dd47fe5

See more details on using hashes here.

File details

Details for the file codemap_python-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: codemap_python-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 126.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for codemap_python-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2a7edb4a725da8f23c3dc046e30b816eeda334f94fffc4247afcfbcd1034ec8a
MD5 5fcc9aec2e6d116ee672fe9634ba5be4
BLAKE2b-256 2b3fe3f84dfe591cdba34fe044b28d3af7a3d007e985fa731c3eeaec410ef176

See more details on using hashes here.

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