finbrain-python 0.2.9__tar.gz → 0.3.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.
Files changed (93) hide show
  1. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/CHANGELOG.md +24 -0
  2. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/PKG-INFO +69 -3
  3. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/README.md +68 -2
  4. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/app_ratings.py +37 -1
  5. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/screener.py +15 -6
  6. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/app_ratings.py +68 -3
  7. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/screener.py +15 -6
  8. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/plotting.py +70 -21
  9. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain_python.egg-info/PKG-INFO +69 -3
  10. finbrain_python-0.3.0/src/finbrain_python.egg-info/scm_version.json +8 -0
  11. finbrain_python-0.3.0/tests/test_app_ratings.py +233 -0
  12. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_integration.py +4 -0
  13. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_plotting.py +48 -0
  14. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_screener.py +30 -2
  15. finbrain_python-0.2.9/src/finbrain_python.egg-info/scm_version.json +0 -8
  16. finbrain_python-0.2.9/tests/test_app_ratings.py +0 -81
  17. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/.gitattributes +0 -0
  18. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/.github/workflows/ci.yml +0 -0
  19. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/.github/workflows/release.yml +0 -0
  20. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/.gitignore +0 -0
  21. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/LICENSE +0 -0
  22. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/RELEASE.md +0 -0
  23. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/examples/async_example.py +0 -0
  24. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/examples/transactions_plotting_example.py +0 -0
  25. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/pyproject.toml +0 -0
  26. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/setup.cfg +0 -0
  27. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/__init__.py +0 -0
  28. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/__init__.py +0 -0
  29. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/client.py +0 -0
  30. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/__init__.py +0 -0
  31. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/_utils.py +0 -0
  32. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/analyst_ratings.py +0 -0
  33. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/available.py +0 -0
  34. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/corporate_lobbying.py +0 -0
  35. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/government_contracts.py +0 -0
  36. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/house_trades.py +0 -0
  37. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/insider_transactions.py +0 -0
  38. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/linkedin_data.py +0 -0
  39. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/news.py +0 -0
  40. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/options.py +0 -0
  41. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/patent_filings.py +0 -0
  42. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/predictions.py +0 -0
  43. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/recent.py +0 -0
  44. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/reddit_mentions.py +0 -0
  45. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/senate_trades.py +0 -0
  46. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/aio/endpoints/sentiments.py +0 -0
  47. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/client.py +0 -0
  48. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/__init__.py +0 -0
  49. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/_utils.py +0 -0
  50. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/analyst_ratings.py +0 -0
  51. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/available.py +0 -0
  52. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/corporate_lobbying.py +0 -0
  53. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/government_contracts.py +0 -0
  54. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/house_trades.py +0 -0
  55. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/insider_transactions.py +0 -0
  56. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/linkedin_data.py +0 -0
  57. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/news.py +0 -0
  58. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/options.py +0 -0
  59. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/patent_filings.py +0 -0
  60. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/predictions.py +0 -0
  61. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/recent.py +0 -0
  62. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/reddit_mentions.py +0 -0
  63. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/senate_trades.py +0 -0
  64. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/endpoints/sentiments.py +0 -0
  65. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/exceptions.py +0 -0
  66. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain/py.typed +0 -0
  67. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain_python.egg-info/SOURCES.txt +0 -0
  68. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain_python.egg-info/dependency_links.txt +0 -0
  69. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain_python.egg-info/requires.txt +0 -0
  70. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain_python.egg-info/scm_file_list.json +0 -0
  71. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/src/finbrain_python.egg-info/top_level.txt +0 -0
  72. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/__init__.py +0 -0
  73. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/conftest.py +0 -0
  74. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_analyst_ratings.py +0 -0
  75. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_async_client.py +0 -0
  76. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_available.py +0 -0
  77. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_cik_passthrough.py +0 -0
  78. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_client.py +0 -0
  79. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_corporate_lobbying.py +0 -0
  80. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_envelope.py +0 -0
  81. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_government_contracts.py +0 -0
  82. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_house_trades.py +0 -0
  83. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_insider_transactions.py +0 -0
  84. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_linkedin_data.py +0 -0
  85. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_news.py +0 -0
  86. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_options.py +0 -0
  87. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_patent_filings.py +0 -0
  88. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_predictions.py +0 -0
  89. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_recent.py +0 -0
  90. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_reddit_mentions.py +0 -0
  91. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_senate_trades.py +0 -0
  92. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_sentiments.py +0 -0
  93. {finbrain_python-0.2.9 → finbrain_python-0.3.0}/tests/test_utils.py +0 -0
