CntxtPY
A discovery and compression tool for your Python codebase. Creates a knowledge graph for a LLM context window, efficiently outlining your project | Code structure visualization | LLM Context Window Efficiency | Static analysis for AI | Large Language Model tooling #LLM #AI #Python #CodeAnalysis #ContextWindow #DeveloperTools
Install / Use
/learn @brandondocusen/CntxtPYREADME
🐍 CntxtPY: Minify Your Python Codebase Context for LLMs
🤯 75% Token Reduction In Context Window Usage!
Why CntxtPY?
- Boosts precision: Maps relationships and dependencies for clear analysis.
- Eliminates noise: Focuses LLMs on key code insights.
- Supports analysis: Reveals architecture for smarter LLM insights.
- Speeds solutions: Helps LLMs trace workflows and logic faster.
- Improves recommendations: Gives LLMs detailed metadata for better suggestions.
- Optimized prompts: Provides structured context for better LLM responses.
- Streamlines collaboration: Helps LLMs explain and document code easily.
Supercharge your understanding of Python codebases. CntxtPY generates comprehensive knowledge graphs that help LLMs navigate and comprehend your code structure with minimal token usage.
It's like handing your LLM the cliff notes instead of a novel.
Active Enhancement Notice
- CntxtPY is actively being enhanced at high velocity with improvements every day. Thank you for your contributions! 🙌
✨ Features
- 🔍 Deep analysis of Python codebases
- 📊 Generates detailed knowledge graphs of:
- Module relationships and imports
- Class hierarchies and methods
- Function signatures and type hints
- Package structures
- Circular dependency detection
- Requirements.txt/Poetry/Pipenv dependencies
- Decorators and protocols
- 🎯 Specially designed for LLM context windows
- 📈 Built-in visualization capabilities of your project's knowledge graph
- 🚀 Support for modern Python frameworks and patterns
🚀 Quick Start
# Clone the repository
git clone https://github.com/brandondocusen/CntxtPY.git
# Navigate to the directory
cd CntxtPY-main
# Install required packages
pip install pyyaml configparser toml chardet networkx
# Run the analyzer
python cntxtpy.py
# Find compressed_knowledge_graph.txt in the compression directory
cd compression
# Upload compressed_knowledge_graph.txt to an LLM and discuss your codebase
When prompted, enter the path to your Python codebase. The tool will generate a python_code_knowledge_graph.json file and offer to visualize the relationships.
💡 Example Usage with LLMs
The LLM can now provide detailed insights about your codebase's implementations, understanding the relationships between components, modules, and packages! After generating your knowledge graph, you can upload it as a single file to give LLMs deep context about your codebase. Here's a powerful example prompt:
Based on the knowledge graph, explain how dependency injection is implemented in this application, including which classes use the dependency container and how services are registered.
Based on the knowledge graph, map out the core package structure - starting from __main__.py through to the different modules and their interactions.
Using the knowledge graph, analyze the decorator usage in this application. Which decorators exist, what do they modify, and how do they interact with functions/classes?
From the knowledge graph data, break down this application's API route structure, focusing on endpoints and their implementation patterns.
According to the knowledge graph, identify all error handling patterns in this codebase - where are exceptions caught, how are they processed, and what custom exceptions exist?
Based on the knowledge graph's dependency analysis, outline the key pip/poetry dependencies this project relies on and their primary use cases in the application.
Using the knowledge graph's type hint analysis, explain how the application handles data validation and type checking across different services.
📊 Output Format
The tool generates three main outputs:
- A JSON knowledge graph (
python_code_knowledge_graph.json) - A highly compressed txt knowledge graph (
compressed_knowledge_graph.txt) - Optional visualization using matplotlib
The knowledge graph includes:
- Detailed metadata about your codebase
- Node and edge relationships
- Function signatures and type hints
- Class hierarchies
- Import mappings
- Package structures
🤝 Contributing
We love contributions! Whether it's:
- 🐛 Bug fixes
- ✨ New features
- 📚 Documentation improvements
- 🎨 Visualization enhancements
Just fork, make your changes, and submit a PR. Check out our contribution guidelines for more details.
🎯 Future Goals
- [ ] Deeper support for additional frameworks
- [ ] Interactive web-based visualizations
- [ ] Custom graph export formats
- [ ] Integration with popular IDEs
- [ ] Support for Cython and PyPy
📝 License
MIT License - feel free to use this in your own projects!
🌟 Show Your Support
If you find CntxtPY helpful, give it a star! ⭐️
Made with ❤️ for the LLM and Python communities
Related Skills
claude-opus-4-5-migration
82.5kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
model-usage
335.4kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
TrendRadar
49.7k⭐AI-driven public opinion & trend monitor with multi-platform aggregation, RSS, and smart alerts.🎯 告别信息过载,你的 AI 舆情监控助手与热点筛选工具!聚合多平台热点 + RSS 订阅,支持关键词精准筛选。AI 智能筛选新闻 + AI 翻译 + AI 分析简报直推手机,也支持接入 MCP 架构,赋能 AI 自然语言对话分析、情感洞察与趋势预测等。支持 Docker ,数据本地/云端自持。集成微信/飞书/钉钉/Telegram/邮件/ntfy/bark/slack 等渠道智能推送。
mcp-for-beginners
15.6kThis open-source curriculum introduces the fundamentals of Model Context Protocol (MCP) through real-world, cross-language examples in .NET, Java, TypeScript, JavaScript, Rust and Python. Designed for developers, it focuses on practical techniques for building modular, scalable, and secure AI workflows from session setup to service orchestration.
