Git DB
Making sense of GitHub projects is harder than it should be.
- Default
insightsare poor and do give us much information on how the project is evolving. - The API model is not straightforward (issues & PRs are handled together, some calls are easier on v3 than v4,...).
- The typical approach consists on reading the API and computing metrics on-the-fly. This is too strict and new insights have a high cost (API calls).
Our goal with Git DB is to focus on simplicity and flexibility:
- We dump all the project's data to a local Duck DB.
- Your answers are one SQL query away.
Installation
pip install PyGitDB
What will you find?
stargazers
| Column Name | Type |
|---|---|
| id | INTEGER |
| starred_at | TIMESTAMP |
| user_id | INTEGER |
| user_login | VARCHAR |
issues
| Column Name | Type |
|---|---|
| id | INTEGER |
| number | INTEGER |
| title | VARCHAR |
| body | VARCHAR |
| user_id | INTEGER |
| user_login | VARCHAR |
| state | VARCHAR |
| assignees | VARCHAR[] |
| labels | VARCHAR[] |
| created_at | TIMESTAMP |
| updated_at | TIMESTAMP |
| closed_at | TIMESTAMP |
| author_association | VARCHAR |
| html_uri | VARCHAR |
pulls
| Column Name | Type |
|---|---|
| id | INTEGER |
| number | INTEGER |
| title | VARCHAR |
| body | VARCHAR |
| user_id | INTEGER |
| user_login | VARCHAR |
| state | VARCHAR |
| assignees | VARCHAR[] |
| labels | VARCHAR[] |
| created_at | TIMESTAMP |
| updated_at | TIMESTAMP |
| merged_at | TIMESTAMP |
| closed_at | TIMESTAMP |
| author_association | VARCHAR |
| html_uri | VARCHAR |
contributors
| Column Name | Type |
|---|---|
| id | INTEGER |
| contributions | INTEGER |
| user_id | INTEGER |
| user_login | VARCHAR |
latest_reviews
| Column Name | Type |
|---|---|
| id | INTEGER |
| number | INTEGER |
| reviewer | VARCHAR |
| review_state | VARCHAR |
| reviewed_at | TIMESTAMP |
weekly_commits
| Column Name | Type |
|---|---|
| id | INTEGER |
| date | TIMESTAMP |
| commits | INTEGER |
How to run
1. CLI
Once installed, you can prepare the database for your GitHub project directly with the CLI:
❯ gitdb --help х INT Py 3.9.13 11:36:05
usage: gitdb [-h] [-r REPO] [-o OWNER] [-f FILE] [--clean]
optional arguments:
-h, --help show this help message and exit
-r REPO, --repo REPO Repo to analyze
-o OWNER, --owner OWNER
Repo owner
-f FILE, --file FILE Db file path
--clean Clean the existing db
For example:
❯ gitdb -r OpenMetadata -o open-metadata 3s Py 3.9.13 11:37:04
2023-05-01 11:38:01.472 | INFO | gitdb.main:init:30 - Starting GitDB in gitdb.db...
2023-05-01 11:38:01.473 | INFO | gitdb.api.client:__init__:45 - Preparing client with root='api.github.com' owner='open-metadata' repo='OpenMetadata' token=SecretStr('**********') start_date='Aug 1 2021' timeout=300 graphql='graphql'
2023-05-01 12:31:29.240 | INFO | gitdb.dao.core:process:36 - Starting to process ReviewsDAO...
2023-05-01 12:31:29.240 | INFO | gitdb.dao.core:process:36 - Starting to process IssuesDAO...
2023-05-01 12:31:29.241 | INFO | gitdb.dao.core:process:36 - Starting to process StarsDAO...
2023-05-01 12:31:29.241 | INFO | gitdb.dao.core:process:36 - Starting to process WeeklyCommitsDAO...
2023-05-01 12:31:29.241 | INFO | gitdb.dao.core:process:36 - Starting to process ContributorsDAO...
2023-05-01 12:31:44.356 | INFO | gitdb.main:init:54 - Loaded all data in 0.26767790695000004 min.
2. Run from Python
If instead, you want to call the database generation from another Python program, you can use the following:
from gitdb.main import init
session = init(
repo=...,
owner=...,
token=...,
path=...,
)
The init method will create the Duck DB database and will give you the SQLAlchemy Session to start running
your queries.
Examples
Connect to the database using duckdb and start running queries:
import duckdb
conn = duckdb.connect(database="gitdb.db", read_only=True)
conn.execute("show tables").fetchall()
A typical question is wanting to see the evolution of the stars by week. This can be achieved with the following query:
WITH CTE AS (
SELECT
strftime(starred_at - INTERVAL (DAYOFWEEK(starred_at) - 1) DAY, '%Y/%m/%d') as starred_week,
count(id) as stars
from stargazers
group by strftime(starred_at - INTERVAL (DAYOFWEEK(starred_at) - 1) DAY, '%Y/%m/%d')
)
select
starred_week as week,
SUM(stars) over (ORDER BY starred_week ASC) as stars_by
FROM CTE
ORDER BY starred_week ASC
How does this work?
We are running a bunch of calls against the GitHub API when dumping all the data against the db. Doing this sequentially
can be rather long. Our client has a get_all_parallel function that accepts a number of threads as a parameter to do calls
in parallel by playing with totals and pagination.
The big chunk of work has gone into preparing the init call to be as fast as possible by leveraging multithreading in the host.
Metadata
Release files for PyGitDB 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 |
|---|---|---|---|---|
| PyGitDB-0.1.0.tar.gz | 17.4 kB | Without provenance | Details for PyGitDB-0.1.0.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| PyGitDB-0.1.0-py3.9.egg | Legacy Egg format | - | - | Details for PyGitDB-0.1.0-py3.9.egg |
| PyGitDB-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for PyGitDB-0.1.0-py3-none-any.whl |
Total release size: 92.3 kB
Release files / PyGitDB-0.1.0.tar.gz
| Download URL | PyGitDB-0.1.0.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f326ab8bcd42ada52604db834b82719988f13083a88f63cabd70dc5947e6faa6
|
|
BLAKE2b-256 checksum How to use checksums |
6cd7c40c335622b1c6ea86b5c450bd98c65b7d8e9a29649cf7d8bce6e4e5b2f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / PyGitDB-0.1.0-py3.9.egg
| Download URL | PyGitDB-0.1.0-py3.9.egg |
|---|---|
| Size | 48.3 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
9a3128a203af8f36fc20eeb326ea8ad10b627d32bf84cd2e336f257fa967fa1f
|
|
BLAKE2b-256 checksum How to use checksums |
8cab0a4cc72e5925ba36d8848383133425aeed7be888e3bf3922fa0a455899e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / PyGitDB-0.1.0-py3-none-any.whl
| Download URL | PyGitDB-0.1.0-py3-none-any.whl |
|---|---|
| Size | 26.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0ef501c5ae4922642f2f4110e96d29da3e44436785b61159112e76b9bbf99620
|
|
BLAKE2b-256 checksum How to use checksums |
b753d53d1a3cb29fef2d19f705797060f2f8c84ae60f87621c9b4ef0c9b82d26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for PyGitDB 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.