PyDriller is a Python framework designed for mining software repositories. It enables developers to easily extract detailed information from any Git repository, including commits, developers, file modifications, diffs, and source code. The library is actively maintained with frequent minor releases to introduce new features and improvements.
pip install pydrillerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a `Repository` object, traverse all commits, and access basic commit information. It also shows an example of using filters to analyze a specific number of recent commits within a particular branch.
Update your import statement from `from pydriller import RepositoryMining` to `from pydriller import Repository`.
Replace `modification.source_code` with `modification.content` when accessing the source code of a modified file.
Ensure that only one filter from a given category (e.g., 'from', 'to') is used at a time. For complex filtering, retrieve a broader set of commits and apply programmatic filtering afterwards.
Utilize filters like `since`, `to`, `num_commits`, `only_in_branches`, or `only_commits` to narrow down the scope of analysis. Consider running analyses on subsets of the repository history.
Avoid using `Git.checkout()` in multi-threaded scenarios. If repository state manipulation is necessary, perform it in a single-threaded context or ensure proper locking/isolation mechanisms.
If commit order is crucial for your analysis, set `num_workers=1` or sort the commits after retrieval based on `commit.author_date` or `commit.committer_date`.
Change the import statement to `from pydriller import Repository`.
Ensure Git is installed on your system and its executable is in your system's PATH. Verify that `path_to_repo` points to a valid and accessible Git repository. Check for required Git versions (e.g., 2.38+).
Ensure the repository is fully cloned (e.g., `include_remotes=True`). If the commit is truly missing from the fetched history, consider using `git fetch --all` or `git pull --all` on the local repository before running PyDriller. If the commit exists only in a specific ref or remote, ensure that ref is included in the analysis filters.