codearc
Mine a Python repo's git history to extract all distinct versions of every function and class into a DuckDB database.
Quick Start
# Run directly (no install needed)
uvx codearc --repo /path/to/repo --db output.duckdb --verbose
# Query the results
python -c "
import duckdb
conn = duckdb.connect('output.duckdb')
for row in conn.execute('SELECT qualname, kind, COUNT(*) as versions FROM symbol_versions GROUP BY 1, 2 ORDER BY 3 DESC LIMIT 10').fetchall():
print(row)
"
Installation
Requires Python 3.12+ and uv.
# As a CLI tool
uv tool install codearc
codearc --repo /path/to/repo --db output.duckdb
# As a library
uv add codearc
From source
git clone https://github.com/drothermel/codearc.git
cd codearc
uv sync
uv run codearc --help
CLI Reference
codearc --repo PATH --db OUTPUT.duckdb [options]
| Option | Description |
|---|---|
--repo PATH |
Path to the git repository (required) |
--db PATH |
Path to output DuckDB file (required) |
--package-root PATH |
Package root for module path calculation |
--since-commit HASH |
Resume from a specific commit |
--since DATE |
Process commits after date (ISO format) |
--authors "a,b" |
Comma-separated author filter |
--no-merge/--include-merge |
Skip merge commits (default: skip) |
--ignore PATTERN |
Additional ignore patterns (repeatable) |
-v, --verbose |
Show mining statistics |
Examples
# Mine a repo with verbose output
codearc --repo ~/projects/mylib --db mylib.duckdb --verbose
# Filter by author and date
codearc --repo . --db output.duckdb --authors "Alice,Bob" --since 2024-01-01
# Resume from a specific commit
codearc --repo . --db output.duckdb --since-commit abc123
# Add custom ignore patterns
codearc --repo . --db output.duckdb --ignore "generated/*" --ignore "vendor/*"
Features
- Symbol extraction - Extracts functions, classes, and methods using LibCST with accurate source positions and qualified names
- Version deduplication - Stores only distinct versions of each symbol (by content hash), avoiding redundant storage
- Git history traversal - Walks commit history with PyDriller, processing only modified Python files
- Crash recovery - Per-commit database writes with extraction state tracking for resumability
- Flexible filtering - Filter by author, date, ignore patterns; skip merge commits by default
- Encoding handling - Gracefully handles non-UTF8 files with fallback encodings
Database Schema
The extracted data is stored in two tables:
symbol_versions - All distinct versions of symbols
version_key- Unique identifier (repo:module:qualname:kind:code_hash)symbol_key- Symbol identifier without version (repo:module:qualname:kind)repo_id,commit_hash,commit_time- Git metadatafile_path,module,start_line,end_line- Location infokind- "function" or "class"qualname- Qualified name (e.g.,ClassName.method_name)code,code_hash- Exact source code and its hashdocstring- Extracted docstring if present
extraction_state - Tracks mining progress for resumability
repo_id,last_processed_commit,total_commits_processed, etc.
Demo Scripts
Interactive demos to explore the library's capabilities:
| Script | Description |
|---|---|
scripts/demo_models.py |
Data models, ignore pattern matching, key generation |
scripts/demo_database.py |
Database operations, deduplication, extraction state |
scripts/demo_extractor.py |
LibCST parsing, symbol extraction with metadata |
scripts/demo_module_paths.py |
File path to module name conversion |
scripts/demo_miner.py |
End-to-end mining of a sample git repo |
Run any demo:
uv run python scripts/demo_miner.py
Development
Running Tests
uv run pytest tests/ -v
Project Structure
src/codearc/
├── cli.py # Typer CLI entrypoint
├── database.py # DuckDB schema + operations
├── utils.py # Hashing, module paths, encoding
├── extraction/ # Symbol extraction from source
│ ├── extract_symbols.py # Main extraction entry point
│ ├── symbol_extractor.py # LibCST visitor for symbols
│ └── docstring.py # Docstring extraction
├── mining/ # Git history mining
│ ├── miner.py # PyDriller git traversal
│ ├── mining_config.py # MiningConfig
│ ├── mining_stats.py # MiningStats
│ ├── symbol_version.py # SymbolVersion
│ ├── ignore_patterns.py # IgnorePatterns
│ └── encoding_config.py # EncodingConfig
└── models/ # Shared models
└── extracted_symbol.py # ExtractedSymbol, SymbolKind
scripts/ # Demo scripts
tests/ # Test suite (80 tests)
Dependencies
- PyDriller - Git repository mining
- LibCST - Lossless Python parsing
- DuckDB - Embedded analytics database
- Typer - CLI framework
- Rich - Terminal output formatting
- Pydantic - Data validation and models
Metadata
Release files for codearc 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| codearc-0.1.0.tar.gz | 23.9 kB | Without provenance | Details for codearc-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| codearc-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for codearc-0.1.0-py3-none-any.whl |
Total release size: 41.3 kB
Release files / codearc-0.1.0.tar.gz
| Download URL | codearc-0.1.0.tar.gz |
|---|---|
| Size | 23.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e5ebd4f5142bd2d3cd8a79e786546eb4cad89290eb12d95ecd12adec2f40a288
|
|
BLAKE2b-256 checksum How to use checksums |
1762b1f0f6821a3805e5aff9d4ade4553024e04f2db76e54791525db4223897f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.0
|
Release files / codearc-0.1.0-py3-none-any.whl
| Download URL | codearc-0.1.0-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc5798f4b9cda793f65831895afb0df00c8f88542c9f0213ee1cb12d35dc29ad
|
|
BLAKE2b-256 checksum How to use checksums |
90e579ef3b33472ea5e7bf317703bb58cc9bdc63c4e7656c1fc8f71b3368add3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.0
|
Security for codearc 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.