syscu-kiro-report-usage 0.1.0__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.
- syscu_kiro_report_usage-0.1.0/LICENSE +25 -0
- syscu_kiro_report_usage-0.1.0/PKG-INFO +129 -0
- syscu_kiro_report_usage-0.1.0/README.md +110 -0
- syscu_kiro_report_usage-0.1.0/pyproject.toml +43 -0
- syscu_kiro_report_usage-0.1.0/setup.cfg +4 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/__init__.py +3 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/__main__.py +3 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/activity.py +224 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/assets/Figtree-Variable.woff2 +0 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/assets/NOTICE.md +9 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/assets/logo-dark.svg +13 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/assets/logo-light.svg +13 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/aws.py +104 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/cli.py +364 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/cur.py +192 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/demo.py +79 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/identity.py +33 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/ids.py +18 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/model.py +177 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/periods.py +90 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/render.py +96 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/sso_flow.py +146 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/templates/report.html +508 -0
- syscu_kiro_report_usage-0.1.0/src/kiro_report/tiers.py +72 -0
- syscu_kiro_report_usage-0.1.0/src/syscu_kiro_report_usage.egg-info/PKG-INFO +129 -0
- syscu_kiro_report_usage-0.1.0/src/syscu_kiro_report_usage.egg-info/SOURCES.txt +34 -0
- syscu_kiro_report_usage-0.1.0/src/syscu_kiro_report_usage.egg-info/dependency_links.txt +1 -0
- syscu_kiro_report_usage-0.1.0/src/syscu_kiro_report_usage.egg-info/entry_points.txt +2 -0
- syscu_kiro_report_usage-0.1.0/src/syscu_kiro_report_usage.egg-info/requires.txt +7 -0
- syscu_kiro_report_usage-0.1.0/src/syscu_kiro_report_usage.egg-info/top_level.txt +1 -0
- syscu_kiro_report_usage-0.1.0/tests/test_activity.py +128 -0
- syscu_kiro_report_usage-0.1.0/tests/test_cli_render_aws.py +188 -0
- syscu_kiro_report_usage-0.1.0/tests/test_cur_model.py +199 -0
- syscu_kiro_report_usage-0.1.0/tests/test_periods.py +72 -0
- syscu_kiro_report_usage-0.1.0/tests/test_sso_flow.py +184 -0
- syscu_kiro_report_usage-0.1.0/tests/test_tiers.py +39 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kiro-usage-report contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
Note: the logo files in src/kiro_report/assets/ (logo-light.svg, logo-dark.svg) are
|
|
24
|
+
SysCu brand assets and are NOT covered by this license. The bundled Figtree font is
|
|
25
|
+
distributed under the SIL Open Font License 1.1 (see src/kiro_report/assets/NOTICE.md).
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: syscu-kiro-report-usage
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Self-contained HTML report of Kiro usage and cost per IAM Identity Center user (AWS CUR + Kiro user activity report).
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/syscu-es/syscu-kiro-report-usage
|
|
7
|
+
Project-URL: Issues, https://github.com/syscu-es/syscu-kiro-report-usage/issues
|
|
8
|
+
Keywords: kiro,aws,finops,cost,usage,report,iam-identity-center
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: boto3>=1.34
|
|
13
|
+
Requires-Dist: pyarrow>=14
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
16
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
17
|
+
Requires-Dist: ruff>=0.5; extra == "dev"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# kiro-usage-report
|
|
21
|
+
|
|
22
|
+
Generate a **single, self-contained HTML report** of [Kiro](https://kiro.dev) usage and cost **per IAM Identity Center user** — one command, no infrastructure to deploy.
|
|
23
|
+
|
|
24
|
+

|
|
25
|
+
|
|
26
|
+
It answers the questions Kiro administrators keep asking:
|
|
27
|
+
|
|
28
|
+
- Who is using Kiro, on which client (IDE / CLI / Web), and with which models?
|
|
29
|
+
- Credits used per day / week / month, by client type and by plan — the same views as the Kiro console dashboard, plus per-person detail.
|
|
30
|
+
- What do the subscriptions cost, and how much of it is covered by AWS credits?
|
|
31
|
+
- Who is on the wrong plan? Right-sizing suggestions include overage cost ($0.04/credit).
|
|
32
|
+
- Which licences are idle?
|
|
33
|
+
|
|
34
|
+
The output is a static `.html` file (light/dark theme, English/Spanish, date-range and daily/weekly/monthly filters, tooltips, print-friendly). Share it as an attachment; nothing is uploaded anywhere.
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install syscu-kiro-report-usage # from PyPI
|
|
40
|
+
pip install git+https://github.com/syscu-es/syscu-kiro-report-usage.git # latest from GitHub
|
|
41
|
+
# or from a clone: pip install . (development: pip install -e ".[dev]")
|
|
42
|
+
|
|
43
|
+
kiro-report --demo --open # preview with synthetic data, no AWS needed
|
|
44
|
+
kiro-report # interactive: pick or sign in to ANY AWS account, then the period
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Unattended:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
kiro-report --profile my-sso-profile --sso-login --last 6 --out kiro.html
|
|
51
|
+
kiro-report --profile prod --month 2026-10 --lang en --anonymize
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Works against any account, interactively
|
|
55
|
+
|
|
56
|
+
Run `kiro-report` on a terminal and it asks, step by step:
|
|
57
|
+
|
|
58
|
+
1. **Account** — choose one of your local profiles (`~/.aws/config` / `~/.aws/credentials`), the default credential chain, or **“Sign in with AWS IAM Identity Center”**.
|
|
59
|
+
2. **IAM Identity Center sign-in (no profile needed)** — enter your start URL (`https://<name>.awsapps.com/start`) and region, approve in the browser (device authorization, the same flow as `aws sso login`), then pick any **account** and **role** you can reach (type text to filter long lists). Tokens and temporary credentials stay in memory; nothing is written to disk.
|
|
60
|
+
3. **Period** — last full month, current month, last 3/6/12 months, or a custom `YYYY-MM[:YYYY-MM]` range.
|
|
61
|
+
|
|
62
|
+
For an existing SSO *profile* with an expired session it offers to run `aws sso login` for you (`--sso-login` does it without asking). Everything is also scriptable: `--sso-start-url … --sso-account <id|name> --sso-role <name>`; `-y/--yes` never prompts. Set `KIRO_REPORT_SSO_START_URL` to pre-fill the start URL.
|
|
63
|
+
|
|
64
|
+
## Where the data comes from
|
|
65
|
+
|
|
66
|
+
| Source | Gives you | How to enable |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| **Kiro user activity report** (daily CSVs in S3) | client type (IDE/CLI/Web), plan, credits, **overage**, messages, models, user e-mail, new users | Kiro console → *Settings* → *User activity report* → CSV → S3 bucket. [Docs](https://kiro.dev/docs/enterprise/monitor-and-track/user-activity/) |
|
|
69
|
+
| **AWS Cost and Usage Report** (Data Exports, parquet) | real subscription lines, AWS credits applied, credits per Identity Center user (`line_item_resource_id`) | Billing → Data Exports → *Standard data export (CUR 2.0)* with resource IDs, parquet |
|
|
70
|
+
| **IAM Identity Center** | user names when the activity report has no e-mail | automatic |
|
|
71
|
+
|
|
72
|
+
Either source can be missing: with only the activity report, costs are *estimated at list price*; with only the CUR you get per-person credits and costs but no client/plan/model breakdown (the report tells you how to enable the rest). Sources are auto-discovered; override with `--cur-export`, `--cur-bucket/--cur-prefix`, `--activity-bucket/--activity-prefix`.
|
|
73
|
+
|
|
74
|
+
Required AWS permissions are read-only — see [docs/PERMISSIONS.md](docs/PERMISSIONS.md).
|
|
75
|
+
|
|
76
|
+
## Options
|
|
77
|
+
|
|
78
|
+
| Flag | Purpose |
|
|
79
|
+
|---|---|
|
|
80
|
+
| `--profile`, `--region`, `--sso-login` | pick a local profile; refresh an expired SSO session |
|
|
81
|
+
| `--sso-start-url`, `--sso-region`, `--sso-account`, `--sso-role` | sign in to any account through IAM Identity Center, no profile needed |
|
|
82
|
+
| `--month`, `--since`/`--until`, `--last N` | period (default: last 3 months, or asked) |
|
|
83
|
+
| `--no-cur`, `--no-activity` | skip a source |
|
|
84
|
+
| `--lang en\|es` | report language (also switchable inside the report) |
|
|
85
|
+
| `--anonymize` | replace users with `user-NN` before sharing |
|
|
86
|
+
| `--brand`, `--logo`, `--no-logo`, `--no-embed-font` | white-label the report |
|
|
87
|
+
| `--json FILE` | also dump the aggregated data (feed your own dashboards) |
|
|
88
|
+
| `--demo` | synthetic data, no AWS |
|
|
89
|
+
|
|
90
|
+
## How it works
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
CUR (parquet) ─┐ ┌─> report.html (inline CSS/JS/SVG, offline)
|
|
94
|
+
├─> model.build_report (JSON) ──────┤
|
|
95
|
+
Kiro CSVs ─────┘ merge by user id, └─> --json
|
|
96
|
+
IAM Identity Center tier right-sizing
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`src/kiro_report/`: `cli` (prompts) · `aws` (profiles/SSO) · `cur` · `activity` · `identity` · `model` (merge + recommendations) · `tiers` (plan catalogue) · `render` + `templates/report.html`.
|
|
100
|
+
|
|
101
|
+
## Related AWS projects
|
|
102
|
+
|
|
103
|
+
This tool is a lightweight, local alternative to heavier setups; use them if you need always-on dashboards:
|
|
104
|
+
|
|
105
|
+
- [Kiro User Activity Dashboard](https://docs.aws.amazon.com/guidance/latest/cloud-intelligence-dashboards/kiro-user-activity-dashboard.html) (Cloud Intelligence Dashboards, QuickSight)
|
|
106
|
+
- [`aws-samples/sample-kiro-cost-optimizer`](https://github.com/aws-samples/sample-kiro-cost-optimizer) (serverless, e-mail recommendations)
|
|
107
|
+
- [`aws-samples/sample-kiro-user-analytics-dashboard`](https://github.com/aws-samples/sample-kiro-user-analytics-dashboard)
|
|
108
|
+
|
|
109
|
+
## Privacy
|
|
110
|
+
|
|
111
|
+
Reports contain user e-mails and usage. Generated `kiro-report-*.html/json` are git-ignored; use `--anonymize` before sharing. Nothing leaves your machine except the AWS API calls you authorise.
|
|
112
|
+
|
|
113
|
+
## Development
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
pip install -e ".[dev]"
|
|
117
|
+
pytest --cov=kiro_report
|
|
118
|
+
ruff check .
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Plan prices/allowances live in `src/kiro_report/tiers.py` (Kiro pricing is subject to change).
|
|
122
|
+
|
|
123
|
+
## Releasing
|
|
124
|
+
|
|
125
|
+
Releases are published to PyPI by GitHub Actions with [Trusted Publishing](https://docs.pypi.org/trusted-publishers/) (OIDC, no stored tokens): `.github/workflows/release.yml`. To release, bump `version` in `pyproject.toml`, merge, then push a tag `vX.Y.Z` (the workflow refuses a tag that does not match the version). Run the workflow manually with target `testpypi` to rehearse.
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT for the code. The SysCu logo in `src/kiro_report/assets/` is a brand asset and is **not** covered by the MIT license (replace it with `--logo`, or drop it with `--no-logo`); the bundled Figtree font is SIL OFL 1.1. See `LICENSE` and `src/kiro_report/assets/NOTICE.md`.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# kiro-usage-report
|
|
2
|
+
|
|
3
|
+
Generate a **single, self-contained HTML report** of [Kiro](https://kiro.dev) usage and cost **per IAM Identity Center user** — one command, no infrastructure to deploy.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
It answers the questions Kiro administrators keep asking:
|
|
8
|
+
|
|
9
|
+
- Who is using Kiro, on which client (IDE / CLI / Web), and with which models?
|
|
10
|
+
- Credits used per day / week / month, by client type and by plan — the same views as the Kiro console dashboard, plus per-person detail.
|
|
11
|
+
- What do the subscriptions cost, and how much of it is covered by AWS credits?
|
|
12
|
+
- Who is on the wrong plan? Right-sizing suggestions include overage cost ($0.04/credit).
|
|
13
|
+
- Which licences are idle?
|
|
14
|
+
|
|
15
|
+
The output is a static `.html` file (light/dark theme, English/Spanish, date-range and daily/weekly/monthly filters, tooltips, print-friendly). Share it as an attachment; nothing is uploaded anywhere.
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install syscu-kiro-report-usage # from PyPI
|
|
21
|
+
pip install git+https://github.com/syscu-es/syscu-kiro-report-usage.git # latest from GitHub
|
|
22
|
+
# or from a clone: pip install . (development: pip install -e ".[dev]")
|
|
23
|
+
|
|
24
|
+
kiro-report --demo --open # preview with synthetic data, no AWS needed
|
|
25
|
+
kiro-report # interactive: pick or sign in to ANY AWS account, then the period
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Unattended:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
kiro-report --profile my-sso-profile --sso-login --last 6 --out kiro.html
|
|
32
|
+
kiro-report --profile prod --month 2026-10 --lang en --anonymize
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Works against any account, interactively
|
|
36
|
+
|
|
37
|
+
Run `kiro-report` on a terminal and it asks, step by step:
|
|
38
|
+
|
|
39
|
+
1. **Account** — choose one of your local profiles (`~/.aws/config` / `~/.aws/credentials`), the default credential chain, or **“Sign in with AWS IAM Identity Center”**.
|
|
40
|
+
2. **IAM Identity Center sign-in (no profile needed)** — enter your start URL (`https://<name>.awsapps.com/start`) and region, approve in the browser (device authorization, the same flow as `aws sso login`), then pick any **account** and **role** you can reach (type text to filter long lists). Tokens and temporary credentials stay in memory; nothing is written to disk.
|
|
41
|
+
3. **Period** — last full month, current month, last 3/6/12 months, or a custom `YYYY-MM[:YYYY-MM]` range.
|
|
42
|
+
|
|
43
|
+
For an existing SSO *profile* with an expired session it offers to run `aws sso login` for you (`--sso-login` does it without asking). Everything is also scriptable: `--sso-start-url … --sso-account <id|name> --sso-role <name>`; `-y/--yes` never prompts. Set `KIRO_REPORT_SSO_START_URL` to pre-fill the start URL.
|
|
44
|
+
|
|
45
|
+
## Where the data comes from
|
|
46
|
+
|
|
47
|
+
| Source | Gives you | How to enable |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| **Kiro user activity report** (daily CSVs in S3) | client type (IDE/CLI/Web), plan, credits, **overage**, messages, models, user e-mail, new users | Kiro console → *Settings* → *User activity report* → CSV → S3 bucket. [Docs](https://kiro.dev/docs/enterprise/monitor-and-track/user-activity/) |
|
|
50
|
+
| **AWS Cost and Usage Report** (Data Exports, parquet) | real subscription lines, AWS credits applied, credits per Identity Center user (`line_item_resource_id`) | Billing → Data Exports → *Standard data export (CUR 2.0)* with resource IDs, parquet |
|
|
51
|
+
| **IAM Identity Center** | user names when the activity report has no e-mail | automatic |
|
|
52
|
+
|
|
53
|
+
Either source can be missing: with only the activity report, costs are *estimated at list price*; with only the CUR you get per-person credits and costs but no client/plan/model breakdown (the report tells you how to enable the rest). Sources are auto-discovered; override with `--cur-export`, `--cur-bucket/--cur-prefix`, `--activity-bucket/--activity-prefix`.
|
|
54
|
+
|
|
55
|
+
Required AWS permissions are read-only — see [docs/PERMISSIONS.md](docs/PERMISSIONS.md).
|
|
56
|
+
|
|
57
|
+
## Options
|
|
58
|
+
|
|
59
|
+
| Flag | Purpose |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `--profile`, `--region`, `--sso-login` | pick a local profile; refresh an expired SSO session |
|
|
62
|
+
| `--sso-start-url`, `--sso-region`, `--sso-account`, `--sso-role` | sign in to any account through IAM Identity Center, no profile needed |
|
|
63
|
+
| `--month`, `--since`/`--until`, `--last N` | period (default: last 3 months, or asked) |
|
|
64
|
+
| `--no-cur`, `--no-activity` | skip a source |
|
|
65
|
+
| `--lang en\|es` | report language (also switchable inside the report) |
|
|
66
|
+
| `--anonymize` | replace users with `user-NN` before sharing |
|
|
67
|
+
| `--brand`, `--logo`, `--no-logo`, `--no-embed-font` | white-label the report |
|
|
68
|
+
| `--json FILE` | also dump the aggregated data (feed your own dashboards) |
|
|
69
|
+
| `--demo` | synthetic data, no AWS |
|
|
70
|
+
|
|
71
|
+
## How it works
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
CUR (parquet) ─┐ ┌─> report.html (inline CSS/JS/SVG, offline)
|
|
75
|
+
├─> model.build_report (JSON) ──────┤
|
|
76
|
+
Kiro CSVs ─────┘ merge by user id, └─> --json
|
|
77
|
+
IAM Identity Center tier right-sizing
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`src/kiro_report/`: `cli` (prompts) · `aws` (profiles/SSO) · `cur` · `activity` · `identity` · `model` (merge + recommendations) · `tiers` (plan catalogue) · `render` + `templates/report.html`.
|
|
81
|
+
|
|
82
|
+
## Related AWS projects
|
|
83
|
+
|
|
84
|
+
This tool is a lightweight, local alternative to heavier setups; use them if you need always-on dashboards:
|
|
85
|
+
|
|
86
|
+
- [Kiro User Activity Dashboard](https://docs.aws.amazon.com/guidance/latest/cloud-intelligence-dashboards/kiro-user-activity-dashboard.html) (Cloud Intelligence Dashboards, QuickSight)
|
|
87
|
+
- [`aws-samples/sample-kiro-cost-optimizer`](https://github.com/aws-samples/sample-kiro-cost-optimizer) (serverless, e-mail recommendations)
|
|
88
|
+
- [`aws-samples/sample-kiro-user-analytics-dashboard`](https://github.com/aws-samples/sample-kiro-user-analytics-dashboard)
|
|
89
|
+
|
|
90
|
+
## Privacy
|
|
91
|
+
|
|
92
|
+
Reports contain user e-mails and usage. Generated `kiro-report-*.html/json` are git-ignored; use `--anonymize` before sharing. Nothing leaves your machine except the AWS API calls you authorise.
|
|
93
|
+
|
|
94
|
+
## Development
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pip install -e ".[dev]"
|
|
98
|
+
pytest --cov=kiro_report
|
|
99
|
+
ruff check .
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Plan prices/allowances live in `src/kiro_report/tiers.py` (Kiro pricing is subject to change).
|
|
103
|
+
|
|
104
|
+
## Releasing
|
|
105
|
+
|
|
106
|
+
Releases are published to PyPI by GitHub Actions with [Trusted Publishing](https://docs.pypi.org/trusted-publishers/) (OIDC, no stored tokens): `.github/workflows/release.yml`. To release, bump `version` in `pyproject.toml`, merge, then push a tag `vX.Y.Z` (the workflow refuses a tag that does not match the version). Run the workflow manually with target `testpypi` to rehearse.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT for the code. The SysCu logo in `src/kiro_report/assets/` is a brand asset and is **not** covered by the MIT license (replace it with `--logo`, or drop it with `--no-logo`); the bundled Figtree font is SIL OFL 1.1. See `LICENSE` and `src/kiro_report/assets/NOTICE.md`.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "syscu-kiro-report-usage"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Self-contained HTML report of Kiro usage and cost per IAM Identity Center user (AWS CUR + Kiro user activity report)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
keywords = ["kiro", "aws", "finops", "cost", "usage", "report", "iam-identity-center"]
|
|
13
|
+
dependencies = ["boto3>=1.34", "pyarrow>=14"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Homepage = "https://github.com/syscu-es/syscu-kiro-report-usage"
|
|
17
|
+
Issues = "https://github.com/syscu-es/syscu-kiro-report-usage/issues"
|
|
18
|
+
|
|
19
|
+
[project.optional-dependencies]
|
|
20
|
+
dev = ["pytest>=8", "pytest-cov>=5", "ruff>=0.5"]
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
kiro-report = "kiro_report.cli:main"
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.package-data]
|
|
29
|
+
kiro_report = ["assets/*", "templates/*"]
|
|
30
|
+
|
|
31
|
+
[tool.pytest.ini_options]
|
|
32
|
+
testpaths = ["tests"]
|
|
33
|
+
pythonpath = ["src"]
|
|
34
|
+
markers = ["unit: fast tests with no AWS access"]
|
|
35
|
+
|
|
36
|
+
[tool.ruff]
|
|
37
|
+
line-length = 110
|
|
38
|
+
src = ["src", "tests"]
|
|
39
|
+
target-version = "py310"
|
|
40
|
+
|
|
41
|
+
[tool.ruff.lint]
|
|
42
|
+
# explicit so local and CI results never depend on a user-level ruff config
|
|
43
|
+
select = ["F", "UP", "B"]
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"""Reader for the Kiro *user activity report* (daily CSVs delivered to S3).
|
|
2
|
+
|
|
3
|
+
Enable it in the Kiro console (Settings -> User activity report, CSV). Kiro writes one
|
|
4
|
+
CSV per client type and day under
|
|
5
|
+
``<prefix>/AWSLogs/<account>/KiroLogs/user_report/<region>/<yyyy>/<mm>/<dd>/<hh>/``
|
|
6
|
+
named ``KIRO_IDE_<account>_user_report_<yyyymmddhh00>.csv`` (``KIRO_CLI``/``KIRO_WEB``
|
|
7
|
+
for the other clients). Header::
|
|
8
|
+
|
|
9
|
+
Date,UserId,Client_Type,Chat_Conversations,Credits_Used,Overage_Cap,
|
|
10
|
+
Overage_Credits_Used,Overage_Enabled,ProfileId,Subscription_Tier,Total_Messages,
|
|
11
|
+
New_User,User_Email,Usage_Limit,<model>_messages,...
|
|
12
|
+
|
|
13
|
+
Model columns are dynamic (``auto_messages``, ``claude_sonnet_5_messages``, ...).
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import csv
|
|
18
|
+
import datetime as dt
|
|
19
|
+
import io
|
|
20
|
+
import re
|
|
21
|
+
from dataclasses import dataclass
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Any
|
|
24
|
+
from collections.abc import Callable
|
|
25
|
+
from collections.abc import Iterable
|
|
26
|
+
|
|
27
|
+
from .periods import month_bounds
|
|
28
|
+
|
|
29
|
+
KEY_RE = re.compile(
|
|
30
|
+
r"^(?P<base>.*?)AWSLogs/(?P<account>\d+)/KiroLogs/user_report/(?P<region>[^/]+)/"
|
|
31
|
+
r"(?P<y>\d{4})/(?P<m>\d{2})/(?P<d>\d{2})/(?P<h>\d{2})/"
|
|
32
|
+
r"(?P<client>[A-Z_]+?)_\d+_user_report_\d+(?:_part\d+)?\.csv$"
|
|
33
|
+
)
|
|
34
|
+
DEFAULT_MAX_SCAN = 5000
|
|
35
|
+
_CACHE_SAFE_AFTER_DAYS = 2 # reports older than this are final and can be cached
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class ReportLocation:
|
|
40
|
+
bucket: str
|
|
41
|
+
base: str # key prefix before "AWSLogs/" ('' or ending with '/')
|
|
42
|
+
account: str
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass(frozen=True)
|
|
46
|
+
class Discovery:
|
|
47
|
+
location: ReportLocation | None
|
|
48
|
+
candidates: tuple[str, ...] # buckets that looked like Kiro report buckets
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(frozen=True)
|
|
52
|
+
class ReportKey:
|
|
53
|
+
key: str
|
|
54
|
+
date: str
|
|
55
|
+
client: str
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass(frozen=True)
|
|
59
|
+
class ActivityRow:
|
|
60
|
+
date: str
|
|
61
|
+
user_id: str
|
|
62
|
+
email: str
|
|
63
|
+
client: str
|
|
64
|
+
tier: str
|
|
65
|
+
credits: float
|
|
66
|
+
overage: float
|
|
67
|
+
messages: int
|
|
68
|
+
conversations: int
|
|
69
|
+
new_user: bool
|
|
70
|
+
models: tuple[tuple[str, int], ...]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# --------------------------------------------------------------------------- #
|
|
74
|
+
# Parsing
|
|
75
|
+
# --------------------------------------------------------------------------- #
|
|
76
|
+
def normalize_client(raw: str) -> str:
|
|
77
|
+
"""'KIRO_IDE' -> 'IDE'."""
|
|
78
|
+
text = (raw or "").strip().upper()
|
|
79
|
+
return text[5:] if text.startswith("KIRO_") else (text or "UNKNOWN")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _num(value: Any) -> float:
|
|
83
|
+
try:
|
|
84
|
+
return float(str(value).replace(",", "").strip() or 0)
|
|
85
|
+
except ValueError:
|
|
86
|
+
return 0.0
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _truthy(value: Any) -> bool:
|
|
90
|
+
return str(value).strip().lower() in {"true", "1", "yes", "y"}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def parse_report(text: str, client_hint: str = "") -> list[ActivityRow]:
|
|
94
|
+
"""Parse one activity CSV. Header names are matched case-insensitively."""
|
|
95
|
+
reader = csv.DictReader(io.StringIO(text.lstrip("")))
|
|
96
|
+
rows: list[ActivityRow] = []
|
|
97
|
+
for raw in reader:
|
|
98
|
+
row = {(k or "").strip().lower(): (v or "").strip() for k, v in raw.items()}
|
|
99
|
+
if not row.get("date") or not row.get("userid"):
|
|
100
|
+
continue
|
|
101
|
+
models = tuple(
|
|
102
|
+
(name[: -len("_messages")], int(_num(value)))
|
|
103
|
+
for name, value in row.items()
|
|
104
|
+
if name.endswith("_messages") and name != "total_messages" and _num(value) > 0
|
|
105
|
+
)
|
|
106
|
+
rows.append(
|
|
107
|
+
ActivityRow(
|
|
108
|
+
date=row["date"][:10],
|
|
109
|
+
user_id=row["userid"],
|
|
110
|
+
email=row.get("user_email", ""),
|
|
111
|
+
client=normalize_client(row.get("client_type") or client_hint),
|
|
112
|
+
tier=row.get("subscription_tier", ""),
|
|
113
|
+
credits=_num(row.get("credits_used")),
|
|
114
|
+
overage=_num(row.get("overage_credits_used")),
|
|
115
|
+
messages=int(_num(row.get("total_messages"))),
|
|
116
|
+
conversations=int(_num(row.get("chat_conversations"))),
|
|
117
|
+
new_user=_truthy(row.get("new_user", "")),
|
|
118
|
+
models=models,
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
return rows
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
# --------------------------------------------------------------------------- #
|
|
125
|
+
# S3 discovery and download
|
|
126
|
+
# --------------------------------------------------------------------------- #
|
|
127
|
+
def find_in_bucket(s3: Any, bucket: str, max_scan: int = DEFAULT_MAX_SCAN) -> ReportLocation | None:
|
|
128
|
+
"""Scan up to ``max_scan`` keys of ``bucket`` for an activity-report object."""
|
|
129
|
+
scanned = 0
|
|
130
|
+
paginator = s3.get_paginator("list_objects_v2")
|
|
131
|
+
for page in paginator.paginate(Bucket=bucket):
|
|
132
|
+
for obj in page.get("Contents", []):
|
|
133
|
+
match = KEY_RE.match(obj["Key"])
|
|
134
|
+
if match:
|
|
135
|
+
return ReportLocation(bucket, match["base"], match["account"])
|
|
136
|
+
scanned += 1
|
|
137
|
+
if scanned >= max_scan:
|
|
138
|
+
return None
|
|
139
|
+
return None
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def discover(
|
|
143
|
+
s3: Any,
|
|
144
|
+
*,
|
|
145
|
+
bucket: str | None = None,
|
|
146
|
+
prefix: str | None = None,
|
|
147
|
+
account: str | None = None,
|
|
148
|
+
max_scan: int = DEFAULT_MAX_SCAN,
|
|
149
|
+
) -> Discovery:
|
|
150
|
+
"""Locate the activity reports.
|
|
151
|
+
|
|
152
|
+
With ``bucket`` (and optionally ``prefix``/``account``) only that bucket is checked;
|
|
153
|
+
otherwise every bucket whose name contains "kiro" is scanned.
|
|
154
|
+
"""
|
|
155
|
+
if bucket and prefix is not None and account:
|
|
156
|
+
base = prefix if not prefix or prefix.endswith("/") else prefix + "/"
|
|
157
|
+
return Discovery(ReportLocation(bucket, base, account), (bucket,))
|
|
158
|
+
names = [bucket] if bucket else [
|
|
159
|
+
b["Name"] for b in s3.list_buckets().get("Buckets", []) if "kiro" in b["Name"].lower()
|
|
160
|
+
]
|
|
161
|
+
for name in names:
|
|
162
|
+
location = find_in_bucket(s3, name, max_scan)
|
|
163
|
+
if location:
|
|
164
|
+
return Discovery(location, tuple(names))
|
|
165
|
+
return Discovery(None, tuple(names))
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def list_report_keys(s3: Any, location: ReportLocation, months: Iterable[str]) -> list[ReportKey]:
|
|
169
|
+
"""List the report objects of the given months across every region."""
|
|
170
|
+
root = f"{location.base}AWSLogs/{location.account}/KiroLogs/user_report/"
|
|
171
|
+
paginator = s3.get_paginator("list_objects_v2")
|
|
172
|
+
regions = [
|
|
173
|
+
p["Prefix"]
|
|
174
|
+
for page in paginator.paginate(Bucket=location.bucket, Prefix=root, Delimiter="/")
|
|
175
|
+
for p in page.get("CommonPrefixes", [])
|
|
176
|
+
]
|
|
177
|
+
keys: list[ReportKey] = []
|
|
178
|
+
for region in regions:
|
|
179
|
+
for month in months:
|
|
180
|
+
prefix = f"{region}{month[:4]}/{month[5:7]}/"
|
|
181
|
+
for page in paginator.paginate(Bucket=location.bucket, Prefix=prefix):
|
|
182
|
+
for obj in page.get("Contents", []):
|
|
183
|
+
match = KEY_RE.match(obj["Key"])
|
|
184
|
+
if match:
|
|
185
|
+
date = f"{match['y']}-{match['m']}-{match['d']}"
|
|
186
|
+
keys.append(ReportKey(obj["Key"], date, normalize_client(match["client"])))
|
|
187
|
+
return sorted(keys, key=lambda k: (k.date, k.client, k.key))
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def fetch_text(
|
|
191
|
+
s3: Any, bucket: str, item: ReportKey, cache: Path | None, today: dt.date
|
|
192
|
+
) -> str:
|
|
193
|
+
"""Download a report, caching it on disk once it is old enough to be final."""
|
|
194
|
+
target = cache / "activity" / bucket / item.key if cache else None
|
|
195
|
+
final = dt.date.fromisoformat(item.date) <= today - dt.timedelta(days=_CACHE_SAFE_AFTER_DAYS)
|
|
196
|
+
if target and final and target.exists():
|
|
197
|
+
return target.read_text(encoding="utf-8")
|
|
198
|
+
body = s3.get_object(Bucket=bucket, Key=item.key)["Body"].read().decode("utf-8-sig")
|
|
199
|
+
if target and final:
|
|
200
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
201
|
+
target.write_text(body, encoding="utf-8")
|
|
202
|
+
return body
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def load_activity(
|
|
206
|
+
s3: Any,
|
|
207
|
+
location: ReportLocation,
|
|
208
|
+
months: list[str],
|
|
209
|
+
*,
|
|
210
|
+
cache: Path | None = None,
|
|
211
|
+
today: dt.date | None = None,
|
|
212
|
+
progress: Callable[[str], None] = lambda _msg: None,
|
|
213
|
+
) -> list[ActivityRow]:
|
|
214
|
+
"""Fetch and parse every report of ``months``; rows outside the months are dropped."""
|
|
215
|
+
today = today or dt.date.today()
|
|
216
|
+
first, last = month_bounds(months[0])[0], month_bounds(months[-1])[1]
|
|
217
|
+
items = list_report_keys(s3, location, months)
|
|
218
|
+
progress(f" activity: {len(items)} report file(s)")
|
|
219
|
+
rows: list[ActivityRow] = []
|
|
220
|
+
for item in items:
|
|
221
|
+
for row in parse_report(fetch_text(s3, location.bucket, item, cache, today), item.client):
|
|
222
|
+
if first.isoformat() <= row.date <= last.isoformat():
|
|
223
|
+
rows.append(row)
|
|
224
|
+
return rows
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Bundled assets
|
|
2
|
+
|
|
3
|
+
| File | What | License |
|
|
4
|
+
|---|---|---|
|
|
5
|
+
| `Figtree-Variable.woff2` | Figtree (variable, Latin subset) | SIL Open Font License 1.1 — https://github.com/erikdkennedy/figtree |
|
|
6
|
+
| `logo-light.svg`, `logo-dark.svg` | SysCu logo (light / dark theme) | © SysCu. Not covered by the MIT license of this repository. |
|
|
7
|
+
|
|
8
|
+
Replace the logo with `--logo your-logo.svg`, rename the brand with `--brand "Your Name"`,
|
|
9
|
+
or drop it with `--no-logo`. Skip the font with `--no-embed-font`.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<svg id="Capa_2" data-name="Capa 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 918.23 714.18"><defs><style>
|
|
2
|
+
.cls-1 {
|
|
3
|
+
fill: #fff;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.cls-2 {
|
|
7
|
+
fill: #00a7e1;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.cls-3 {
|
|
11
|
+
fill: #002b49;
|
|
12
|
+
}
|
|
13
|
+
</style></defs><g id="Capa_1-2" data-name="Capa 1"><g><path class="cls-1" d="m918.23,459.11c0,140.85-114.22,255.06-255.06,255.06H255.06C114.22,714.18,0,599.96,0,459.11c0-124.88,89.83-228.79,208.39-250.73C230.32,89.83,334.23,0,459.11,0s228.79,89.83,250.73,208.39c118.55,21.94,208.39,125.85,208.39,250.73Z"/><path class="cls-2" d="m459.11,612.15h-204.05c-84.53,0-153.04-68.51-153.04-153.04,0-69.07,45.76-127.43,108.66-146.46,22.65,98.2,102.03,174.67,201.75,193.13,7.29,39.38,23.57,75.55,46.68,106.36Z"/><path class="cls-3" d="m816.2,459.11c0,84.53-68.51,153.04-153.04,153.04-66.62,0-123.3-42.6-144.31-102.03h144.31c28.16,0,51.01-22.85,51.01-51.01s-22.85-51.01-51.01-51.01h-204.05c-84.53,0-153.04-68.51-153.04-153.04s68.51-153.04,153.04-153.04c66.62,0,123.3,42.6,144.31,102.03h-144.31c-28.16,0-51.01,22.85-51.01,51.01s22.85,51.01,51.01,51.01h204.05c84.53,0,153.04,68.51,153.04,153.04Z"/></g></g></svg>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<svg id="Capa_2" data-name="Capa 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 918.23 714.18"><defs><style>
|
|
2
|
+
.cls-1 {
|
|
3
|
+
fill: #fff;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.cls-2 {
|
|
7
|
+
fill: #00a7e1;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.cls-3 {
|
|
11
|
+
fill: #002b49;
|
|
12
|
+
}
|
|
13
|
+
</style></defs><g id="Capa_1-2" data-name="Capa 1"><g><path class="cls-3" d="m918.23,459.11c0,140.85-114.22,255.06-255.06,255.06H255.06C114.22,714.18,0,599.96,0,459.11c0-124.88,89.83-228.79,208.39-250.73C230.32,89.83,334.23,0,459.11,0s228.79,89.83,250.73,208.39c118.55,21.94,208.39,125.85,208.39,250.73Z"/><path class="cls-2" d="m459.11,612.15h-204.05c-84.53,0-153.04-68.51-153.04-153.04,0-69.07,45.76-127.43,108.66-146.46,22.65,98.2,102.03,174.67,201.75,193.13,7.29,39.38,23.57,75.55,46.68,106.36Z"/><path class="cls-1" d="m816.2,459.11c0,84.53-68.51,153.04-153.04,153.04-66.62,0-123.3-42.6-144.31-102.03h144.31c28.16,0,51.01-22.85,51.01-51.01s-22.85-51.01-51.01-51.01h-204.05c-84.53,0-153.04-68.51-153.04-153.04s68.51-153.04,153.04-153.04c66.62,0,123.3,42.6,144.31,102.03h-144.31c-28.16,0-51.01,22.85-51.01,51.01s22.85,51.01,51.01,51.01h204.05c84.53,0,153.04,68.51,153.04,153.04Z"/></g></g></svg>
|