claude-code-analytics 0.1.0__tar.gz

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.
Files changed (64) hide show
  1. claude_code_analytics-0.1.0/.gitignore +104 -0
  2. claude_code_analytics-0.1.0/.idea/misc.xml +0 -0
  3. claude_code_analytics-0.1.0/CLAUDE.md +249 -0
  4. claude_code_analytics-0.1.0/Cargo.lock +773 -0
  5. claude_code_analytics-0.1.0/Cargo.toml +33 -0
  6. claude_code_analytics-0.1.0/LICENSE +21 -0
  7. claude_code_analytics-0.1.0/PKG-INFO +690 -0
  8. claude_code_analytics-0.1.0/README.md +666 -0
  9. claude_code_analytics-0.1.0/docs/RUST_CLAUDE_CODE_SDK_SPECIFICATION.md +556 -0
  10. claude_code_analytics-0.1.0/pyproject.toml +59 -0
  11. claude_code_analytics-0.1.0/python/claude_sdk/__init__.py +139 -0
  12. claude_code_analytics-0.1.0/python/claude_sdk/_core.pyi +328 -0
  13. claude_code_analytics-0.1.0/python/examples/README.md +211 -0
  14. claude_code_analytics-0.1.0/python/examples/analyze_costs.py +428 -0
  15. claude_code_analytics-0.1.0/python/examples/basic_usage.py +117 -0
  16. claude_code_analytics-0.1.0/python/examples/conversation_analysis.py +358 -0
  17. claude_code_analytics-0.1.0/python/examples/example_utils.py +126 -0
  18. claude_code_analytics-0.1.0/python/examples/export_sessions.py +374 -0
  19. claude_code_analytics-0.1.0/python/examples/test_all_examples.py +114 -0
  20. claude_code_analytics-0.1.0/python/examples/tool_usage_analysis.py +280 -0
  21. claude_code_analytics-0.1.0/python/old_pyproj/__init__.py +436 -0
  22. claude_code_analytics-0.1.0/python/old_pyproj/errors.py +95 -0
  23. claude_code_analytics-0.1.0/python/old_pyproj/executor.py +0 -0
  24. claude_code_analytics-0.1.0/python/old_pyproj/message.py +313 -0
  25. claude_code_analytics-0.1.0/python/old_pyproj/models_broken.py +1027 -0
  26. claude_code_analytics-0.1.0/python/old_pyproj/parser.py +499 -0
  27. claude_code_analytics-0.1.0/python/old_pyproj/session.py +457 -0
  28. claude_code_analytics-0.1.0/python/old_pyproj/utils.py +145 -0
  29. claude_code_analytics-0.1.0/python/tests/fixtures/malformed.jsonl +2 -0
  30. claude_code_analytics-0.1.0/python/tests/test_edge_cases.py +17 -0
  31. claude_code_analytics-0.1.0/python/tests/test_enhanced_methods.py +248 -0
  32. claude_code_analytics-0.1.0/python/tests/test_fixture_analysis.py +72 -0
  33. claude_code_analytics-0.1.0/python/tests/test_ingtegration.py +60 -0
  34. claude_code_analytics-0.1.0/src/conversation/mod.rs +3 -0
  35. claude_code_analytics-0.1.0/src/conversation/tree.rs +263 -0
  36. claude_code_analytics-0.1.0/src/error.rs +66 -0
  37. claude_code_analytics-0.1.0/src/lib.rs +59 -0
  38. claude_code_analytics-0.1.0/src/main.rs +61 -0
  39. claude_code_analytics-0.1.0/src/parser/mod.rs +3 -0
  40. claude_code_analytics-0.1.0/src/parser/session.rs +269 -0
  41. claude_code_analytics-0.1.0/src/python/classes.rs +625 -0
  42. claude_code_analytics-0.1.0/src/python/exceptions.rs +16 -0
  43. claude_code_analytics-0.1.0/src/python/functions.rs +250 -0
  44. claude_code_analytics-0.1.0/src/python/mod.rs +44 -0
  45. claude_code_analytics-0.1.0/src/python/models.rs +520 -0
  46. claude_code_analytics-0.1.0/src/python/utils.rs +37 -0
  47. claude_code_analytics-0.1.0/src/types/content.rs +186 -0
  48. claude_code_analytics-0.1.0/src/types/enums.rs +47 -0
  49. claude_code_analytics-0.1.0/src/types/message.rs +117 -0
  50. claude_code_analytics-0.1.0/src/types/metadata.rs +140 -0
  51. claude_code_analytics-0.1.0/src/types/mod.rs +15 -0
  52. claude_code_analytics-0.1.0/src/types/project.rs +183 -0
  53. claude_code_analytics-0.1.0/src/types/session.rs +81 -0
  54. claude_code_analytics-0.1.0/src/types/tool.rs +72 -0
  55. claude_code_analytics-0.1.0/src/utils/analysis.rs +108 -0
  56. claude_code_analytics-0.1.0/src/utils/discovery.rs +119 -0
  57. claude_code_analytics-0.1.0/src/utils/mod.rs +7 -0
  58. claude_code_analytics-0.1.0/src/utils/path.rs +85 -0
  59. claude_code_analytics-0.1.0/tests/db68d083-0471-4213-8609-356b0bf38fec.jsonl +851 -0
  60. claude_code_analytics-0.1.0/tests/debug_file.rs +38 -0
  61. claude_code_analytics-0.1.0/tests/fixtures/example_sample.jsonl +2 -0
  62. claude_code_analytics-0.1.0/tests/integration_test.rs +315 -0
  63. claude_code_analytics-0.1.0/tests/parsing_test.rs +117 -0
  64. claude_code_analytics-0.1.0/tests/simple_test.rs +21 -0
