gitlytics 0.1.1__tar.gz → 0.1.3__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 (50) hide show
  1. gitlytics-0.1.3/PKG-INFO +278 -0
  2. gitlytics-0.1.3/README.md +246 -0
  3. gitlytics-0.1.3/pyproject.toml +74 -0
  4. gitlytics-0.1.3/src/gitlytics/__init__.py +140 -0
  5. gitlytics-0.1.3/src/gitlytics/__main__.py +9 -0
  6. gitlytics-0.1.3/src/gitlytics/api.py +177 -0
  7. gitlytics-0.1.3/src/gitlytics/automation.py +217 -0
  8. gitlytics-0.1.3/src/gitlytics/cli.py +122 -0
  9. gitlytics-0.1.3/src/gitlytics/core.py +288 -0
  10. gitlytics-0.1.3/src/gitlytics/process.py +237 -0
  11. gitlytics-0.1.3/src/gitlytics/static/assets/index-B5LHR_NK.js +44 -0
  12. gitlytics-0.1.3/src/gitlytics/static/assets/index-Cbu2tSV_.css +2 -0
  13. gitlytics-0.1.3/src/gitlytics/static/favicon.svg +4 -0
  14. {gitlytics-0.1.1/github_traffic/frontend/dist → gitlytics-0.1.3/src/gitlytics/static}/index.html +4 -4
  15. gitlytics-0.1.3/src/gitlytics.egg-info/PKG-INFO +278 -0
  16. gitlytics-0.1.3/src/gitlytics.egg-info/SOURCES.txt +26 -0
  17. gitlytics-0.1.3/src/gitlytics.egg-info/entry_points.txt +2 -0
  18. gitlytics-0.1.3/src/gitlytics.egg-info/requires.txt +16 -0
  19. gitlytics-0.1.3/src/gitlytics.egg-info/top_level.txt +1 -0
  20. gitlytics-0.1.3/tests/test_api.py +264 -0
  21. gitlytics-0.1.3/tests/test_automation.py +178 -0
  22. gitlytics-0.1.3/tests/test_cli.py +130 -0
  23. gitlytics-0.1.3/tests/test_core.py +226 -0
  24. gitlytics-0.1.3/tests/test_process.py +321 -0
  25. gitlytics-0.1.1/PKG-INFO +0 -201
  26. gitlytics-0.1.1/README.md +0 -178
  27. gitlytics-0.1.1/github_traffic/__init__.py +0 -4
  28. gitlytics-0.1.1/github_traffic/api.py +0 -76
  29. gitlytics-0.1.1/github_traffic/automation.py +0 -122
  30. gitlytics-0.1.1/github_traffic/cli.py +0 -154
  31. gitlytics-0.1.1/github_traffic/core.py +0 -147
  32. gitlytics-0.1.1/github_traffic/frontend/dist/assets/axios-BATw4G7Y.js +0 -9
  33. gitlytics-0.1.1/github_traffic/frontend/dist/assets/index-BJy89P_N.js +0 -44
  34. gitlytics-0.1.1/github_traffic/frontend/dist/assets/index-DHekp9vT.css +0 -1
  35. gitlytics-0.1.1/github_traffic/frontend/dist/favicon.svg +0 -1
  36. gitlytics-0.1.1/github_traffic/frontend/node_modules/flatted/python/flatted.py +0 -144
  37. gitlytics-0.1.1/github_traffic/process.py +0 -43
  38. gitlytics-0.1.1/gitlytics.egg-info/PKG-INFO +0 -201
  39. gitlytics-0.1.1/gitlytics.egg-info/SOURCES.txt +0 -25
  40. gitlytics-0.1.1/gitlytics.egg-info/entry_points.txt +0 -2
  41. gitlytics-0.1.1/gitlytics.egg-info/requires.txt +0 -12
  42. gitlytics-0.1.1/gitlytics.egg-info/top_level.txt +0 -1
  43. gitlytics-0.1.1/pyproject.toml +0 -43
  44. gitlytics-0.1.1/tests/test_automation.py +0 -72
  45. gitlytics-0.1.1/tests/test_cli.py +0 -56
  46. gitlytics-0.1.1/tests/test_core.py +0 -55
  47. {gitlytics-0.1.1 → gitlytics-0.1.3}/LICENSE +0 -0
  48. {gitlytics-0.1.1 → gitlytics-0.1.3}/setup.cfg +0 -0
  49. {gitlytics-0.1.1/github_traffic/frontend/dist → gitlytics-0.1.3/src/gitlytics/static}/icons.svg +0 -0
  50. {gitlytics-0.1.1 → gitlytics-0.1.3/src}/gitlytics.egg-info/dependency_links.txt +0 -0
