A typed, modular Python library for structured repository parsing
Project description
GitParse
A modern Python library for Git repository analysis with async support and type safety.
Features
- Repository metadata extraction
- File tree analysis with multiple formats
- Dependency parsing (Poetry, requirements.txt, package.json)
- Language statistics and file type detection
- Async support with context managers
- Type-safe API with clear error handling
Installation
pip install gitparse
Basic Usage
Synchronous
from gitparse import RepositoryAnalyzer, ExtractionConfig
# Configure analysis
config = ExtractionConfig(
max_file_size=1024 * 1024, # 1MB
exclude_patterns=["*.pyc"],
include_patterns=["*.py", "*.md"],
)
# Initialize and analyze repository
repo = RepositoryAnalyzer("https://github.com/username/repo", config)
# Repository metadata
info = repo.get_repository_info()
# Returns: {"name": "repo", "default_branch": "main", "head_commit": "abc123..."}
# File tree (markdown format)
tree = repo.get_file_tree(style="markdown")
# Returns: ["- README.md", " - src/", " - main.py", ...]
# Dependencies
deps = repo.get_dependencies()
# Returns: {
# "pyproject.toml": {"dependencies": {"requests": "^2.0.0"}},
# "requirements.txt": [{"name": "flask", "version": "2.0.0"}]
# }
# Language statistics
stats = repo.get_language_stats()
# Returns: {
# "Python": {"files": 10, "bytes": 1500, "percentage": 75.5},
# "Markdown": {"files": 2, "bytes": 500, "percentage": 24.5}
# }
Command Line Interface
Also, GitParse comes with CLI for quick repository analysis. Use --help with any command to see its specific options:
# Get general help
gitparse --help
# Get help for specific commands
gitparse tree --help
gitparse content --help
gitparse all-contents --help
# Common operations
gitparse <repo_url> info
gitparse <repo_url> tree --style markdown
gitparse <repo_url> deps
gitparse <repo_url> langs
gitparse <repo_url> stats
gitparse <repo_url> readme
gitparse <repo_url> content path/to/file.py
gitparse <repo_url> dir-tree src --style markdown
# Advanced usage with filters
gitparse <repo_url> all-contents --max-size 1048576 --exclude "*.pyc" "*.so"
# Output options
gitparse <repo_url> langs -o language_stats.json # Save to file
gitparse <repo_url> stats --no-pretty # Disable pretty printing
Available Commands
Each command supports --help for detailed usage information:
info: Get repository informationtree: Get repository file tree- See
tree --helpfor style options
- See
dir-tree: Get directory file tree- See
dir-tree --helpfor style options
- See
dir-contents: Get directory contentsreadme: Get repository README contentcontent: Get specific file contentall-contents: Get all file contents- See
all-contents --helpfor filtering options
- See
deps: Get repository dependencieslangs: Get language statisticsstats: Get repository statistics
Global Options
Use gitparse --help to see all available options:
-o, --output: Save output to file--no-pretty: Disable pretty printing-h, --help: Show help message
Advanced Features
File Analysis
# Get specific file content
content = repo.get_file_content("README.md")
# Returns: "# Project Title\n..."
# Get all text files
contents = repo.get_all_contents(
max_file_size=1024 * 1024,
exclude_patterns=["*.pyc", "*.so"]
)
# Returns: {"README.md": "# Title...", "src/main.py": "def main():..."}
# Get directory tree
tree = repo.get_directory_tree(
"src",
style="structured" # or "markdown", "flattened"
)
# Returns: {"src": {"main.py": None, "utils": {"helpers.py": None}}}
Statistics
# Repository statistics
stats = repo.get_statistics()
# Returns: {
# "total_files": 100,
# "binary_ratio": 0.05,
# "avg_file_size": 1024,
# "language_breakdown": {...}
# }
# Language breakdown
langs = repo.get_language_stats()
# Returns: {
# "Python": {"files": 50, "percentage": 80.5},
# "JavaScript": {"files": 10, "percentage": 19.5}
# }
Development
# Install dependencies
poetry install
# Run tests
poetry run pytest
# Run linting
poetry run ruff check .
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gitparse-0.1.4.tar.gz.
File metadata
- Download URL: gitparse-0.1.4.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.8 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f03db08620d3283b55e89cc31a9e89b6a071ed3b5637f791e824ccf2bb128b6a
|
|
| MD5 |
bb3615097b553bcc09d0e0463ce606b5
|
|
| BLAKE2b-256 |
cb12b2b2208b6c8fa55659a45d6551b056a04431058b7b03435eb018ba04900a
|
File details
Details for the file gitparse-0.1.4-py3-none-any.whl.
File metadata
- Download URL: gitparse-0.1.4-py3-none-any.whl
- Upload date:
- Size: 36.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.8 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0598426d1fd53eaeae144d57b22ad51dc61ea310ea5254d6d5a274e1e64f2588
|
|
| MD5 |
849e046affda8231e5217e25c0056732
|
|
| BLAKE2b-256 |
d4b8d59f5e47e36fc2b26b1409666421120864b171f7903589771ad076b9a745
|