@@ -0,0 +1,104 @@
1
+ # Rust
2
+ /target/
3
+ Cargo.lock
4
+
5
+ # Python
6
+ __pycache__/
7
+ *.py[cod]
8
+ *$py.class
9
+ *.so
10
+ *.pyi
11
+ py.typed
12
+
13
+ # Distribution / packaging
14
+ .Python
15
+ build/
16
+ develop-eggs/
17
+ dist/
18
+ downloads/
19
+ eggs/
20
+ .eggs/
21
+ lib/
22
+ lib64/
23
+ parts/
24
+ sdist/
25
+ var/
26
+ wheels/
27
+ *.egg-info/
28
+ .installed.cfg
29
+ *.egg
30
+ MANIFEST
31
+
32
+ # PyInstaller
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Python environments
37
+ .env
38
+ .venv
39
+ env/
40
+ venv/
41
+ ENV/
42
+ env.bak/
43
+ venv.bak/
44
+ .python-version
45
+
46
+ # UV package manager
47
+ uv.lock
48
+
49
+ # Jupyter Notebook
50
+ .ipynb_checkpoints
51
+
52
+ # IPython
53
+ profile_default/
54
+ ipython_config.py
55
+
56
+ # pytest
57
+ .pytest_cache/
58
+ .coverage
59
+ htmlcov/
60
+
61
+ # IDEs and editors
62
+ .idea/
63
+ .vscode/
64
+ *.swp
65
+ *.swo
66
+ *~
67
+ .project
68
+ .settings/
69
+
70
+ # OS
71
+ .DS_Store
72
+ .DS_Store?
73
+ ._*
74
+ .Spotlight-V100
75
+ .Trashes
76
+ ehthumbs.db
77
+ Thumbs.db
78
+
79
+ # Temporary files
80
+ *.tmp
81
+ *.temp
82
+ *.log
83
+ *.bak
84
+ *.orig
85
+
86
+ # Test data and session files
87
+ *.jsonl
88
+ !example*.jsonl # Keep example files if any
89
+ !tests/fixtures/example*.jsonl
90
+ !python/tests/fixtures/*.jsonl
91
+
92
+ # Old/backup directories
93
+ backup_*/
94
+ *_old/
95
+ *_backup/
96
+
97
+ # Development artifacts
98
+ .claude/
99
+ *.debug
100
+ core.*
101
+ test-env/
102
+
103
+ # Maturin build cache
104
+ .cargo/
File without changes
@@ -0,0 +1,249 @@
1
+ # Claude SDK Development Guide
2
+
3
+ A Rust library with Python bindings for parsing and analyzing Claude Code session data.
4
+
5
+ ## Quick Start
6
+
7
+ ### Development Setup
8
+
9
+ ```bash
10
+ # Clone and setup
11
+ git clone <repo-url>
12
+ cd rust_sdk
13
+
14
+ # Build and install in development mode
15
+ cd python
16
+ uv build
17
+
18
+ # Test the installation
19
+ python -c "import claude_sdk; print('✅ Import successful!')"
20
+ ```
21
+
22
+ ## Project Structure
23
+
24
+ ```
25
+ rust_sdk/
26
+ ├── src/ # Rust source code
27
+ │ ├── lib.rs # Main library entry point
28
+ │ ├── python/ # Python bindings (PyO3)
29
+ │ │ ├── mod.rs # Python module registration
30
+ │ │ ├── classes.rs # Python class wrappers
31
+ │ │ ├── functions.rs # Python function exports
32
+ │ │ └── ...
33
+ │ ├── types/ # Core Rust types
34
+ │ ├── parser/ # JSONL parsing logic
35
+ │ └── ...
36
+ ├── python/ # Python package
37
+ │ ├── pyproject.toml # Python build configuration
38
+ │ ├── claude_sdk/ # Python package source
39
+ │ │ └── __init__.py # Python API exports
40
+ │ └── .venv/ # Python virtual environment
41
+ ├── Cargo.toml # Rust dependencies and config
42
+ └── tests/ # Test files
43
+ ```
44
+
45
+ ## Building
46
+
47
+ ### Rust Library Only
48
+
49
+ ```bash
50
+ # Check compilation
51
+ cargo check
52
+
53
+ # Build library
54
+ cargo build
55
+
56
+ # Run Rust tests
57
+ cargo test
58
+ ```
59
+
60
+ ### Python Extension
61
+
62
+ ```bash
63
+ cd python
64
+
65
+ # Development build (installs in current Python env)
66
+ uv build
67
+
68
+ # Production build (creates wheel)
69
+ uv build --release
70
+
71
+ # Build with specific features
72
+ uv build --features python
73
+ ```
74
+
75
+ ## Testing
76
+
77
+ ### Rust Tests
78
+
79
+ ```bash
80
+ # Run all Rust tests
81
+ cargo test
82
+
83
+ # Run specific test module
84
+ cargo test parser
85
+
86
+ # Run with output
87
+ cargo test -- --nocapture
88
+ ```
89
+
90
+ ### Python Tests
91
+
92
+ ```bash
93
+ cd python
94
+
95
+ # Install in development mode first
96
+ uv build
97
+
98
+ # Run Python tests (if you have any)
99
+ uv run -m pytest tests/
100
+
101
+ # Quick import test
102
+ python -c "import claude_sdk; print('✅ Working!')"
103
+ ```
104
+
105
+ ### Integration Testing
106
+
107
+ ```bash
108
+ # Test with real session file
109
+ python -c "
110
+ import claude_sdk
111
+ session = claude_sdk.load('path/to/session.jsonl')
112
+ print(f'Loaded session with {len(session.messages)} messages')
113
+ "
114
+ ```
115
+
116
+ ## Development Workflow
117
+
118
+ ### Making Changes
119
+
120
+ 1. **Rust changes**: Edit files in `src/`
121
+ 2. **Python binding changes**: Edit files in `src/python/`
122
+ 3. **Python API changes**: Edit `python/claude_sdk/__init__.py`
123
+
124
+ ### Rebuilding After Changes
125
+
126
+ ```bash
127
+ cd python
128
+
129
+ # Rebuild and reinstall
130
+ uv build
131
+
132
+ # Test your changes
133
+ python -c "import claude_sdk; # your test code"
134
+ ```
135
+
136
+ ### Release Build
137
+
138
+ ```bash
139
+ cd python
140
+
141
+ # Build wheel for distribution
142
+ uv build --release
143
+
144
+ # Wheel will be in ../target/wheels/
145
+ ls ../target/wheels/
146
+ ```
147
+
148
+ ## Configuration Files
149
+
150
+ ### `Cargo.toml`
151
+ - **Package name**: `claude-code-analytics` (matches Python package)
152
+ - **Library name**: `claude_sdk` (matches Python import)
153
+ - **Python feature**: Enable with `--features python`
154
+ - **Excludes**: Top-level `python/` directory from Rust build
155
+
156
+ ### `python/pyproject.toml`
157
+ - **Module name**: `claude_sdk._core` (Rust extension)
158
+ - **Python packages**: `["claude_sdk"]`
159
+ - **Manifest path**: `../Cargo.toml` (points to Rust config)
160
+
161
+ ## Common Issues & Solutions
162
+
163
+ ### Build Failures
164
+
165
+ **Error**: `file not found for module 'python'`
166
+ - **Solution**: Build from project root or use `uv build` from `python/` directory
167
+
168
+ **Error**: `PyInit symbol not found`
169
+ - **Solution**: Ensure `#[pymodule]` function name matches expected import structure
170
+
171
+ ### Import Failures
172
+
173
+ - **Solution**: Run `uv build` to rebuild the extension
174
+ - **Check**: Make sure you're in the right Python environment
175
+
176
+ - **Solution**: Use `uv build` instead of `uv build --release` for development
177
+
178
+ ### Development Tips
179
+
180
+ 1. **Use `uv build`** for development - it handles the shared library correctly
181
+ 2. **Build from `python/` directory** - it has the right context and config
182
+ 3. **Check imports after changes** - Python extensions need rebuilding after Rust changes
183
+ 4. **Use `cargo check`** for quick Rust-only validation
184
+
185
+ ## Available Python API
186
+
187
+ ```python
188
+ import claude_sdk
189
+
190
+ # Core functions
191
+ session = claude_sdk.load("session.jsonl")
192
+ sessions = claude_sdk.find_sessions()
193
+ projects = claude_sdk.find_projects()
194
+ project = claude_sdk.load_project("project_name")
195
+
196
+ # Classes
197
+ claude_sdk.Session # Session data
198
+ claude_sdk.Message # Individual messages
199
+ claude_sdk.Project # Project with multiple sessions
200
+ claude_sdk.ToolResult # Tool execution results
201
+
202
+ # Exceptions
203
+ claude_sdk.ClaudeSDKError
204
+ claude_sdk.ParseError
205
+ claude_sdk.ValidationError
206
+ claude_sdk.SessionError
207
+ ```
208
+
209
+ ## Performance Notes
210
+
211
+ - Written in Rust for fast JSONL parsing
212
+ - Zero-copy string handling where possible
213
+ - Efficient conversation threading
214
+ - Memory-conscious design for large session files
215
+
216
+ ## Troubleshooting
217
+
218
+ ### Clean Build
219
+
220
+ ```bash
221
+ # Clean Rust build cache
222
+ cargo clean
223
+
224
+ # Remove Python build artifacts
225
+ rm -rf python/claude_sdk/*.so
226
+ rm -rf python/claude_sdk/*.pyi
227
+
228
+ # Rebuild everything
229
+ uv build
230
+ ```
231
+
232
+ ### Environment Issues
233
+
234
+ ```bash
235
+ # Check Python environment
236
+ python -c "import sys; print(sys.executable)"
237
+
238
+ # Check if package is installed
239
+ pip list | grep claude
240
+
241
+ # Reinstall if needed
242
+ pip uninstall claude-code-analytics
243
+ uv build
244
+ ```
245
+
246
+ ## Development Memories
247
+
248
+ - ALWAYS use uv run before typing python. it sets up the environment properly. Use `uv add` to add packages.
249
+ - Use uv build to build the project.