contextly 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,60 @@
1
+ """
2
+ Parser for Python source code files.
3
+ """
4
+
5
+ import ast
6
+ from pathlib import Path
7
+ from typing import Dict, Any, List
8
+ from .base import BaseParser, ChunkMetadata
9
+
10
+ class PythonParser(BaseParser):
11
+ """Parser for Python source code using AST."""
12
+
13
+ def __init__(self):
14
+ super().__init__()
15
+ self.supported_extensions = ['.py']
16
+
17
+ def parse(self, file_path: Path) -> Dict[str, Any]:
18
+ """Parse Python file and extract structure and symbols."""
19
+ with open(file_path, 'r') as f:
20
+ content = f.read()
21
+
22
+ try:
23
+ tree = ast.parse(content)
24
+ except SyntaxError as e:
25
+ return {
26
+ 'error': f'Syntax error in {file_path}: {str(e)}',
27
+ 'content': content,
28
+ 'chunks': []
29
+ }
30
+
31
+ chunks: List[Dict[str, Any]] = []
32
+ symbols: List[str] = []
33
+
34
+ # Extract classes and functions
35
+ for node in ast.walk(tree):
36
+ if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
37
+ chunks.append({
38
+ 'type': 'function',
39
+ 'name': node.name,
40
+ 'start_line': node.lineno,
41
+ 'end_line': node.end_lineno or node.lineno,
42
+ 'content': ast.get_source_segment(content, node),
43
+ })
44
+ symbols.append(node.name)
45
+ elif isinstance(node, ast.ClassDef):
46
+ chunks.append({
47
+ 'type': 'class',
48
+ 'name': node.name,
49
+ 'start_line': node.lineno,
50
+ 'end_line': node.end_lineno or node.lineno,
51
+ 'content': ast.get_source_segment(content, node),
52
+ })
53
+ symbols.append(node.name)
54
+
55
+ return {
56
+ 'file_type': 'python',
57
+ 'content': content,
58
+ 'chunks': chunks,
59
+ 'symbols': symbols
60
+ }
@@ -0,0 +1,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: contextly
3
+ Version: 0.1.0
4
+ Summary: AI Context Engine for Developers
5
+ Project-URL: Homepage, https://github.com/contextly/contextly
6
+ Project-URL: Repository, https://github.com/contextly/contextly
7
+ Project-URL: Documentation, https://github.com/contextly/contextly#readme
8
+ Project-URL: Bug Tracker, https://github.com/contextly/contextly/issues
9
+ Author-email: Contextly Team <team@contextly.dev>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: ai,analysis,code,context,development,documentation,llm
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Topic :: Software Development :: Documentation
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.9
24
+ Requires-Dist: aiohttp>=3.8.0
25
+ Requires-Dist: aiosqlite>=0.19.0
26
+ Requires-Dist: asyncio>=3.4.3
27
+ Requires-Dist: cachetools>=5.3.2
28
+ Requires-Dist: chromadb>=0.4.0
29
+ Requires-Dist: colorama>=0.4.6
30
+ Requires-Dist: huggingface-hub>=0.19.0
31
+ Requires-Dist: openai>=1.0.0
32
+ Requires-Dist: pydantic>=2.0.0
33
+ Requires-Dist: python-dotenv>=1.0.0
34
+ Requires-Dist: pyyaml>=6.0.0
35
+ Requires-Dist: requests>=2.31.0
36
+ Requires-Dist: rich>=13.0.0
37
+ Requires-Dist: sentence-transformers>=2.2.0
38
+ Requires-Dist: tiktoken>=0.5.1
39
+ Requires-Dist: tokenizers>=0.15.0
40
+ Requires-Dist: toml>=0.10.2
41
+ Requires-Dist: tqdm>=4.66.1
42
+ Requires-Dist: transformers>=4.35.0
43
+ Requires-Dist: typer>=0.9.0
44
+ Provides-Extra: dev
45
+ Requires-Dist: black>=23.0.0; extra == 'dev'
46
+ Requires-Dist: isort>=5.12.0; extra == 'dev'
47
+ Requires-Dist: mypy>=1.5.0; extra == 'dev'
48
+ Requires-Dist: pre-commit>=3.3.0; extra == 'dev'
49
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
50
+ Provides-Extra: test
51
+ Requires-Dist: black>=23.0.0; extra == 'test'
52
+ Requires-Dist: isort>=5.12.0; extra == 'test'
53
+ Requires-Dist: mypy>=1.5.0; extra == 'test'
54
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'test'
55
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
56
+ Requires-Dist: pytest>=7.0.0; extra == 'test'
57
+ Requires-Dist: ruff>=0.1.0; extra == 'test'
58
+ Description-Content-Type: text/markdown
59
+
60
+ # 🧠 Contextly - The AI Context Engine for Developers
61
+
62
+ > "Know your code. Know your configs. Instantly."
63
+
64
+ Contextly is your terminal-native AI that helps you understand your codebase and configuration environment with natural-language queries and AI-powered explanations.
65
+
66
+ ## 🎯 Features
67
+
68
+ - **Natural Language Queries**: Ask questions about your code in plain English
69
+ - **Configuration Management**: Compare and analyze config files (env, json, yaml, etc.)
70
+ - **Semantic Code Search**: Find relevant code snippets by describing what you're looking for
71
+ - **Offline Support**: Built-in local LLM integration with Ollama
72
+ - **Multi-Language Support**: Works with Python, JavaScript, TypeScript, and more
73
+ - **Privacy-Focused**: Your code never leaves your machine (when using local LLMs)
74
+ - **VSCode-Friendly**: All features work directly in your terminal or VS Code
75
+
76
+ ## ⚡ Quick Start
77
+
78
+ 1. **Installation**
79
+ ```bash
80
+ pip install contextly
81
+ ```
82
+
83
+ 2. **Setup (Optional)**
84
+ ```bash
85
+ # Configure local LLM (recommended)
86
+ brew install ollama
87
+ ollama pull codellama
88
+
89
+ # Or set up OpenAI (optional)
90
+ export OPENAI_API_KEY=your_api_key
91
+ ```
92
+
93
+ 3. **Initialize in Your Repo**
94
+ ```bash
95
+ cd your-project
96
+ contextly sync
97
+ ```
98
+
99
+ ## 💡 Usage
100
+
101
+ ### Ask Questions About Your Code
102
+
103
+ ```bash
104
+ # General questions
105
+ contextly ask "How is user authentication handled?"
106
+ contextly ask "What's the database schema like?"
107
+
108
+ # Specific file questions
109
+ contextly ask "What does the login function in auth.py do?"
110
+
111
+ # Architecture questions
112
+ contextly ask "What's the overall project structure?"
113
+ ```
114
+
115
+ ### Search Code Semantically
116
+
117
+ ```bash
118
+ # Find relevant code
119
+ contextly search "password hashing implementation"
120
+ contextly search "database connection setup"
121
+ ```
122
+
123
+ ### Analyze Specific Code
124
+
125
+ ```bash
126
+ # Get explanation for code at a specific line
127
+ contextly explain src/auth.py:42
128
+
129
+ # Understand a function or class
130
+ contextly explain src/models.py:15
131
+ ```
132
+
133
+ ### Compare Config Files
134
+
135
+ ```bash
136
+ # Compare different environment files
137
+ contextly diff .env.dev .env.prod
138
+
139
+ # Compare any config files
140
+ contextly diff config/local.yml config/prod.yml
141
+ ```
142
+
143
+ ## ⚙️ Configuration
144
+
145
+ Contextly can be configured via environment variables or a `contextly.yml` file in your project root:
146
+
147
+ ```yaml
148
+ # contextly.yml
149
+ llm:
150
+ provider: ollama # or 'openai'
151
+ model: codellama # or 'gpt-4' for OpenAI
152
+ temperature: 0.2
153
+
154
+ embedding:
155
+ model: all-MiniLM-L6-v2 # Default embedding model
156
+ cache_dir: .contextly # Where to store the vector index
157
+
158
+ parsers:
159
+ python:
160
+ enabled: true
161
+ javascript:
162
+ enabled: true
163
+ config:
164
+ enabled: true
165
+ extensions: ['.json', '.yml', '.yaml', '.env', '.toml']
166
+ ```
167
+
168
+ ### Environment Variables
169
+
170
+ - `CONTEXTLY_LLM_PROVIDER`: 'ollama' or 'openai'
171
+ - `CONTEXTLY_MODEL`: LLM model to use
172
+ - `OPENAI_API_KEY`: Required if using OpenAI
173
+ - `CONTEXTLY_CACHE_DIR`: Where to store the vector index
174
+
175
+ ## �️ How It Works
176
+
177
+ Contextly works by:
178
+
179
+ 1. **Parsing**: Analyzes your code and config files using language-specific parsers
180
+ 2. **Embedding**: Creates vector embeddings of your code using SentenceTransformers
181
+ 3. **Indexing**: Stores embeddings in a local ChromaDB for fast retrieval
182
+ 4. **Reasoning**: Uses local or cloud LLMs to understand and explain code
183
+
184
+ ## 🤝 Contributing
185
+
186
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for:
187
+
188
+ - Setting up the development environment
189
+ - Running tests
190
+ - Code style guidelines
191
+ - Pull request process
192
+
193
+ ## 📝 License
194
+
195
+ MIT License - see [LICENSE](LICENSE) for details.
196
+
197
+ ## 🙋 FAQ
198
+
199
+ **Q: How does offline mode work?**
200
+ A: When using Ollama as the LLM provider, all processing happens locally. Your code never leaves your machine.
201
+
202
+ **Q: What languages are supported?**
203
+ A: Currently Python, JavaScript, TypeScript, and various config formats (JSON, YAML, TOML, ENV). More coming soon!
204
+
205
+ **Q: How can I customize the LLM responses?**
206
+ A: Adjust the `temperature` setting in your config. Lower values (0.1-0.3) give more precise answers, higher values more creative ones.
207
+
208
+ **Q: Where is data stored?**
209
+ A: By default, the vector index is stored in `.contextly/` in your project root. This can be configured via `CONTEXTLY_CACHE_DIR`.
@@ -0,0 +1,20 @@
1
+ contextly/__init__.py,sha256=3U7qro-M8x-nW90ysD04EFdcNZsFPBY0iMtAB00L028,79
2
+ contextly/app.py,sha256=_xVXMyvSFAkcwBlra_IskvqUaAKPdzvJpIux9PHOefI,3006
3
+ contextly/cli.py,sha256=t80ANTvbTFe2p-GmtFjJw4fcsS9L8Wvt7NnakcQ1fRc,6066
4
+ contextly/core/analyzer.py,sha256=nffNP8csKcJTcizRHagkG-wGZAFzv8GaQhpkth3VYn0,3699
5
+ contextly/core/embeddings.py,sha256=-53_8Eu31y1r2_3UAW11QuuLvxh6W40JtgVwuKQaZuc,3656
6
+ contextly/core/sync.py,sha256=Au6TSX7pHEObdCegBzbyLcRnHSuU1fnd_0Iq1xCQviE,2166
7
+ contextly/llm/base.py,sha256=aC719bIqiNDJoVO3PVseX63kog0J-UQaGQ53I-ABNS4,469
8
+ contextly/llm/manager.py,sha256=uBclknaDYIdLxG5dXWnaJIFap3bL-9GLDYyN8dtXSUs,4585
9
+ contextly/llm/models.py,sha256=3YKu8P0L-kCN_09nd6GFAFfSb6bWAZy1nn-loe9Qcsc,7560
10
+ contextly/llm/ollama.py,sha256=-j2iaIkTxUFu1oUviD4mkBfjQsI_XaitB1gorHQs2AI,2727
11
+ contextly/llm/openai.py,sha256=LixoxqMkIpyYaNIwLWtY0N9WRqt01CJw7RxxDBpbfC0,1301
12
+ contextly/parsers/base.py,sha256=UPik21ZWA6I78ba9ZIaAH_Z-QfTx7YiQTqbWVPoJ-bY,1090
13
+ contextly/parsers/config.py,sha256=U_QEK5RlcoubPNzZ2mhXpUJY_fwi66t7k0XEHhl12_I,2911
14
+ contextly/parsers/javascript.py,sha256=o6ljpJsrgaczs4adc1h-4zN8HVzcbUrc2H3wWmDzDG0,4602
15
+ contextly/parsers/python.py,sha256=K-Nrix2JIAY2EerZD5jduiBatLUt5i0oMiN522_LXmQ,1981
16
+ contextly-0.1.0.dist-info/METADATA,sha256=AwKUyX09uG0r03J_CyKXX_2g_wNsFYkBwGIr-UIneSk,6538
17
+ contextly-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
18
+ contextly-0.1.0.dist-info/entry_points.txt,sha256=JdeabARo3koshWmxzfNW0NuKPcVoL9voKhKI7PCUL4A,48
19
+ contextly-0.1.0.dist-info/licenses/LICENSE,sha256=70w0CZaboyv7Ppz4U0Ltgcn-PN1TMlc5WIhCJu3ySD4,1070
20
+ contextly-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ contextly = contextly.cli:app
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Contextly Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.