GitHub Repository Structure Analyzer
A Python utility for cloning GitHub repositories and generating a JSON-friendly representation of their directory structure. This tool provides a clean way to analyze repository layouts while respecting .gitignore rules and offering customizable exclude patterns for different project types.
Features
- Clone GitHub repositories with progress visualization
- Generate nested JSON representation of repository structure
- Support for private repositories via GitHub tokens
- Respect
.gitignorepatterns - Configurable depth limit for directory traversal
- Pre-defined exclude patterns for common project types (Python, Node.js, Java)
- Progress bar visualization during cloning using
alive-progress - Handles symlinks and special files appropriately
Installation
Prerequisites
Make sure you have Python 3.6+ installed. Then install the required dependencies:
pip install -r requirements.txt
Usage
Basic Usage
from repo_structure import get_repo_structure
# Simple example with default settings
structure = get_repo_structure(
github_url="https://github.com/username/repo.git",
clone_path="local_repo_folder"
)
Advanced Usage
from repo_structure import get_repo_structure, PROJECT_EXCLUDES
import json
# Using project-specific excludes and depth limit
structure = get_repo_structure(
github_url="https://github.com/username/repo.git",
clone_path="local_repo_folder",
token="your_github_token", # For private repos
max_depth=2, # Limit directory traversal depth
exclude_patterns=PROJECT_EXCLUDES["python"] # Use Python-specific excludes
)
# Print the structure as formatted JSON
print(json.dumps(structure, indent=2))
Private Repositories
For private repositories, you'll need to provide a GitHub personal access token:
structure = get_repo_structure(
github_url="https://github.com/oguzhancetinkaya/private-repo.git",
clone_path="private_repo_folder",
token="your_github_personal_access_token"
)
Exclude Patterns
The tool comes with predefined exclude patterns for different project types:
DEFAULT_EXCLUDES: Basic patterns like.git,node_modules,venvPYTHON_EXCLUDES: Python-specific patternsNODE_EXCLUDES: Node.js-specific patternsJAVA_EXCLUDES: Java-specific patterns
You can also provide your own custom exclude patterns:
custom_excludes = [
"*.log",
"temp",
"custom_folder"
]
structure = get_repo_structure(
github_url="https://github.com/username/repo.git",
clone_path="local_repo_folder",
exclude_patterns=custom_excludes
)
Output Format
The tool generates a nested dictionary structure that represents the repository layout:
{
"name": "repo_name",
"type": "directory",
"children": [
{
"name": "src",
"type": "directory",
"children": [
{
"name": "main.py",
"type": "file"
}
]
}
]
}
Components
repo_structure.py
The main module containing:
- Directory traversal logic
- Repository cloning functionality
- Exclude pattern definitions
.gitignoreintegration
clone_progress.py
A helper module that provides:
- Custom progress handler for Git operations
- Integration with the
alive-progresslibrary - Visual feedback during repository cloning
Contributing
Contributions are welcome! Some areas for potential improvement:
- Additional project-type exclude patterns
- Support for other Git hosting services
- Enhanced progress reporting
- Additional output formats
- Performance optimizations for large repositories
License
[Add your chosen license here]
License
This project is open-source. See the LICENSE file for details.
Thank you for using github-repo-structure ! If you have any questions or suggestions, don’t hesitate to create an issue or open a discussion. Happy coding! ```
Metadata
Release files for github-repo-structure 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 |
|---|---|---|---|---|
| github_repo_structure-0.1.0.tar.gz | 7.3 kB | Without provenance | Details for github_repo_structure-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| github_repo_structure-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for github_repo_structure-0.1.0-py3-none-any.whl |
Total release size: 14.5 kB
Release files / github_repo_structure-0.1.0.tar.gz
| Download URL | github_repo_structure-0.1.0.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7720f2467e87889693af336a4eb87f4beb5518a139bdcbd90ecd60f9fede41b4
|
|
BLAKE2b-256 checksum How to use checksums |
f3c2128ff473ae7221fac52428d1fe648660598f19fbb46bb277e56d95dee66f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.0
|
Release files / github_repo_structure-0.1.0-py3-none-any.whl
| Download URL | github_repo_structure-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5b051d4bff5694910ae0b6393ce21a0171f67ac1609f2206db47c6c0a061d6ff
|
|
BLAKE2b-256 checksum How to use checksums |
c5ae1f9d011e58361bfe32a122a9b8bc2ec55b27d5137e357485ebe976699a18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.0
|
Security for github-repo-structure 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.