gitlytics 0.1.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. gitlytics-0.1.2/PKG-INFO +273 -0
  2. gitlytics-0.1.2/README.md +246 -0
  3. {gitlytics-0.1.1 → gitlytics-0.1.2}/pyproject.toml +14 -5
  4. gitlytics-0.1.2/src/gitlytics/__init__.py +73 -0
  5. gitlytics-0.1.2/src/gitlytics/api.py +112 -0
  6. gitlytics-0.1.2/src/gitlytics/automation.py +153 -0
  7. gitlytics-0.1.2/src/gitlytics/cli.py +94 -0
  8. gitlytics-0.1.2/src/gitlytics/core.py +188 -0
  9. gitlytics-0.1.2/src/gitlytics/process.py +117 -0
  10. gitlytics-0.1.2/src/gitlytics/static/assets/index-BPCIBQz4.js +44 -0
  11. gitlytics-0.1.2/src/gitlytics/static/assets/index-DytQw1pB.css +2 -0
  12. gitlytics-0.1.2/src/gitlytics/static/favicon.svg +4 -0
  13. {gitlytics-0.1.1/github_traffic/frontend/dist → gitlytics-0.1.2/src/gitlytics/static}/index.html +4 -4
  14. gitlytics-0.1.2/src/gitlytics.egg-info/PKG-INFO +273 -0
  15. gitlytics-0.1.2/src/gitlytics.egg-info/SOURCES.txt +23 -0
  16. gitlytics-0.1.2/src/gitlytics.egg-info/entry_points.txt +2 -0
  17. {gitlytics-0.1.1 → gitlytics-0.1.2/src}/gitlytics.egg-info/requires.txt +1 -0
  18. gitlytics-0.1.2/src/gitlytics.egg-info/top_level.txt +1 -0
  19. gitlytics-0.1.1/PKG-INFO +0 -201
  20. gitlytics-0.1.1/README.md +0 -178
  21. gitlytics-0.1.1/github_traffic/__init__.py +0 -4
  22. gitlytics-0.1.1/github_traffic/api.py +0 -76
  23. gitlytics-0.1.1/github_traffic/automation.py +0 -122
  24. gitlytics-0.1.1/github_traffic/cli.py +0 -154
  25. gitlytics-0.1.1/github_traffic/core.py +0 -147
  26. gitlytics-0.1.1/github_traffic/frontend/dist/assets/axios-BATw4G7Y.js +0 -9
  27. gitlytics-0.1.1/github_traffic/frontend/dist/assets/index-BJy89P_N.js +0 -44
  28. gitlytics-0.1.1/github_traffic/frontend/dist/assets/index-DHekp9vT.css +0 -1
  29. gitlytics-0.1.1/github_traffic/frontend/dist/favicon.svg +0 -1
  30. gitlytics-0.1.1/github_traffic/frontend/node_modules/flatted/python/flatted.py +0 -144
  31. gitlytics-0.1.1/github_traffic/process.py +0 -43
  32. gitlytics-0.1.1/gitlytics.egg-info/PKG-INFO +0 -201
  33. gitlytics-0.1.1/gitlytics.egg-info/SOURCES.txt +0 -25
  34. gitlytics-0.1.1/gitlytics.egg-info/entry_points.txt +0 -2
  35. gitlytics-0.1.1/gitlytics.egg-info/top_level.txt +0 -1
  36. {gitlytics-0.1.1 → gitlytics-0.1.2}/LICENSE +0 -0
  37. {gitlytics-0.1.1 → gitlytics-0.1.2}/setup.cfg +0 -0
  38. {gitlytics-0.1.1/github_traffic/frontend/dist → gitlytics-0.1.2/src/gitlytics/static}/icons.svg +0 -0
  39. {gitlytics-0.1.1 → gitlytics-0.1.2/src}/gitlytics.egg-info/dependency_links.txt +0 -0
  40. {gitlytics-0.1.1 → gitlytics-0.1.2}/tests/test_automation.py +0 -0
  41. {gitlytics-0.1.1 → gitlytics-0.1.2}/tests/test_cli.py +0 -0
  42. {gitlytics-0.1.1 → gitlytics-0.1.2}/tests/test_core.py +0 -0