@@ -0,0 +1,278 @@
1
+ Metadata-Version: 2.4
2
+ Name: gitlytics
3
+ Version: 0.1.3
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
+ Project-URL: Repository, https://github.com/ameyac11/gitlytics
9
+ Project-URL: Bug Tracker, https://github.com/ameyac11/gitlytics/issues
10
+ Keywords: github,traffic,analytics,automation,cli
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: requests>=2.32.0
18
+ Requires-Dist: pandas>=2.2.0
19
+ Requires-Dist: python-dotenv>=1.0.1
20
+ Requires-Dist: croniter>=2.0.0
21
+ Provides-Extra: dashboard
22
+ Requires-Dist: fastapi>=0.111.0; extra == "dashboard"
23
+ Requires-Dist: uvicorn>=0.30.0; extra == "dashboard"
24
+ Requires-Dist: python-multipart>=0.0.9; extra == "dashboard"
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
27
+ Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
28
+ Requires-Dist: httpx>=0.27.0; extra == "dev"
29
+ Requires-Dist: Faker>=20.0.0; extra == "dev"
30
+ Requires-Dist: anyio[trio]>=4.0.0; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ <div align="center">
34
+
35
+ # 📊 Gitlytics
36
+ ### GitHub Traffic Analytics & Automation
37
+
38
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
39
+ [![Python](https://img.shields.io/badge/Python-3.9%2B-blue)](https://www.python.org/)
40
+ [![PyPI](https://img.shields.io/pypi/v/gitlytics?color=blue)](https://pypi.org/project/gitlytics/)
41
+ [![React](https://img.shields.io/badge/UI-React-61dafb?logo=react)](https://react.dev/)
42
+ [![FastAPI](https://img.shields.io/badge/Backend-FastAPI-009688?logo=fastapi)](https://fastapi.tiangolo.com/)
43
+ [![Automation](https://img.shields.io/badge/Data%20Backup-Automation%20Tool-purple?logo=github-actions)](https://github.com/ameyac11/gitlytics-github-traffic-automation)
44
+
45
+ **Beautiful GitHub traffic analytics for all your repositories — public and private.** <br/> Track views, clones, referrers, and popular paths indefinitely.
46
+
47
+ Please consider giving this project a ⭐ if you find it helpful!
48
+
49
+ </div>
50
+
51
+ ---
52
+
53
+ > **⚠️ NOTE: V0.1.2 ARCHITECTURE UPGRADE!** <br/>
54
+ > 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!
55
+
56
+ ---
57
+
58
+ <div align="center">
59
+ <img src="https://raw.githubusercontent.com/ameyac11/gitlytics/main/assets/gitlytics_thumbnail_1.png" width="49%" />
60
+ <img src="https://raw.githubusercontent.com/ameyac11/gitlytics/main/assets/gitlytics_thumbnail_2.png" width="49%" />
61
+ </div>
62
+ <div align="center">
63
+ <img src="https://raw.githubusercontent.com/ameyac11/gitlytics/main/assets/gitlytics_thumbnail_3.png" width="98.5%" />
64
+ </div>
65
+
66
+ ---
67
+
68
+ ## 📌 Table of Contents
69
+
70
+ - [🚨 The 14-Day Catch (And How We Fix It)](#the-14-day-catch-and-how-we-fix-it)
71
+ - [🛠️ Installation](#installation)
72
+ - [🔑 Generating a GitHub Personal Access Token](#generating-a-github-personal-access-token)
73
+ - [⌨️ The 3 Core CLI Commands](#the-3-core-cli-commands)
74
+ - [1️⃣ `gitlytics fetch` (Live Terminal Data)](#1-gitlytics-fetch-live-terminal-data)
75
+ - [2️⃣ `gitlytics sync` (Background Database Cron)](#2-gitlytics-sync-background-database-cron)
76
+ - [3️⃣ `gitlytics dashboard` (React Web UI)](#3-gitlytics-dashboard-react-web-ui)
77
+ - [🐍 Native Python API](#native-python-api)
78
+ - [1️⃣ `gitlytics.fetch_traffic()`](#1-gitlyticsfetch_traffic)
79
+ - [2️⃣ `gitlytics.sync()`](#2-gitlyticssync)
80
+ - [3️⃣ `gitlytics.serve_dashboard()`](#3-gitlyticsserve_dashboard)
81
+ - [📊 CSV Output Columns](#csv-output-columns)
82
+ - [🌟 Show Your Support](#show-your-support)
83
+ - [📄 License](#license)
84
+
85
+ ---
86
+
87
+ ## 🚨 The 14-Day Catch (And How We Fix It)
88
+
89
+ > **⚠️ 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.
90
+
91
+ **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.
92
+
93
+ 👉 **[Set up GitHub Traffic Automation here](https://github.com/ameyac11/gitlytics-github-traffic-automation)** (It takes literally 2 minutes to set up!)
94
+
95
+ 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!
96
+
97
+ ---
98
+
99
+ ## 🛠️ Installation
100
+
101
+ Install via PyPI:
102
+
103
+ ```bash
104
+ # Basic CLI and Python Module installation
105
+ pip install gitlytics
106
+
107
+ # Full installation (includes React Dashboard dependencies)
108
+ pip install "gitlytics[dashboard]"
109
+ ```
110
+
111
+ ### 🔑 Generating a GitHub Personal Access Token
112
+ To use the tools, you'll need a GitHub token.
113
+ 1. Go to **[GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)](https://github.com/settings/tokens)**
114
+ 2. Click **Generate new token (classic)**
115
+ 3. Select the **`repo`** scope *(required to read traffic data for private repositories)*
116
+ 4. Click **Generate token** and copy it!
117
+
118
+ ---
119
+
120
+ ## ⌨️ The 3 Core CLI Commands
121
+
122
+ Gitlytics is powered by 3 massive command-line tools. You can run them anywhere in your terminal.
123
+
124
+ ### 1️⃣ `gitlytics fetch` (Live Terminal Data)
125
+ Fetch your live 14-day traffic and print a beautiful ASCII table directly in your console.
126
+ ```bash
127
+ gitlytics fetch --token ghp_your_token_here --print-table
128
+ ```
129
+
130
+ ### 2️⃣ `gitlytics sync` (Background Database Cron)
131
+ 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)!
132
+ ```bash
133
+ # Sync once
134
+ gitlytics sync --token ghp_your_token --data-dir ./data
135
+
136
+ # Run permanently in the background as a cron job (runs at 11:00 PM every day)
137
+ gitlytics sync --token ghp_your_token --data-dir ./data --schedule-cron "0 23 * * *"
138
+ ```
139
+
140
+ ### 3️⃣ `gitlytics dashboard` (React Web UI)
141
+ Launch the beautiful React + FastAPI web interface.
142
+ ```bash
143
+ gitlytics dashboard
144
+ ```
145
+ > **📺 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!
146
+ > ```bash
147
+ > gitlytics dashboard --token "ghp_xxx" --data-dir "./data"
148
+ > ```
149
+
150
+ ---
151
+
152
+ ## 🐍 Native Python API
153
+
154
+ 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.
155
+
156
+ 📚 **[Read the Full API Documentation](docs/api_documentation.md)**
157
+
158
+ ### 1️⃣ `gitlytics.fetch_traffic()`
159
+ Fetches the last 14 days of traffic data (views, clones, referrers, paths) for one or more repositories.
160
+
161
+ ```python
162
+ import gitlytics
163
+
164
+ # Fetch traffic for all repositories accessible by the token
165
+ df = gitlytics.fetch_traffic(
166
+ token="ghp_your_token",
167
+ return_format="dataframe" # Options: "dataframe" (Pandas), "timeseries" (chart-ready dict), or "summary" (per-repo totals dict)
168
+ )
169
+
170
+ # Fetch traffic for a single specific repository and print the table to stdout
171
+ gitlytics.fetch_traffic(
172
+ token="ghp_your_token",
173
+ repo_name="username/my-repo",
174
+ print_table=True
175
+ )
176
+
177
+ # Save output directly to a file (CSV or JSON depending on file extension)
178
+ gitlytics.fetch_traffic(
179
+ token="ghp_your_token",
180
+ return_format="dataframe",
181
+ save_file="./data/traffic.csv"
182
+ )
183
+ ```
184
+
185
+ #### ⚙️ Parameters:
186
+ | Parameter | Type | Default | Description |
187
+ |---|---|---|---|
188
+ | `token` | `str` | *Required* | GitHub Personal Access Token with `repo` scope enabled. |
189
+ | `repo_name` | `str` | `None` | Specific repository name (e.g. `"user/repo"`). If `None`, fetches all repositories. |
190
+ | `print_table` | `bool` | `False` | If `True`, formats and prints a detailed ASCII traffic table to the console. |
191
+ | `return_format` | `str` | `"dataframe"` | The format of returned data: `"dataframe"` (Pandas DataFrame), `"timeseries"` (chart-ready nested dict), or `"summary"` (per-repo totals dict). |
192
+ | `save_file` | `str` | `None` | Optional. File path where the fetched data will be saved (CSV or JSON). |
193
+
194
+ ---
195
+
196
+ ### 2️⃣ `gitlytics.sync()`
197
+ 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.
198
+
199
+ ```python
200
+ import gitlytics
201
+
202
+ # Standard run: Syncs current snapshots to the CSV database and exports UI JSON
203
+ gitlytics.sync(
204
+ token="ghp_your_token",
205
+ data_dir="./data",
206
+ export_json="./data/export.json",
207
+ export_public_only=True # Security Firewall: Exclude private repos from the public-facing export.json
208
+ )
209
+
210
+ # Scheduled Cloud Worker: Run infinitely using standard cron schedule syntax
211
+ gitlytics.sync(
212
+ token="ghp_your_token",
213
+ data_dir="./data",
214
+ schedule_cron="0 23 * * *", # Runs everyday at 11:00 PM UTC
215
+ export_json="./data/export.json"
216
+ )
217
+ ```
218
+
219
+ #### ⚙️ Parameters:
220
+ | Parameter | Type | Default | Description |
221
+ |---|---|---|---|
222
+ | `token` | `str` | *Required* | GitHub Personal Access Token. |
223
+ | `repo_name` | `str` or `list` | `None` | Specific repository name(s) to sync. If `None`, syncs all repositories. |
224
+ | `data_dir` | `str` | `"./data"` | Directory where CSV files are saved. |
225
+ | `output_mode` | `str` | `"monthly"` | File grouping frequency: `"monthly"` (creates `traffic_YYYY-MM.csv`) or `"yearly"` (creates `traffic_YYYY.csv`). |
226
+ | `schedule_cron` | `str` | `None` | Optional cron expression (e.g., `"*/15 * * * *"`). If set, runs an infinite scheduler loop. |
227
+ | `export_json` | `str` | `None` | Optional. Path to compile and export a consolidated history JSON for the frontend. |
228
+ | `export_public_only` | `bool` | `True` | Security firewall: if `True`, strips private repository data from the compiled `export_json`. |
229
+
230
+ ---
231
+
232
+ ### 3️⃣ `gitlytics.serve_dashboard()`
233
+ Launches the FastAPI backend and hosts the embedded React SPA dashboard.
234
+
235
+ ```python
236
+ import gitlytics
237
+
238
+ # Host the dashboard programmatically on a custom host/port
239
+ gitlytics.serve_dashboard(
240
+ host="0.0.0.0",
241
+ port=8080,
242
+ token="ghp_your_token", # Pre-authenticates the dashboard session
243
+ data_dir="./data" # Folder containing the historical databases
244
+ )
245
+ ```
246
+
247
+ #### ⚙️ Parameters:
248
+ | Parameter | Type | Default | Description |
249
+ |---|---|---|---|
250
+ | `host` | `str` | `"127.0.0.1"` | Host IP to bind the FastAPI server. Use `"0.0.0.0"` to listen on all interfaces. |
251
+ | `port` | `int` | `8000` | Port to run the web server on. |
252
+ | `token` | `str` | `None` | Optional. Pre-authenticates the dashboard session to bypass the login screen. |
253
+ | `data_dir` | `str` | `None` | Optional. Path to the folder containing your synced CSV or JSON databases. |
254
+
255
+ ---
256
+
257
+
258
+ ## 📊 CSV Output Columns
259
+
260
+ When you sync data, the local CSV databases track 13 detailed metrics:
261
+
262
+ | Column | Description | Column | Description |
263
+ |---|---|---|---|
264
+ | `repository` | Full repo name (`user/repo`) | `stars` | Current star count |
265
+ | `is_private` | `True` / `False` | `forks` | Current fork count |
266
+ | `views` | Page views today | `unique_visitors` | Unique visitors today |
267
+ | `clones` | Clone count today | `unique_cloners` | Unique cloners today |
268
+ | `top_referrer` | Highest-traffic referral source | `top_referrer_views` | Views from top referrer |
269
+ | `top_path` | Most visited path | `top_path_views` | Views for top path |
270
+
271
+ ---
272
+
273
+ ## 🌟 Show Your Support
274
+
275
+ 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.
276
+
277
+ ## 📄 License
278
+ 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" (chart-ready dict), or "summary" (per-repo totals dict)
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"` (chart-ready nested dict), or `"summary"` (per-repo totals dict). |
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).
@@ -0,0 +1,74 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "gitlytics"
7
+ version = "0.1.3"
8
+ description = "Monitor and automate your GitHub repository traffic analytics."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [
13
+ { name = "Ameya Chopade" }
14
+ ]
15
+ # Fix #20: Add version lower-bounds to prevent silent breakage on old environments.
16
+ # These match the constraints already documented in requirements.txt.
17
+ dependencies = [
18
+ "requests>=2.32.0",
19
+ "pandas>=2.2.0",
20
+ "python-dotenv>=1.0.1",
21
+ "croniter>=2.0.0"
22
+ ]
23
+ keywords = [
24
+ "github",
25
+ "traffic",
26
+ "analytics",
27
+ "automation",
28
+ "cli"
29
+ ]
30
+ classifiers = [
31
+ "Programming Language :: Python :: 3",
32
+ "License :: OSI Approved :: Apache Software License",
33
+ "Operating System :: OS Independent",
34
+ ]
35
+
36
+ [project.urls]
37
+ Homepage = "https://github.com/ameyac11/gitlytics"
38
+ Repository = "https://github.com/ameyac11/gitlytics"
39
+ "Bug Tracker" = "https://github.com/ameyac11/gitlytics/issues"
40
+
41
+ [project.optional-dependencies]
42
+ # Fix #20: dashboard extras are optional — base package works without them.
43
+ # requirements.txt was including them as mandatory; that was wrong.
44
+ dashboard = [
45
+ "fastapi>=0.111.0",
46
+ "uvicorn>=0.30.0",
47
+ "python-multipart>=0.0.9"
48
+ ]
49
+ dev = [
50
+ "pytest>=8.0.0",
51
+ "pytest-cov>=5.0.0",
52
+ "httpx>=0.27.0", # required by FastAPI TestClient (used in test_api.py)
53
+ "Faker>=20.0.0", # used by pytest-faker plugin for generating test data
54
+ "anyio[trio]>=4.0.0" # async test support
55
+ ]
56
+
57
+
58
+ [project.scripts]
59
+ gitlytics = "gitlytics.cli:main"
60
+
61
+ [tool.setuptools.packages.find]
62
+ where = ["src"]
63
+ include = ["gitlytics*"]
64
+
65
+ [tool.setuptools.package-data]
66
+ "gitlytics" = ["static/**/*", "static/*"]
67
+
68
+ [tool.pytest.ini_options]
69
+ # Only collect files that match the offline test naming convention.
70
+ # live_*.py scripts are excluded — they need a real GitHub token.
71
+ testpaths = ["tests"]
72
+ python_files = ["test_*.py"]
73
+ python_classes = ["Test*"]
74
+ python_functions = ["test_*"]