@@ -5,6 +5,29 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.3.0] - 2026-09-04
9
+
10
+ ### Added
11
+
12
+ - **Per-app app ratings**: `fb.app_ratings.ticker(..., as_dataframe=True, per_app=True)` (sync and async) returns the granular frame the v2 API's new `apps[]` carries — one row per app per observation with `platform`, `app_id`, `app_name`, `score`, `ratings_count` and `install_count`. A company can publish many apps (Apple has 140 on iOS), and the blended per-date view necessarily reports only its biggest on each store; the per-app frame does no blending and derives no company score, leaving the weighting to the caller. Deliberately **not** indexed by `date`, since a date carries one row per app
13
+ - **`app_id` on the app-ratings chart**: `fb.plot.app_ratings(..., app_id=...)` charts one specific app rather than the company's largest on that store, and raises listing the available ids when the requested one is absent
14
+ - **Documentation**: README "App ratings: the per-app view (`per_app=True`)" section covering the columns, the unindexed frame, the null `app_id` case and the plotting parameter
15
+ - **Congressional amount metadata on the screener**: `fb.screener.congress_house()` and `fb.screener.congress_senate()` rows (sync and async) now carry `amountRaw` and `amountFlag`, matching the ticker-level endpoints since 0.2.8. On rows whose `amount` was normalized to its STOCK Act bracket, `amountRaw` preserves the string as originally filed; `amountFlag` is `review` or `ambiguous` when the filed amount could not be safely normalized; both are `null` on clean rows. The fields are emitted by the v2 API and pass through both the raw-dict and DataFrame branches with no SDK code changes; docstrings, README, unit tests and integration tests now cover them
16
+
17
+ ### Changed
18
+
19
+ - **DataFrame shape**: the congress screener frames gain `amountRaw` and `amountFlag` columns. Code that asserts an exact column set (`set(df.columns) == {...}`) or compares frames for equality needs updating
20
+
21
+ ### Fixed
22
+
23
+ - **App-ratings chart with a mismatched store**: passing an iOS `app_id` with `store="play"` (or the reverse) relabelled that app's series as the other platform's and plotted it. It now raises, naming the store the app actually lives on
24
+
25
+ ### Notes
26
+
27
+ - Also carries the congressional screener changes written up as 0.2.10 on 2026-08-26, which were never tagged or published: PyPI goes from 0.2.9 straight to this release
28
+ - Purely additive: `per_app=False` remains the default and the blended frame is byte-for-byte unchanged. An API deployment predating `apps[]` yields an empty per-app frame rather than an error, so the SDK can ship before or after the API
29
+ - The raw-dict branch is purely additive — no call-site changes are required to receive the new fields
30
+
8
31
  ## [0.2.9] - 2026-08-14
9
32
 
10
33
  ### Added
@@ -244,6 +267,7 @@ Previous releases...
244
267
 
245
268
  Previous releases...
246
269
 
270
+ [0.3.0]: https://github.com/ahmetsbilgin/finbrain-python/compare/v0.2.9...v0.3.0
247
271
  [0.2.1]: https://github.com/ahmetsbilgin/finbrain-python/compare/v0.2.0...v0.2.1
248
272
  [0.2.0]: https://github.com/ahmetsbilgin/finbrain-python/compare/v0.1.8...v0.2.0
249
273
  [0.1.8]: https://github.com/ahmetsbilgin/finbrain-python/compare/v0.1.7...v0.1.8
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: finbrain-python
3
- Version: 0.2.9
3
+ Version: 0.3.0
4
4
  Summary: Official Python client for the FinBrain API
5
5
  Author-email: Ahmet Salim Bilgin <ahmet@finbrain.tech>
6
6
  License-Expression: MIT
@@ -77,6 +77,14 @@ fb.app_ratings.ticker("AMZN",
77
77
  date_to="2025-06-30",
78
78
  as_dataframe=True)
79
79
 
80
+ # One row per app per date instead of one blended row per date
81
+ # — see "App ratings: the per-app view" below.
82
+ fb.app_ratings.ticker("AMZN",
83
+ date_from="2025-01-01",
84
+ date_to="2025-06-30",
85
+ as_dataframe=True,
86
+ per_app=True)
87
+
80
88
  # ---------- analyst ratings ----------