@@ -0,0 +1,273 @@
1
+ Metadata-Version: 2.4
2
+ Name: gitlytics
3
+ Version: 0.1.2
4
+ Summary: Monitor and automate your GitHub repository traffic analytics.
5
+ Author: Ameya Chopade
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/ameyac11/gitlytics
8
+ Keywords: github,traffic,analytics,automation,cli
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: requests
16
+ Requires-Dist: pandas
17
+ Requires-Dist: python-dotenv
18
+ Requires-Dist: croniter
19
+ Provides-Extra: dashboard
20
+ Requires-Dist: fastapi; extra == "dashboard"
21
+ Requires-Dist: uvicorn; extra == "dashboard"
22
+ Requires-Dist: python-multipart; extra == "dashboard"
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
25
+ Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ <div align="center">
29
+
30
+ # 📊 Gitlytics
31
+ ### GitHub Traffic Analytics & Automation
32
+
33
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
34
+ [![Python](https://img.shields.io/badge/Python-3.9%2B-blue)](https://www.python.org/)
35
+ [![PyPI](https://img.shields.io/pypi/v/gitlytics?color=blue)](https://pypi.org/project/gitlytics/)
36
+ [![React](https://img.shields.io/badge/UI-React-61dafb?logo=react)](https://react.dev/)
37
+ [![FastAPI](https://img.shields.io/badge/Backend-FastAPI-009688?logo=fastapi)](https://fastapi.tiangolo.com/)
38
+ [![Automation](https://img.shields.io/badge/Data%20Backup-Automation%20Tool-purple?logo=github-actions)](https://github.com/ameyac11/gitlytics-github-traffic-automation)
39
+
40
+ **Beautiful GitHub traffic analytics for all your repositories — public and private.** <br/> Track views, clones, referrers, and popular paths indefinitely.
41
+
42
+ Please consider giving this project a ⭐ if you find it helpful!
43
+
44
+ </div>
45
+
46
+ ---
47
+
48
+ > **⚠️ NOTE: V0.1.2 ARCHITECTURE UPGRADE!** <br/>
49
+ > Formerly `github-traffic-monitor`, we have officially rebranded to **`gitlytics`**! We completely migrated away from Streamlit. The dashboard is now a **React + Vite** SPA, powered by a **FastAPI** backend!
50
+
51
+ ---
52
+
53
+ <div align="center">
54
+ <img src="https://raw.githubusercontent.com/ameyac11/gitlytics/main/assets/gitlytics_thumbnail_1.png" width="49%" />
55
+ <img src="https://raw.githubusercontent.com/ameyac11/gitlytics/main/assets/gitlytics_thumbnail_2.png" width="49%" />
56
+ </div>
57
+ <div align="center">
58
+ <img src="https://raw.githubusercontent.com/ameyac11/gitlytics/main/assets/gitlytics_thumbnail_3.png" width="98.5%" />
59
+ </div>
60
+
61
+ ---
62
+
63
+ ## 📌 Table of Contents
64
+
65
+ - [🚨 The 14-Day Catch (And How We Fix It)](#the-14-day-catch-and-how-we-fix-it)
66
+ - [🛠️ Installation](#installation)
67
+ - [🔑 Generating a GitHub Personal Access Token](#generating-a-github-personal-access-token)
68
+ - [⌨️ The 3 Core CLI Commands](#the-3-core-cli-commands)
69
+ - [1️⃣ `gitlytics fetch` (Live Terminal Data)](#1-gitlytics-fetch-live-terminal-data)
70
+ - [2️⃣ `gitlytics sync` (Background Database Cron)](#2-gitlytics-sync-background-database-cron)
71
+ - [3️⃣ `gitlytics dashboard` (React Web UI)](#3-gitlytics-dashboard-react-web-ui)
72
+ - [🐍 Native Python API](#native-python-api)
73
+ - [1️⃣ `gitlytics.fetch_traffic()`](#1-gitlyticsfetch_traffic)
74
+ - [2️⃣ `gitlytics.sync()`](#2-gitlyticssync)
75
+ - [3️⃣ `gitlytics.serve_dashboard()`](#3-gitlyticsserve_dashboard)
76
+ - [📊 CSV Output Columns](#csv-output-columns)
77
+ - [🌟 Show Your Support](#show-your-support)
78
+ - [📄 License](#license)
79
+
80
+ ---
81
+
82
+ ## 🚨 The 14-Day Catch (And How We Fix It)
83
+
84
+ > **⚠️ Did you know?** GitHub normally **only saves your repository traffic data for 14 days**. After two weeks, your valuable views and clones data is permanently deleted.
85
+
86
+ **Don't lose your data!** We built a companion automation tool that runs silently in the background every 13 days using GitHub Actions to fetch and save your data permanently.
87
+
88
+ 👉 **[Set up GitHub Traffic Automation here](https://github.com/ameyac11/gitlytics-github-traffic-automation)** (It takes literally 2 minutes to set up!)
89
+
90
+ Once you have your automated CSV data saved from that tool, you can seamlessly plug it right into `gitlytics` to visualize beautiful, long-term historical charts stretching back months or years!
91
+
92
+ ---
93
+
94
+ ## 🛠️ Installation
95
+
96
+ Install via PyPI:
97
+
98
+ ```bash
99
+ # Basic CLI and Python Module installation
100
+ pip install gitlytics
101
+
102
+ # Full installation (includes React Dashboard dependencies)
103
+ pip install "gitlytics[dashboard]"
104
+ ```
105
+
106
+ ### 🔑 Generating a GitHub Personal Access Token
107
+ To use the tools, you'll need a GitHub token.
108
+ 1. Go to **[GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)](https://github.com/settings/tokens)**
109
+ 2. Click **Generate new token (classic)**
110
+ 3. Select the **`repo`** scope *(required to read traffic data for private repositories)*
111
+ 4. Click **Generate token** and copy it!
112
+
113
+ ---
114
+
115
+ ## ⌨️ The 3 Core CLI Commands
116
+
117
+ Gitlytics is powered by 3 massive command-line tools. You can run them anywhere in your terminal.
118
+
119
+ ### 1️⃣ `gitlytics fetch` (Live Terminal Data)
120
+ Fetch your live 14-day traffic and print a beautiful ASCII table directly in your console.
121
+ ```bash
122
+ gitlytics fetch --token ghp_your_token_here --print-table
123
+ ```
124
+
125
+ ### 2️⃣ `gitlytics sync` (Background Database Cron)
126
+ Tired of losing data? Use `sync` to permanently append today's traffic to a CSV database. You can even run it as a background cron job (perfect for Raspberry Pi or Linux/Cloud servers)!
127
+ ```bash
128
+ # Sync once
129
+ gitlytics sync --token ghp_your_token --data-dir ./data
130
+
131
+ # Run permanently in the background as a cron job (runs at 11:00 PM every day)
132
+ gitlytics sync --token ghp_your_token --data-dir ./data --schedule-cron "0 23 * * *"
133
+ ```
134
+
135
+ ### 3️⃣ `gitlytics dashboard` (React Web UI)
136
+ Launch the beautiful React + FastAPI web interface.
137
+ ```bash
138
+ gitlytics dashboard
139
+ ```
140
+ > **📺 Headless TV Mode:** Want to display the dashboard on an office TV monitor? Pass the historical database and token directly so the UI auto-loads without requiring a manual browser login!
141
+ > ```bash
142
+ > gitlytics dashboard --token "ghp_xxx" --data-dir "./data"
143
+ > ```
144
+
145
+ ---
146
+
147
+ ## 🐍 Native Python API
148
+
149
+ You can import Gitlytics natively into your own Python applications to build custom integrations, run custom cron workflows, or serve the dashboard programmatically on your own cloud servers.
150
+
151
+ 📚 **[Read the Full API Documentation](docs/api_documentation.md)**
152
+
153
+ ### 1️⃣ `gitlytics.fetch_traffic()`
154
+ Fetches the last 14 days of traffic data (views, clones, referrers, paths) for one or more repositories.
155
+
156
+ ```python
157
+ import gitlytics
158
+
159
+ # Fetch traffic for all repositories accessible by the token
160
+ df = gitlytics.fetch_traffic(
161
+ token="ghp_your_token",
162
+ return_format="dataframe" # Options: "dataframe" (Pandas), "timeseries" (React Chart-ready dict), or "raw" (JSON API payload)
163
+ )
164
+
165
+ # Fetch traffic for a single specific repository and print the table to stdout
166
+ gitlytics.fetch_traffic(
167
+ token="ghp_your_token",
168
+ repo_name="username/my-repo",
169
+ print_table=True
170
+ )
171
+
172
+ # Save output directly to a file (CSV or JSON depending on file extension)
173
+ gitlytics.fetch_traffic(
174
+ token="ghp_your_token",
175
+ return_format="dataframe",
176
+ save_file="./data/traffic.csv"
177
+ )
178
+ ```
179
+
180
+ #### ⚙️ Parameters:
181
+ | Parameter | Type | Default | Description |
182
+ |---|---|---|---|
183
+ | `token` | `str` | *Required* | GitHub Personal Access Token with `repo` scope enabled. |
184
+ | `repo_name` | `str` | `None` | Specific repository name (e.g. `"user/repo"`). If `None`, fetches all repositories. |
185
+ | `print_table` | `bool` | `False` | If `True`, formats and prints a detailed ASCII traffic table to the console. |
186
+ | `return_format` | `str` | `"dataframe"` | The format of returned data: `"dataframe"` (Pandas DataFrame), `"timeseries"`, or `"raw"`. |
187
+ | `save_file` | `str` | `None` | Optional. File path where the fetched data will be saved (CSV or JSON). |
188
+
189
+ ---
190
+
191
+ ### 2️⃣ `gitlytics.sync()`
192
+ Fetches the live traffic data and appends it to a persistent CSV database. Handles merging overlaps and duplicates. Can be scheduled with an internal cron scheduler for cloud deployments.
193
+
194
+ ```python
195
+ import gitlytics
196
+
197
+ # Standard run: Syncs current snapshots to the CSV database and exports UI JSON
198
+ gitlytics.sync(
199
+ token="ghp_your_token",
200
+ data_dir="./data",
201
+ export_json="./data/export.json",
202
+ export_public_only=True # Security Firewall: Exclude private repos from the public-facing export.json
203
+ )
204
+
205
+ # Scheduled Cloud Worker: Run infinitely using standard cron schedule syntax
206
+ gitlytics.sync(
207
+ token="ghp_your_token",
208
+ data_dir="./data",
209
+ schedule_cron="0 23 * * *", # Runs everyday at 11:00 PM UTC
210
+ export_json="./data/export.json"
211
+ )
212
+ ```
213
+
214
+ #### ⚙️ Parameters:
215
+ | Parameter | Type | Default | Description |
216
+ |---|---|---|---|
217
+ | `token` | `str` | *Required* | GitHub Personal Access Token. |
218
+ | `repo_name` | `str` or `list` | `None` | Specific repository name(s) to sync. If `None`, syncs all repositories. |
219
+ | `data_dir` | `str` | `"./data"` | Directory where CSV files are saved. |
220
+ | `output_mode` | `str` | `"monthly"` | File grouping frequency: `"monthly"` (creates `traffic_YYYY-MM.csv`) or `"yearly"` (creates `traffic_YYYY.csv`). |
221
+ | `schedule_cron` | `str` | `None` | Optional cron expression (e.g., `"*/15 * * * *"`). If set, runs an infinite scheduler loop. |
222
+ | `export_json` | `str` | `None` | Optional. Path to compile and export a consolidated history JSON for the frontend. |
223
+ | `export_public_only` | `bool` | `True` | Security firewall: if `True`, strips private repository data from the compiled `export_json`. |
224
+
225
+ ---
226
+
227
+ ### 3️⃣ `gitlytics.serve_dashboard()`
228
+ Launches the FastAPI backend and hosts the embedded React SPA dashboard.
229
+
230
+ ```python
231
+ import gitlytics
232
+
233
+ # Host the dashboard programmatically on a custom host/port
234
+ gitlytics.serve_dashboard(
235
+ host="0.0.0.0",
236
+ port=8080,
237
+ token="ghp_your_token", # Pre-authenticates the dashboard session
238
+ data_dir="./data" # Folder containing the historical databases
239
+ )
240
+ ```
241
+
242
+ #### ⚙️ Parameters:
243
+ | Parameter | Type | Default | Description |
244
+ |---|---|---|---|
245
+ | `host` | `str` | `"127.0.0.1"` | Host IP to bind the FastAPI server. Use `"0.0.0.0"` to listen on all interfaces. |
246
+ | `port` | `int` | `8000` | Port to run the web server on. |
247
+ | `token` | `str` | `None` | Optional. Pre-authenticates the dashboard session to bypass the login screen. |
248
+ | `data_dir` | `str` | `None` | Optional. Path to the folder containing your synced CSV or JSON databases. |
249
+
250
+ ---
251
+
252
+
253
+ ## 📊 CSV Output Columns
254
+
255
+ When you sync data, the local CSV databases track 13 detailed metrics:
256
+
257
+ | Column | Description | Column | Description |
258
+ |---|---|---|---|
259
+ | `repository` | Full repo name (`user/repo`) | `stars` | Current star count |
260
+ | `is_private` | `True` / `False` | `forks` | Current fork count |
261
+ | `views` | Page views today | `unique_visitors` | Unique visitors today |
262
+ | `clones` | Clone count today | `unique_cloners` | Unique cloners today |
263
+ | `top_referrer` | Highest-traffic referral source | `top_referrer_views` | Views from top referrer |
264
+ | `top_path` | Most visited path | `top_path_views` | Views for top path |
265
+
266
+ ---
267
+
268
+ ## 🌟 Show Your Support
269
+
270
+ If you find this project useful, please consider giving it a ⭐ on [GitHub](https://github.com/ameyac11/gitlytics)! It helps more people discover the tool.
271
+
272
+ ## 📄 License
273
+ Licensed under the [Apache License 2.0](LICENSE).
@@ -0,0 +1,246 @@
1
+ <div align="center">
2
+
3
+ # 📊 Gitlytics
4
+ ### GitHub Traffic Analytics & Automation
5
+
6
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
7
+ [![Python](https://img.shields.io/badge/Python-3.9%2B-blue)](https://www.python.org/)
8
+ [![PyPI](https://img.shields.io/pypi/v/gitlytics?color=blue)](https://pypi.org/project/gitlytics/)
9
+ [![React](https://img.shields.io/badge/UI-React-61dafb?logo=react)](https://react.dev/)
10
+ [![FastAPI](https://img.shields.io/badge/Backend-FastAPI-009688?logo=fastapi)](https://fastapi.tiangolo.com/)
11
+ [![Automation](https://img.shields.io/badge/Data%20Backup-Automation%20Tool-purple?logo=github-actions)](https://github.com/ameyac11/gitlytics-github-traffic-automation)
12
+
13
+ **Beautiful GitHub traffic analytics for all your repositories — public and private.** <br/> Track views, clones, referrers, and popular paths indefinitely.
14
+
15
+ Please consider giving this project a ⭐ if you find it helpful!
16
+
17
+ </div>
18
+
19
+ ---
20
+
21
+ > **⚠️ NOTE: V0.1.2 ARCHITECTURE UPGRADE!** <br/>
22
+ > Formerly `github-traffic-monitor`, we have officially rebranded to **`gitlytics`**! We completely migrated away from Streamlit. The dashboard is now a **React + Vite** SPA, powered by a **FastAPI** backend!
23
+
24
+ ---
25
+
26
+ <div align="center">
27
+ <img src="https://raw.githubusercontent.com/ameyac11/gitlytics/main/assets/gitlytics_thumbnail_1.png" width="49%" />
28
+ <img src="https://raw.githubusercontent.com/ameyac11/gitlytics/main/assets/gitlytics_thumbnail_2.png" width="49%" />
29
+ </div>
30
+ <div align="center">
31
+ <img src="https://raw.githubusercontent.com/ameyac11/gitlytics/main/assets/gitlytics_thumbnail_3.png" width="98.5%" />
32
+ </div>
33
+
34
+ ---
35
+
36
+ ## 📌 Table of Contents
37
+
38
+ - [🚨 The 14-Day Catch (And How We Fix It)](#the-14-day-catch-and-how-we-fix-it)
39
+ - [🛠️ Installation](#installation)
40
+ - [🔑 Generating a GitHub Personal Access Token](#generating-a-github-personal-access-token)
41
+ - [⌨️ The 3 Core CLI Commands](#the-3-core-cli-commands)
42
+ - [1️⃣ `gitlytics fetch` (Live Terminal Data)](#1-gitlytics-fetch-live-terminal-data)
43
+ - [2️⃣ `gitlytics sync` (Background Database Cron)](#2-gitlytics-sync-background-database-cron)
44
+ - [3️⃣ `gitlytics dashboard` (React Web UI)](#3-gitlytics-dashboard-react-web-ui)
45
+ - [🐍 Native Python API](#native-python-api)
46
+ - [1️⃣ `gitlytics.fetch_traffic()`](#1-gitlyticsfetch_traffic)
47
+ - [2️⃣ `gitlytics.sync()`](#2-gitlyticssync)
48
+ - [3️⃣ `gitlytics.serve_dashboard()`](#3-gitlyticsserve_dashboard)
49
+ - [📊 CSV Output Columns](#csv-output-columns)
50
+ - [🌟 Show Your Support](#show-your-support)
51
+ - [📄 License](#license)
52
+
53
+ ---
54
+
55
+ ## 🚨 The 14-Day Catch (And How We Fix It)
56
+
57
+ > **⚠️ Did you know?** GitHub normally **only saves your repository traffic data for 14 days**. After two weeks, your valuable views and clones data is permanently deleted.
58
+
59
+ **Don't lose your data!** We built a companion automation tool that runs silently in the background every 13 days using GitHub Actions to fetch and save your data permanently.
60
+
61
+ 👉 **[Set up GitHub Traffic Automation here](https://github.com/ameyac11/gitlytics-github-traffic-automation)** (It takes literally 2 minutes to set up!)
62
+
63
+ Once you have your automated CSV data saved from that tool, you can seamlessly plug it right into `gitlytics` to visualize beautiful, long-term historical charts stretching back months or years!
64
+
65
+ ---
66
+
67
+ ## 🛠️ Installation
68
+
69
+ Install via PyPI:
70
+
71
+ ```bash
72
+ # Basic CLI and Python Module installation
73
+ pip install gitlytics
74
+
75
+ # Full installation (includes React Dashboard dependencies)
76
+ pip install "gitlytics[dashboard]"
77
+ ```
78
+
79
+ ### 🔑 Generating a GitHub Personal Access Token
80
+ To use the tools, you'll need a GitHub token.
81
+ 1. Go to **[GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)](https://github.com/settings/tokens)**
82
+ 2. Click **Generate new token (classic)**
83
+ 3. Select the **`repo`** scope *(required to read traffic data for private repositories)*
84
+ 4. Click **Generate token** and copy it!
85
+
86
+ ---
87
+
88
+ ## ⌨️ The 3 Core CLI Commands
89
+
90
+ Gitlytics is powered by 3 massive command-line tools. You can run them anywhere in your terminal.
91
+
92
+ ### 1️⃣ `gitlytics fetch` (Live Terminal Data)
93
+ Fetch your live 14-day traffic and print a beautiful ASCII table directly in your console.
94
+ ```bash
95
+ gitlytics fetch --token ghp_your_token_here --print-table
96
+ ```
97
+
98
+ ### 2️⃣ `gitlytics sync` (Background Database Cron)
99
+ Tired of losing data? Use `sync` to permanently append today's traffic to a CSV database. You can even run it as a background cron job (perfect for Raspberry Pi or Linux/Cloud servers)!
100
+ ```bash
101
+ # Sync once
102
+ gitlytics sync --token ghp_your_token --data-dir ./data
103
+
104
+ # Run permanently in the background as a cron job (runs at 11:00 PM every day)
105
+ gitlytics sync --token ghp_your_token --data-dir ./data --schedule-cron "0 23 * * *"
106
+ ```
107
+
108
+ ### 3️⃣ `gitlytics dashboard` (React Web UI)
109
+ Launch the beautiful React + FastAPI web interface.
110
+ ```bash
111
+ gitlytics dashboard
112
+ ```
113
+ > **📺 Headless TV Mode:** Want to display the dashboard on an office TV monitor? Pass the historical database and token directly so the UI auto-loads without requiring a manual browser login!
114
+ > ```bash
115
+ > gitlytics dashboard --token "ghp_xxx" --data-dir "./data"
116
+ > ```
117
+
118
+ ---
119
+
120
+ ## 🐍 Native Python API
121
+
122
+ You can import Gitlytics natively into your own Python applications to build custom integrations, run custom cron workflows, or serve the dashboard programmatically on your own cloud servers.
123
+
124
+ 📚 **[Read the Full API Documentation](docs/api_documentation.md)**
125
+
126
+ ### 1️⃣ `gitlytics.fetch_traffic()`
127
+ Fetches the last 14 days of traffic data (views, clones, referrers, paths) for one or more repositories.
128
+
129
+ ```python
130
+ import gitlytics
131
+
132
+ # Fetch traffic for all repositories accessible by the token
133
+ df = gitlytics.fetch_traffic(
134
+ token="ghp_your_token",
135
+ return_format="dataframe" # Options: "dataframe" (Pandas), "timeseries" (React Chart-ready dict), or "raw" (JSON API payload)
136
+ )
137
+
138
+ # Fetch traffic for a single specific repository and print the table to stdout
139
+ gitlytics.fetch_traffic(
140
+ token="ghp_your_token",
141
+ repo_name="username/my-repo",
142
+ print_table=True
143
+ )
144
+
145
+ # Save output directly to a file (CSV or JSON depending on file extension)
146
+ gitlytics.fetch_traffic(
147
+ token="ghp_your_token",
148
+ return_format="dataframe",
149
+ save_file="./data/traffic.csv"
150
+ )
151
+ ```
152
+
153
+ #### ⚙️ Parameters:
154
+ | Parameter | Type | Default | Description |
155
+ |---|---|---|---|
156
+ | `token` | `str` | *Required* | GitHub Personal Access Token with `repo` scope enabled. |
157
+ | `repo_name` | `str` | `None` | Specific repository name (e.g. `"user/repo"`). If `None`, fetches all repositories. |
158
+ | `print_table` | `bool` | `False` | If `True`, formats and prints a detailed ASCII traffic table to the console. |
159
+ | `return_format` | `str` | `"dataframe"` | The format of returned data: `"dataframe"` (Pandas DataFrame), `"timeseries"`, or `"raw"`. |
160
+ | `save_file` | `str` | `None` | Optional. File path where the fetched data will be saved (CSV or JSON). |
161
+
162
+ ---
163
+
164
+ ### 2️⃣ `gitlytics.sync()`
165
+ Fetches the live traffic data and appends it to a persistent CSV database. Handles merging overlaps and duplicates. Can be scheduled with an internal cron scheduler for cloud deployments.
166
+
167
+ ```python
168
+ import gitlytics
169
+
170
+ # Standard run: Syncs current snapshots to the CSV database and exports UI JSON
171
+ gitlytics.sync(
172
+ token="ghp_your_token",
173
+ data_dir="./data",
174
+ export_json="./data/export.json",
175
+ export_public_only=True # Security Firewall: Exclude private repos from the public-facing export.json
176
+ )
177
+
178
+ # Scheduled Cloud Worker: Run infinitely using standard cron schedule syntax
179
+ gitlytics.sync(
180
+ token="ghp_your_token",
181
+ data_dir="./data",
182
+ schedule_cron="0 23 * * *", # Runs everyday at 11:00 PM UTC
183
+ export_json="./data/export.json"
184
+ )
185
+ ```
186
+
187
+ #### ⚙️ Parameters:
188
+ | Parameter | Type | Default | Description |
189
+ |---|---|---|---|
190
+ | `token` | `str` | *Required* | GitHub Personal Access Token. |
191
+ | `repo_name` | `str` or `list` | `None` | Specific repository name(s) to sync. If `None`, syncs all repositories. |
192
+ | `data_dir` | `str` | `"./data"` | Directory where CSV files are saved. |
193
+ | `output_mode` | `str` | `"monthly"` | File grouping frequency: `"monthly"` (creates `traffic_YYYY-MM.csv`) or `"yearly"` (creates `traffic_YYYY.csv`). |
194
+ | `schedule_cron` | `str` | `None` | Optional cron expression (e.g., `"*/15 * * * *"`). If set, runs an infinite scheduler loop. |
195
+ | `export_json` | `str` | `None` | Optional. Path to compile and export a consolidated history JSON for the frontend. |
196
+ | `export_public_only` | `bool` | `True` | Security firewall: if `True`, strips private repository data from the compiled `export_json`. |
197
+
198
+ ---
199
+
200
+ ### 3️⃣ `gitlytics.serve_dashboard()`
201
+ Launches the FastAPI backend and hosts the embedded React SPA dashboard.
202
+
203
+ ```python
204
+ import gitlytics
205
+
206
+ # Host the dashboard programmatically on a custom host/port
207
+ gitlytics.serve_dashboard(
208
+ host="0.0.0.0",
209
+ port=8080,
210
+ token="ghp_your_token", # Pre-authenticates the dashboard session
211
+ data_dir="./data" # Folder containing the historical databases
212
+ )
213
+ ```
214
+
215
+ #### ⚙️ Parameters:
216
+ | Parameter | Type | Default | Description |
217
+ |---|---|---|---|
218
+ | `host` | `str` | `"127.0.0.1"` | Host IP to bind the FastAPI server. Use `"0.0.0.0"` to listen on all interfaces. |
219
+ | `port` | `int` | `8000` | Port to run the web server on. |
220
+ | `token` | `str` | `None` | Optional. Pre-authenticates the dashboard session to bypass the login screen. |
221
+ | `data_dir` | `str` | `None` | Optional. Path to the folder containing your synced CSV or JSON databases. |
222
+
223
+ ---
224
+
225
+
226
+ ## 📊 CSV Output Columns
227
+
228
+ When you sync data, the local CSV databases track 13 detailed metrics:
229
+
230
+ | Column | Description | Column | Description |
231
+ |---|---|---|---|
232
+ | `repository` | Full repo name (`user/repo`) | `stars` | Current star count |
233
+ | `is_private` | `True` / `False` | `forks` | Current fork count |
234
+ | `views` | Page views today | `unique_visitors` | Unique visitors today |
235
+ | `clones` | Clone count today | `unique_cloners` | Unique cloners today |
236
+ | `top_referrer` | Highest-traffic referral source | `top_referrer_views` | Views from top referrer |
237
+ | `top_path` | Most visited path | `top_path_views` | Views for top path |
238
+
239
+ ---
240
+
241
+ ## 🌟 Show Your Support
242
+
243
+ If you find this project useful, please consider giving it a ⭐ on [GitHub](https://github.com/ameyac11/gitlytics)! It helps more people discover the tool.
244
+
245
+ ## 📄 License
246
+ Licensed under the [Apache License 2.0](LICENSE).
@@ -4,14 +4,19 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "gitlytics"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "Monitor and automate your GitHub repository traffic analytics."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [
13
+ { name = "Ameya Chopade" }
14
+ ]
11
15
  dependencies = [
12
16
  "requests",
13
17
  "pandas",
14
- "python-dotenv"
18
+ "python-dotenv",
19
+ "croniter"
15
20
  ]
16
21
  keywords = [
17
22
  "github",
@@ -26,6 +31,9 @@ classifiers = [
26
31
  "Operating System :: OS Independent",
27
32
  ]
28
33
 
34
+ [project.urls]
35
+ Homepage = "https://github.com/ameyac11/gitlytics"
36
+
29
37
  [project.optional-dependencies]
30
38
  dashboard = ["fastapi", "uvicorn", "python-multipart"]
31
39
  dev = [
@@ -34,10 +42,11 @@ dev = [
34
42
  ]
35
43
 
36
44
  [project.scripts]
37
- gitlytics = "github_traffic.cli:main"
45
+ gitlytics = "gitlytics.cli:main"
38
46
 
39
47
  [tool.setuptools.packages.find]
40
- include = ["github_traffic*"]
48
+ where = ["src"]
49
+ include = ["gitlytics*"]
41
50
 
42
51
  [tool.setuptools.package-data]
43
- "github_traffic" = ["frontend/dist/**/*", "frontend/dist/*"]
52
+ "gitlytics" = ["static/**/*", "static/*"]
@@ -0,0 +1,73 @@
1
+ """
2
+ gitlytics/__init__.py
3
+ The public API for the gitlytics package.
4
+ """
5
+ import os
6
+ import sys
7
+ import logging
8
+ import json
9
+ import uvicorn
10
+ from .core import fetch_traffic_data, print_repo_table
11
+ from .automation import run_sync
12
+ from .process import build_json_payload
13
+
14
+ # Configure standard python logging
15
+ logging.basicConfig(
16
+ level=logging.INFO,
17
+ format='[%(asctime)s] %(levelname)s: %(message)s',
18
+ datefmt='%Y-%m-%d %H:%M:%S',
19
+ handlers=[logging.StreamHandler(sys.stdout)]
20
+ )
21
+
22
+ def fetch_traffic(token: str, repo_name=None, print_table: bool = False, return_format: str = "dataframe", save_file: str = None):
23
+ """
24
+ Fetches the last 14 days of traffic data for one or all repositories.
25
+ """
26
+ df = fetch_traffic_data(token, repo_name)
27
+
28
+ if print_table:
29
+ print_repo_table(df)
30
+
31
+ if return_format == "dataframe":
32
+ if save_file:
33
+ if save_file.endswith(".json"):
34
+ payload = build_json_payload(df, return_format="timeseries", export_public_only=True)
35
+ with open(save_file, "w", encoding="utf-8") as f:
36
+ json.dump(payload, f, indent=2)
37
+ else:
38
+ df.to_csv(save_file, index=False)
39
+ return df
40
+
41
+ # Return JSON payloads
42
+ payload = build_json_payload(df, return_format=return_format, export_public_only=False)
43
+ if save_file:
44
+ with open(save_file, "w", encoding="utf-8") as f:
45
+ json.dump(payload, f, indent=2)
46
+
47
+ return payload
48
+
49
+ def sync(token: str, repo_name=None, data_dir: str = "./data", output_mode: str = "monthly", schedule_cron: str = None, export_json: str = None, export_public_only: bool = True):
50
+ """
51
+ Fetches data and appends it to a local CSV database, optionally running as a permanent background daemon.
52
+ """
53
+ run_sync(
54
+ token=token,
55
+ repo_names=repo_name,
56
+ data_dir=data_dir,
57
+ output_mode=output_mode,
58
+ schedule_cron=schedule_cron,
59
+ export_json=export_json,
60
+ export_public_only=export_public_only
61
+ )
62
+
63
+ def serve_dashboard(host: str = "127.0.0.1", port: int = 8000, token: str = None, data_dir: str = None):
64
+ """
65
+ Starts the React + FastAPI dashboard server.
66
+ """
67
+ # We pass token and data_dir through environment variables so api.py can read them
68
+ if token:
69
+ os.environ["GITLYTICS_TOKEN"] = token
70
+ if data_dir:
71
+ os.environ["GITLYTICS_DATA_DIR"] = os.path.abspath(data_dir)
72
+
73
+ uvicorn.run("gitlytics.api:app", host=host, port=port, reload=False)