81
89
  fb.analyst_ratings.ticker("AMZN",
82
90
  date_from="2025-01-01",
@@ -199,8 +207,9 @@ and the other fields are columns whose missing values read as `None` or
199
207
  `NaN` depending on your pandas version — test them with `pandas.isna()`
200
208
  rather than `is None`. Note that `.dropna()` on such a frame will discard
201
209
  every row with any missing field — use `.dropna(subset=[...])`.
202
- `disclosureDate` and `owner` are also present on
203
- `fb.screener.congress_house()` and `fb.screener.congress_senate()` rows.
210
+ All four fields — `owner`, `amountRaw`, `amountFlag` and `disclosureDate` —
211
+ are also present on `fb.screener.congress_house()` and
212
+ `fb.screener.congress_senate()` rows.
204
213
 
205
214
  ### Company identifier (`cik`)
206
215
 
@@ -240,6 +249,55 @@ own = [
240
249
  ]
241
250
  ```
242
251
 
252
+ ### App ratings: the per-app view (`per_app=True`)
253
+
254
+ A company can publish many apps — Apple has 140 on iOS. The default frame
255
+ reports **one row per date**, carrying the company's biggest app on each
256
+ store, so a portfolio collapses to two numbers. `per_app=True` returns the
257
+ granular alternative: one row per app per observation, with no blending and no
258
+ derived company score, so you decide which apps matter and how to weight them.
259
+
260
+ ```python
261
+ apps = fb.app_ratings.ticker(
262
+ "AMZN",
263
+ date_from="2025-01-01",
264
+ date_to="2025-06-30",
265
+ as_dataframe=True,
266
+ per_app=True,
267
+ )
268
+
269
+ apps.columns
270
+ # ['date', 'platform', 'app_id', 'app_name',
271
+ # 'score', 'ratings_count', 'install_count']
272
+
273
+ # Which apps exist, and how big each is
274
+ apps.groupby(["platform", "app_id", "app_name"])["ratings_count"].max()
275
+
276
+ # One app's own series
277
+ apps[apps["app_id"] == "com.amazon.mShop.android.shopping"]
278
+ ```
279
+
280
+ | Column | Meaning |
281
+ | --------------- | ---------------------------------------------------------------- |
282
+ | `platform` | `ios` or `android` |
283
+ | `app_id` | App Store numeric id or Play package name; `null` — see below |
284
+ | `app_name` | App title as published on the store |
285
+ | `score` | Average rating, 0–5 |
286
+ | `ratings_count` | Number of ratings |
287
+ | `install_count` | Play Store only — Apple publishes no install count, so `null` on `ios` |
288
+
289
+ Three things to know:
290
+
291
+ - **Not indexed by date.** A single date carries one row per app, so a date
292
+ index would not be unique. The blended frame (`per_app=False`, the default)
293
+ is still indexed by `date` and is unchanged.
294
+ - **`app_id` is `null` on older observations**, collected before the API keyed
295
+ rows per app. Those rows carry the platform but not the app identity — we
296
+ know the store, not which app produced the number. Filter them with
297
+ `apps["app_id"].notna()` if you need identified apps only.
298
+ - **Purely additive.** `per_app=False` behaviour is untouched, and an API that
299
+ predates the per-app view returns an empty frame rather than an error.
300
+
243
301
  ## ⚡ Async Usage
244
302
 
245
303
  For async/await support, install with the `async` extra:
@@ -296,6 +354,14 @@ fb.plot.app_ratings("AMZN",
296
354
  date_from="2025-01-01",
297
355
  date_to="2025-06-30")
298
356
 
357
+ # Chart one specific app rather than the company's biggest on that store.
358
+ # Ids come from the per_app frame; the app must live on the store you pass.
359
+ fb.plot.app_ratings("AMZN",
360
+ store="play",
361
+ app_id="com.amazon.mShop.android.shopping",
362
+ date_from="2025-01-01",
363
+ date_to="2025-06-30")
364
+
299
365
  # ---------- LinkedIn Metrics Chart ----------
300
366
  fb.plot.linkedin("AMZN",
301
367
  date_from="2025-01-01",
@@ -49,6 +49,14 @@ fb.app_ratings.ticker("AMZN",
49
49
  date_to="2025-06-30",
50
50
  as_dataframe=True)
51
51
 
52
+ # One row per app per date instead of one blended row per date
53
+ # — see "App ratings: the per-app view" below.
54
+ fb.app_ratings.ticker("AMZN",
55
+ date_from="2025-01-01",
56
+ date_to="2025-06-30",
57
+ as_dataframe=True,
58
+ per_app=True)
59
+
52
60
  # ---------- analyst ratings ----------
53
61
  fb.analyst_ratings.ticker("AMZN",
54
62
  date_from="2025-01-01",
@@ -171,8 +179,9 @@ and the other fields are columns whose missing values read as `None` or
171
179
  `NaN` depending on your pandas version — test them with `pandas.isna()`
172
180
  rather than `is None`. Note that `.dropna()` on such a frame will discard
173
181
  every row with any missing field — use `.dropna(subset=[...])`.
174
- `disclosureDate` and `owner` are also present on
175
- `fb.screener.congress_house()` and `fb.screener.congress_senate()` rows.
182
+ All four fields — `owner`, `amountRaw`, `amountFlag` and `disclosureDate` —
183
+ are also present on `fb.screener.congress_house()` and
184
+ `fb.screener.congress_senate()` rows.
176
185
 
177
186
  ### Company identifier (`cik`)
178
187
 
@@ -212,6 +221,55 @@ own = [
212
221
  ]
213
222
  ```
214
223
 
224
+ ### App ratings: the per-app view (`per_app=True`)
225
+
226
+ A company can publish many apps — Apple has 140 on iOS. The default frame
227
+ reports **one row per date**, carrying the company's biggest app on each
228
+ store, so a portfolio collapses to two numbers. `per_app=True` returns the
229
+ granular alternative: one row per app per observation, with no blending and no
230
+ derived company score, so you decide which apps matter and how to weight them.
231
+
232
+ ```python
233
+ apps = fb.app_ratings.ticker(
234
+ "AMZN",
235
+ date_from="2025-01-01",
236
+ date_to="2025-06-30",
237
+ as_dataframe=True,
238
+ per_app=True,
239
+ )
240
+
241
+ apps.columns
242
+ # ['date', 'platform', 'app_id', 'app_name',
243
+ # 'score', 'ratings_count', 'install_count']
244
+
245
+ # Which apps exist, and how big each is
246
+ apps.groupby(["platform", "app_id", "app_name"])["ratings_count"].max()
247
+
248
+ # One app's own series
249
+ apps[apps["app_id"] == "com.amazon.mShop.android.shopping"]
250
+ ```
251
+
252
+ | Column | Meaning |
253
+ | --------------- | ---------------------------------------------------------------- |
254
+ | `platform` | `ios` or `android` |
255
+ | `app_id` | App Store numeric id or Play package name; `null` — see below |
256
+ | `app_name` | App title as published on the store |
257
+ | `score` | Average rating, 0–5 |
258
+ | `ratings_count` | Number of ratings |
259
+ | `install_count` | Play Store only — Apple publishes no install count, so `null` on `ios` |
260
+
261
+ Three things to know:
262
+
263
+ - **Not indexed by date.** A single date carries one row per app, so a date
264
+ index would not be unique. The blended frame (`per_app=False`, the default)
265
+ is still indexed by `date` and is unchanged.
266
+ - **`app_id` is `null` on older observations**, collected before the API keyed
267
+ rows per app. Those rows carry the platform but not the app identity — we
268
+ know the store, not which app produced the number. Filter them with
269
+ `apps["app_id"].notna()` if you need identified apps only.
270
+ - **Purely additive.** `per_app=False` behaviour is untouched, and an API that
271
+ predates the per-app view returns an empty frame rather than an error.
272
+
215
273
  ## ⚡ Async Usage
216
274
 
217
275
  For async/await support, install with the `async` extra:
@@ -268,6 +326,14 @@ fb.plot.app_ratings("AMZN",
268
326
  date_from="2025-01-01",
269
327
  date_to="2025-06-30")
270
328
 
329
+ # Chart one specific app rather than the company's biggest on that store.
330
+ # Ids come from the per_app frame; the app must live on the store you pass.
331
+ fb.plot.app_ratings("AMZN",
332
+ store="play",
333
+ app_id="com.amazon.mShop.android.shopping",
334
+ date_from="2025-01-01",
335
+ date_to="2025-06-30")
336
+
271
337
  # ---------- LinkedIn Metrics Chart ----------
272
338
  fb.plot.linkedin("AMZN",
273
339
  date_from="2025-01-01",
@@ -26,6 +26,25 @@ def _flatten_app_ratings(rows: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
26
26
  return flat
27
27
 
28
28
 
29
+ def _flatten_apps(apps: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
30
+ """One row per app per observation — see the sync endpoint for the rationale."""
31
+ flat: List[Dict[str, Any]] = []
32
+ for app in apps or []:
33
+ for obs in app.get("observations") or []:
34
+ flat.append(
35
+ {
36
+ "date": obs.get("date"),
37
+ "platform": app.get("platform"),
38
+ "app_id": app.get("appId"),
39
+ "app_name": app.get("appName"),
40
+ "score": obs.get("score"),
41
+ "ratings_count": obs.get("ratingsCount"),
42
+ "install_count": obs.get("installCount"),
43
+ }
44
+ )
45
+ return flat
46
+
47
+
29
48
  class AsyncAppRatingsAPI:
30
49
  """Async wrapper for mobile-app rating analytics."""
31
50
 
@@ -40,8 +59,15 @@ class AsyncAppRatingsAPI:
40
59
  date_to: _dt.date | str | None = None,
41
60
  limit: int | None = None,
42
61
  as_dataframe: bool = False,
62
+ per_app: bool = False,
43
63
  ) -> Dict[str, Any] | pd.DataFrame:
44
- """Fetch mobile-app ratings for a symbol (async)."""
64
+ """Fetch mobile-app ratings for a symbol (async).
65
+
66
+ ``per_app=True`` returns the granular frame — one row per app per
67
+ observation — instead of the blended per-date view. A company can
68
+ publish many apps, so the blended view necessarily reports only its
69
+ biggest on each platform.
70
+ """
45
71
  params: Dict[str, str] = {}
46
72
 
47
73
  if date_from:
@@ -55,6 +81,16 @@ class AsyncAppRatingsAPI:
55
81
  data = await self._c._request("GET", path, params=params)
56
82
 
57
83
  if as_dataframe:
84
+ if per_app:
85
+ flat = _flatten_apps(data.get("apps") or [])
86
+ df = pd.DataFrame(flat)
87
+ if not df.empty and "date" in df.columns:
88
+ df["date"] = pd.to_datetime(df["date"])
89
+ # Not indexed by date: a date repeats across apps.
90
+ df.sort_values(["app_id", "date"], inplace=True)
91
+ df.reset_index(drop=True, inplace=True)
92
+ return df
93
+
58
94
  rows: List[Dict[str, Any]] = data.get("data", [])
59
95
  flat = _flatten_app_ratings(rows)
60
96
  df = pd.DataFrame(flat)
@@ -113,9 +113,13 @@ class AsyncScreenerAPI:
113
113
  Rows carry ``symbol``, ``name``, ``date``, ``politician``,
114
114
  ``transactionType``, ``amount``, ``owner`` (beneficial owner of the
115
115
  account: ``"SELF"``, ``"SP"``, ``"DC"``, ``"JT"``, or an account
116
- code) and ``disclosureDate`` (the public disclosure date). ``owner``
117
- and ``disclosureDate`` are nullable, though rare — historical rows
118
- were backfilled upstream.
116
+ code), ``amountRaw``, ``amountFlag`` and ``disclosureDate`` (the
117
+ public disclosure date). On rows whose ``amount`` was normalized to
118
+ its STOCK Act bracket, ``amountRaw`` preserves the string as
119
+ originally filed; ``amountFlag`` is ``"review"`` or ``"ambiguous"``
120
+ when the filed amount could not be safely normalized. Both are
121
+ ``None`` on clean rows. ``owner`` and ``disclosureDate`` are
122
+ nullable, though rare — historical rows were backfilled upstream.
119
123
  """
120
124
  params = self._build_params(limit=limit)
121
125
  return await self._get("screener/congress/house", params, as_dataframe)
@@ -134,9 +138,14 @@ class AsyncScreenerAPI:
134
138
  Rows carry ``symbol``, ``name``, ``date``, ``politician``,
135
139
  ``transactionType``, ``amount``, ``owner`` (beneficial owner of the
136
140
  account: ``"SELF"``, ``"SP"``, ``"DC"``, ``"JT"``, an account code,
137
- or ``"UNKNOWN"`` for blank Senate filings) and ``disclosureDate``
138
- (the public disclosure date). ``owner`` and ``disclosureDate`` are
139
- nullable, though rare — historical rows were backfilled upstream.
141
+ or ``"UNKNOWN"`` for blank Senate filings), ``amountRaw``,
142
+ ``amountFlag`` and ``disclosureDate`` (the public disclosure date).
143
+ On rows whose ``amount`` was normalized to its STOCK Act bracket,
144
+ ``amountRaw`` preserves the string as originally filed;
145
+ ``amountFlag`` is ``"review"`` or ``"ambiguous"`` when the filed
146
+ amount could not be safely normalized. Both are ``None`` on clean
147
+ rows. ``owner`` and ``disclosureDate`` are nullable, though rare —
148
+ historical rows were backfilled upstream.
140
149
  """
141
150
  params = self._build_params(limit=limit)
142
151
  return await self._get("screener/congress/senate", params, as_dataframe)
@@ -44,6 +44,48 @@ def _flatten_app_ratings(rows: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
44
44
  return flat
45
45
 
46
46
 
47
+ def _flatten_apps(apps: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
48
+ """
49
+ Flatten the per-app series into one row per app per observation.
50
+
51
+ A company can publish many apps — Apple has 140 on iOS — so the blended
52
+ ``data`` view necessarily reports one per platform. This is the granular
53
+ alternative: no blending and no derived company score, one row per
54
+ (app, date), so callers weight or filter for themselves.
55
+
56
+ ``app_id`` is ``None`` for observations predating the API keying rows per
57
+ app: the platform is known, the app is not.
58
+
59
+ Input format per app::
60
+
61
+ {
62
+ "platform": "ios",
63
+ "appId": "1108187390",
64
+ "appName": "Apple Music",
65
+ "observations": [
66
+ {"date": "2026-09-01", "score": 4.86,
67
+ "ratingsCount": 3074796, "installCount": None},
68
+ ...
69
+ ],
70
+ }
71
+ """
72
+ flat: List[Dict[str, Any]] = []
73
+ for app in apps or []:
74
+ for obs in app.get("observations") or []:
75
+ flat.append(
76
+ {
77
+ "date": obs.get("date"),
78
+ "platform": app.get("platform"),
79
+ "app_id": app.get("appId"),
80
+ "app_name": app.get("appName"),
81
+ "score": obs.get("score"),
82
+ "ratings_count": obs.get("ratingsCount"),
83
+ "install_count": obs.get("installCount"),
84
+ }
85
+ )
86
+ return flat
87
+
88
+
47
89
  class AppRatingsAPI:
48
90
  """
49
91
  Mobile-app rating analytics for a single ticker.
@@ -77,6 +119,7 @@ class AppRatingsAPI:
77
119
  date_to: _dt.date | str | None = None,
78
120
  limit: int | None = None,
79
121
  as_dataframe: bool = False,
122
+ per_app: bool = False,
80
123
  ) -> Dict[str, Any] | pd.DataFrame:
81
124
  """
82
125
  Fetch mobile-app ratings for *symbol*.
@@ -90,9 +133,20 @@ class AppRatingsAPI:
90
133
  limit :
91
134
  Maximum number of records to return.
92
135
  as_dataframe :
93
- If *True*, return a **pandas.DataFrame** indexed by ``date``
94
- with flattened columns (``ios_score``, ``android_score``, etc.);
95
- otherwise return the raw JSON dict.
136
+ If *True*, return a **pandas.DataFrame**; otherwise the raw JSON
137
+ dict, which carries both views.
138
+ per_app :
139
+ Only meaningful with ``as_dataframe``. If *True*, return the
140
+ granular frame — one row per app per observation, with
141
+ ``platform``, ``app_id``, ``app_name``, ``score``,
142
+ ``ratings_count`` and ``install_count``, **not** indexed by date
143
+ since a date repeats across apps. If *False* (default), return the
144
+ blended per-date frame indexed by ``date``, which reports the
145
+ company's biggest app on each platform.
146
+
147
+ Prefer ``per_app=True`` for anything quantitative: a company can
148
+ publish many apps (Apple has 140 on iOS) and which of them matters
149
+ is your judgement, not ours.
96
150
 
97
151
  Returns
98
152
  -------
@@ -111,6 +165,17 @@ class AppRatingsAPI:
111
165
  data = self._c._request("GET", path, params=params)
112
166
 
113
167
  if as_dataframe:
168
+ if per_app:
169
+ flat = _flatten_apps(data.get("apps") or [])
170
+ df = pd.DataFrame(flat)
171
+ if not df.empty and "date" in df.columns:
172
+ df["date"] = pd.to_datetime(df["date"])
173
+ # Deliberately NOT indexed by date: one date carries one
174
+ # row per app, so a date index would not be unique.
175
+ df.sort_values(["app_id", "date"], inplace=True)
176
+ df.reset_index(drop=True, inplace=True)
177
+ return df
178
+
114
179
  rows: List[Dict[str, Any]] = data.get("data", [])
115
180
  flat = _flatten_app_ratings(rows)
116
181
  df = pd.DataFrame(flat)
@@ -118,9 +118,13 @@ class ScreenerAPI:
118
118
  Rows carry ``symbol``, ``name``, ``date``, ``politician``,
119
119
  ``transactionType``, ``amount``, ``owner`` (beneficial owner of the
120
120
  account: ``"SELF"``, ``"SP"``, ``"DC"``, ``"JT"``, or an account
121
- code) and ``disclosureDate`` (the public disclosure date). ``owner``
122
- and ``disclosureDate`` are nullable, though rare — historical rows
123
- were backfilled upstream.
121
+ code), ``amountRaw``, ``amountFlag`` and ``disclosureDate`` (the
122
+ public disclosure date). On rows whose ``amount`` was normalized to
123
+ its STOCK Act bracket, ``amountRaw`` preserves the string as
124
+ originally filed; ``amountFlag`` is ``"review"`` or ``"ambiguous"``
125
+ when the filed amount could not be safely normalized. Both are
126
+ ``None`` on clean rows. ``owner`` and ``disclosureDate`` are
127
+ nullable, though rare — historical rows were backfilled upstream.
124
128
  """
125
129
  params = self._build_params(limit=limit)
126
130
  return self._get("screener/congress/house", params, as_dataframe)
@@ -139,9 +143,14 @@ class ScreenerAPI:
139
143
  Rows carry ``symbol``, ``name``, ``date``, ``politician``,
140
144
  ``transactionType``, ``amount``, ``owner`` (beneficial owner of the
141
145
  account: ``"SELF"``, ``"SP"``, ``"DC"``, ``"JT"``, an account code,
142
- or ``"UNKNOWN"`` for blank Senate filings) and ``disclosureDate``
143
- (the public disclosure date). ``owner`` and ``disclosureDate`` are
144
- nullable, though rare — historical rows were backfilled upstream.
146
+ or ``"UNKNOWN"`` for blank Senate filings), ``amountRaw``,
147
+ ``amountFlag`` and ``disclosureDate`` (the public disclosure date).
148
+ On rows whose ``amount`` was normalized to its STOCK Act bracket,
149
+ ``amountRaw`` preserves the string as originally filed;
150
+ ``amountFlag`` is ``"review"`` or ``"ambiguous"`` when the filed
151
+ amount could not be safely normalized. Both are ``None`` on clean
152
+ rows. ``owner`` and ``disclosureDate`` are nullable, though rare —
153
+ historical rows were backfilled upstream.
145
154
  """
146
155
  params = self._build_params(limit=limit)
147
156
  return self._get("screener/congress/senate", params, as_dataframe)
@@ -26,6 +26,7 @@ class _PlotNamespace:
26
26
  ticker: str,
27
27
  *,
28
28
  store: str = "play",
29
+ app_id: str | None = None,
29
30
  date_from: str | None = None,
30
31
  date_to: str | None = None,
31
32
  as_json: bool = False,
@@ -43,29 +44,76 @@ class _PlotNamespace:
43
44
  ----------
44
45
  store : {'play', 'app'}, default 'play'
45
46
  Which store to visualise.
47
+ app_id :
48
+ Plot one specific app rather than the company's biggest on that
49
+ store. A company can publish many apps — Apple has 140 on iOS —
50
+ and the default picks only the largest, so pass this when you care
51
+ about a particular one. Ids come from
52
+ ``fb.app_ratings.ticker(sym, as_dataframe=True, per_app=True)``.
46
53
  Other args/kwargs identical to the other plotting wrappers.
47
54
  """
55
+ s = store.lower()
56
+ if s in ("play", "playstore", "google", "android"):
57
+ platform = "android"
58
+ elif s in ("app", "appstore", "apple", "ios"):
59
+ platform = "ios"
60
+ else:
61
+ raise ValueError("store must be 'play' or 'app'")
62
+
48
63
  # 1) pull data
49
- df: pd.DataFrame = self._fb.app_ratings.ticker(
50
- ticker,
51
- date_from=date_from,
52
- date_to=date_to,
53
- as_dataframe=True,
54
- **kwargs,
55
- )
64
+ df: pd.DataFrame
65
+ if app_id is not None:
66
+ per_app: pd.DataFrame = self._fb.app_ratings.ticker(
67
+ ticker,
68
+ date_from=date_from,
69
+ date_to=date_to,
70
+ as_dataframe=True,
71
+ per_app=True,
72
+ **kwargs,
73
+ )
74
+ if per_app.empty or "app_id" not in per_app.columns:
75
+ raise ValueError(f"no per-app data available for {ticker}")
76
+ subset = per_app[per_app["app_id"] == app_id]
77
+ if subset.empty:
78
+ available = sorted({a for a in per_app["app_id"].dropna().unique()})
79
+ raise ValueError(
80
+ f"app_id {app_id!r} not found for {ticker}; available: {available}"
81
+ )
82
+ # An app lives on one store. Without this check, asking for an
83
+ # iOS app with store="play" would relabel its series as Android
84
+ # and plot it, which is worse than refusing.
85
+ app_platforms = set(subset["platform"].dropna().unique())
86
+ if app_platforms and platform not in app_platforms:
87
+ raise ValueError(
88
+ f"app_id {app_id!r} is on {'/'.join(sorted(app_platforms))}, "
89
+ f"but store={store!r} plots {platform}"
90
+ )
91
+
92
+ # Reshape to the column names the plotting code below expects.
93
+ df = subset.set_index("date").rename(
94
+ columns={
95
+ "score": f"{platform}_score",
96
+ "ratings_count": f"{platform}_ratingsCount",
97
+ "install_count": f"{platform}_installCount",
98
+ }
99
+ )
100
+ else:
101
+ df = self._fb.app_ratings.ticker(
102
+ ticker,
103
+ date_from=date_from,
104
+ date_to=date_to,
105
+ as_dataframe=True,
106
+ **kwargs,
107
+ )
56
108
 
57
109
  # 2) pick columns & colours
58
- s = store.lower()
59
- if s in ("play", "playstore", "google", "android"):
110
+ if platform == "android":
60
111
  count_col, score_col = "android_ratingsCount", "android_score"
61
112
  count_name, score_name = "Android Ratings Count", "Android Score"
62
- count_color, score_color = "rgba(0,190,0,0.65)", "#02d2ff"
63
- elif s in ("app", "appstore", "apple", "ios"):
113
+ else:
64
114
  count_col, score_col = "ios_ratingsCount", "ios_score"
65
115
  count_name, score_name = "iOS Ratings Count", "iOS Score"
66
- count_color, score_color = "rgba(0,190,0,0.65)", "#02d2ff"
67
- else:
68
- raise ValueError("store must be 'play' or 'app'")
116
+ count_color, score_color = "rgba(0,190,0,0.65)", "#02d2ff"
69
117
 
70
118
  # 3) dynamic axis ranges
71
119
  max_cnt = float(df[count_col].max())
@@ -912,9 +960,7 @@ class _PlotNamespace:
912
960
  mentions_normalized = self._to_naive_index(mentions_df)
913
961
 
914
962
  # Exclude _all (aggregate) — use individual subreddits for stacked bars
915
- per_sub = mentions_normalized[
916
- mentions_normalized["subreddit"] != "_all"
917
- ]
963
+ per_sub = mentions_normalized[mentions_normalized["subreddit"] != "_all"]
918
964
 
919
965
  if not per_sub.empty:
920
966
  for subreddit in sorted(per_sub["subreddit"].unique()):
@@ -1010,7 +1056,9 @@ class _PlotNamespace:
1010
1056
  latest[sym] = row
1011
1057
 
1012
1058
  # Sort by totalMentions descending, take top N
1013
- ranked = sorted(latest.values(), key=lambda r: r.get("totalMentions", 0), reverse=True)
1059
+ ranked = sorted(
1060
+ latest.values(), key=lambda r: r.get("totalMentions", 0), reverse=True
1061
+ )
1014
1062
  top = ranked[:top_n]
1015
1063
 
1016
1064
  # Reverse so the highest-mentioned ticker is at the top of the chart
@@ -1406,7 +1454,9 @@ class _PlotNamespace:
1406
1454
  """Nearest available price for a rating date."""
1407
1455
  if when in price_data_normalized.index:
1408
1456
  return price_data_normalized.loc[when, price_col]
1409
- idx = price_data_normalized.index.get_indexer([when], method="nearest")[0]
1457
+ idx = price_data_normalized.index.get_indexer([when], method="nearest")[
1458
+ 0
1459
+ ]
1410
1460
  if 0 <= idx < len(price_data_normalized):
1411
1461
  return price_data_normalized.iloc[idx][price_col]
1412
1462
  return None
@@ -1434,8 +1484,7 @@ class _PlotNamespace:
1434
1484
 
1435
1485
  # Bucket each rating row by action category
1436
1486
  buckets: dict[str, dict[str, list]] = {
1437
- key: {"x": [], "y": [], "symbol": [], "hover": []}
1438
- for key in categories
1487
+ key: {"x": [], "y": [], "symbol": [], "hover": []} for key in categories
1439
1488
  }
1440
1489
 
1441
1490
  for pos, (when, row) in enumerate(ratings_normalized.iterrows()):