scigantic-who 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.
- scigantic_who-0.1.0/LICENSE +16 -0
- scigantic_who-0.1.0/PKG-INFO +142 -0
- scigantic_who-0.1.0/README.md +107 -0
- scigantic_who-0.1.0/pyproject.toml +59 -0
- scigantic_who-0.1.0/setup.cfg +4 -0
- scigantic_who-0.1.0/src/scigantic_who/__init__.py +35 -0
- scigantic_who-0.1.0/src/scigantic_who/_constants.py +59 -0
- scigantic_who-0.1.0/src/scigantic_who/catalog.py +64 -0
- scigantic_who-0.1.0/src/scigantic_who/cli.py +87 -0
- scigantic_who-0.1.0/src/scigantic_who/connection.py +162 -0
- scigantic_who-0.1.0/src/scigantic_who/data.py +151 -0
- scigantic_who-0.1.0/src/scigantic_who/live.py +69 -0
- scigantic_who-0.1.0/src/scigantic_who/py.typed +0 -0
- scigantic_who-0.1.0/src/scigantic_who.egg-info/PKG-INFO +142 -0
- scigantic_who-0.1.0/src/scigantic_who.egg-info/SOURCES.txt +19 -0
- scigantic_who-0.1.0/src/scigantic_who.egg-info/dependency_links.txt +1 -0
- scigantic_who-0.1.0/src/scigantic_who.egg-info/entry_points.txt +2 -0
- scigantic_who-0.1.0/src/scigantic_who.egg-info/requires.txt +9 -0
- scigantic_who-0.1.0/src/scigantic_who.egg-info/top_level.txt +1 -0
- scigantic_who-0.1.0/tests/test_fixture_mirror.py +135 -0
- scigantic_who-0.1.0/tests/test_live.py +45 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
MIT No Attribution
|
|
2
|
+
|
|
3
|
+
Copyright 2026 Scigantic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
6
|
+
software and associated documentation files (the "Software"), to deal in the Software
|
|
7
|
+
without restriction, including without limitation the rights to use, copy, modify,
|
|
8
|
+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
permit persons to whom the Software is furnished to do so.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
12
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
13
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
14
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
15
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
16
|
+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scigantic-who
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Query every WHO Global Health Observatory indicator from a public parquet mirror over DuckDB (one query instead of 3,099 API calls), decode WHO's dimension codes, or fetch a fresh indicator from the live OData API in the same shape.
|
|
5
|
+
Author-email: Scigantic <support@scigantic.com>
|
|
6
|
+
License: MIT-0
|
|
7
|
+
Project-URL: Homepage, https://scigantic.com
|
|
8
|
+
Project-URL: Repository, https://github.com/Scigantic/scigantic-who
|
|
9
|
+
Project-URL: Issues, https://github.com/Scigantic/scigantic-who/issues
|
|
10
|
+
Project-URL: GHO, https://www.who.int/data/gho
|
|
11
|
+
Keywords: who,global health observatory,gho,public health,epidemiology,health indicators,duckdb
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT No Attribution License (MIT-0)
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Classifier: Development Status :: 4 - Beta
|
|
21
|
+
Classifier: Intended Audience :: Science/Research
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: duckdb<2,>=0.10
|
|
27
|
+
Requires-Dist: pandas<4,>=1.5
|
|
28
|
+
Requires-Dist: pyarrow<23,>=12
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
32
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
33
|
+
Requires-Dist: pandas-stubs; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
<h1 align="center">scigantic-who</h1>
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<a href="https://github.com/Scigantic/scigantic-who/actions/workflows/ci.yml">
|
|
40
|
+
<img alt="CI" src="https://github.com/Scigantic/scigantic-who/actions/workflows/ci.yml/badge.svg" /></a>
|
|
41
|
+
<a href="https://pypi.org/project/scigantic-who/">
|
|
42
|
+
<img alt="PyPI" src="https://img.shields.io/pypi/v/scigantic-who" /></a>
|
|
43
|
+
<a href="https://pypi.org/project/scigantic-who/">
|
|
44
|
+
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/scigantic-who" /></a>
|
|
45
|
+
<a href="https://github.com/Scigantic/scigantic-who/blob/main/LICENSE">
|
|
46
|
+
<img alt="License" src="https://img.shields.io/github/license/Scigantic/scigantic-who" /></a>
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
Query the WHO [Global Health Observatory](https://www.who.int/data/gho) from Python: every indicator, from a public parquet mirror over DuckDB, with WHO's codes decoded. No API key, no download, no local database.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import scigantic_who as who
|
|
53
|
+
|
|
54
|
+
who.indicators("life expectancy")
|
|
55
|
+
df = who.data("WHOSIS_000001", countries=["JPN", "NGA"], dims={"SEX": who.BOTH_SEXES}, decode=True)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
That runs against `s3://scigantic-who` over DuckDB's httpfs extension. Inside a Scigantic notebook with the archive mounted, the same call reads the mount instead.
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
```console
|
|
63
|
+
$ pip install scigantic-who
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Why this exists
|
|
67
|
+
|
|
68
|
+
WHO's GHO OData API serves one indicator per request and has no bulk download. Pulling the observatory means 3,099 requests and about 6 GB of JSON, and the API serves large indicators at roughly 1 MB/s. [ghoclient](https://pypi.org/project/ghoclient/) (1.2.0, May 2026) is the existing Python client and is a good live wrapper: indicator search, country and region lists, one indicator at a time as a DataFrame. It has no bulk path, no decoding of the `Dim1`..`Dim3` codes to labels, and no DuckDB.
|
|
69
|
+
|
|
70
|
+
This package adds the mirror. `s3://scigantic-who/gho/` holds all 3,099 indicators (9.9 million observations) as parquet, rebuilt monthly, plus the lookup tables that turn every code into a label. One SQL statement over `observations` replaces thousands of API calls, and `data()` makes the pins a GHO query needs explicit. The live API is still here, in `who.live`, returning the same 25 columns so everything else works on a fresh pull too.
|
|
71
|
+
|
|
72
|
+
## The shape of a GHO indicator, and the three mistakes this package prevents
|
|
73
|
+
|
|
74
|
+
A GHO indicator file holds every disaggregation and every spatial level at once: both sexes plus male plus female, every age group plus all ages, countries plus WHO regions plus income groups plus the world. Three things follow.
|
|
75
|
+
|
|
76
|
+
**Pin the spatial level.** `data()` keeps `SpatialDimType = 'COUNTRY'` by default; pass `spatial_type=None` to see regions and the world too.
|
|
77
|
+
|
|
78
|
+
**Pin the disaggregations by type, not by slot.** `Dim1` is a sex code for one indicator and an age group for another. `dims={"SEX": "SEX_BTSX"}` matches whichever of `Dim1`..`Dim3` carries `SEX` for this indicator.
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
who.data("MORT_100", countries="NGA", years=2021,
|
|
82
|
+
dims={"SEX": who.BOTH_SEXES, "AGEGROUP": "AGEGROUP_YEARS0-4"}, decode=True)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
(`MORT_100` is under-five deaths by cause; the cause sits in `Dim3`.) "All ages" alone is spelled three ways across indicators (`AGEGROUP_AGEAll`, `AGEGROUP_YEARSALL`, `AGEGROUP_ALLAges`, listed in `who.ALL_AGES_CODES`), so look the right one up in `dimension_values` for your indicator.
|
|
86
|
+
|
|
87
|
+
**Decode on (dimension, code), never on code alone.** The same code string can exist under different dimensions. `decode=True` and `who.decode(df)` join `dimension_values` on the pair.
|
|
88
|
+
|
|
89
|
+
Three more facts worth knowing. The `GHE_*` burden series (DALYs, YLLs, YLDs by cause) exist in the GHO only as global and GHE-region aggregates for 2000 and 2012; WHO's country-level Global Health Estimates are a separate download the API does not carry. `Value` is the published string (`48.1 [45.4-50.8]`, or a category); `NumericValue`, `Low` and `High` are the numbers. And 612 of the 3,099 catalog entries have no data behind them; `indicators()` hides them unless you ask.
|
|
90
|
+
|
|
91
|
+
## What is in the mirror
|
|
92
|
+
|
|
93
|
+
| path | what |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `gho/indicators.parquet` | code, name, `row_count`, first and last year, number of spatial units, `archived` |
|
|
96
|
+
| `gho/dimensions.parquet` | the 202 dimension codes |
|
|
97
|
+
| `gho/dimension_values.parquet` | 20,860 rows: every code in every dimension, with `Title`, `ParentCode`, `ParentTitle` |
|
|
98
|
+
| `gho/observations.parquet` | 9,944,921 rows, every indicator, ordered by `IndicatorCode` |
|
|
99
|
+
| `gho/data/<IndicatorCode>.parquet` | the same rows, one file per indicator |
|
|
100
|
+
| `_MANIFEST.json` | when the mirror was pulled and the row counts; `who.manifest()` |
|
|
101
|
+
| `_MIRROR.txt` | WHO's terms and the attribution they require |
|
|
102
|
+
|
|
103
|
+
## Raw SQL
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
con = who.connect() # views: indicators, dimensions, dimension_values, observations
|
|
107
|
+
con.sql("""
|
|
108
|
+
select o.SpatialDim, c.Title, o.TimeDim, o.NumericValue
|
|
109
|
+
from observations o
|
|
110
|
+
join dimension_values c on c.Dimension = 'COUNTRY' and c.Code = o.SpatialDim
|
|
111
|
+
where o.IndicatorCode = 'MDG_0000000001' and o.Dim1 = 'SEX_BTSX' and o.TimeDim = 2022
|
|
112
|
+
order by o.NumericValue desc limit 10
|
|
113
|
+
""").show()
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`who.query(sql)` does the same and returns a DataFrame. `observations.parquet` is ordered by `IndicatorCode`, so a `WHERE IndicatorCode = ...` reads a few row groups, not the file.
|
|
117
|
+
|
|
118
|
+
## Live API
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
fresh = who.live.fetch("WHOSIS_000001", odata_filter="SpatialDim eq 'JPN' and TimeDim ge 2015")
|
|
122
|
+
who.decode(fresh)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`who.live.indicators()` lists the catalog as WHO publishes it today, for spotting codes added since the last mirror run.
|
|
126
|
+
|
|
127
|
+
## Where it reads from
|
|
128
|
+
|
|
129
|
+
In order: an explicit `source=` (a directory or an `s3://` prefix), the `SCIGANTIC_WHO_PATH` environment variable, a Scigantic notebook mount (`$SCIGANTIC_MOUNT_PATH`, `/mnt/archive`, `/home/jovyan/archive`), then `s3://scigantic-who`.
|
|
130
|
+
|
|
131
|
+
## Command line
|
|
132
|
+
|
|
133
|
+
```console
|
|
134
|
+
$ scigantic-who search "under-five"
|
|
135
|
+
$ scigantic-who data MDG_0000000001 --country NGA --years 2010-2022 --dim SEX=SEX_BTSX --decode
|
|
136
|
+
$ scigantic-who query "select count(*) from observations"
|
|
137
|
+
$ scigantic-who info
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Data terms
|
|
141
|
+
|
|
142
|
+
The data is WHO's. WHO's [terms](https://www.who.int/about/policies/publishing/data-policy/terms-and-conditions) grant a royalty-free right to use, reproduce and distribute the datasets for public health purposes, require attribution in the form `WHO, Global Health Observatory data, <year>, accessed <date>` with acknowledgement of the reporting countries, and bar use in connection with the promotion of a commercial enterprise. The mirror changes storage format only; `_MIRROR.txt` carries the full notice. This package's own code is MIT-0.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<h1 align="center">scigantic-who</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://github.com/Scigantic/scigantic-who/actions/workflows/ci.yml">
|
|
5
|
+
<img alt="CI" src="https://github.com/Scigantic/scigantic-who/actions/workflows/ci.yml/badge.svg" /></a>
|
|
6
|
+
<a href="https://pypi.org/project/scigantic-who/">
|
|
7
|
+
<img alt="PyPI" src="https://img.shields.io/pypi/v/scigantic-who" /></a>
|
|
8
|
+
<a href="https://pypi.org/project/scigantic-who/">
|
|
9
|
+
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/scigantic-who" /></a>
|
|
10
|
+
<a href="https://github.com/Scigantic/scigantic-who/blob/main/LICENSE">
|
|
11
|
+
<img alt="License" src="https://img.shields.io/github/license/Scigantic/scigantic-who" /></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
Query the WHO [Global Health Observatory](https://www.who.int/data/gho) from Python: every indicator, from a public parquet mirror over DuckDB, with WHO's codes decoded. No API key, no download, no local database.
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
import scigantic_who as who
|
|
18
|
+
|
|
19
|
+
who.indicators("life expectancy")
|
|
20
|
+
df = who.data("WHOSIS_000001", countries=["JPN", "NGA"], dims={"SEX": who.BOTH_SEXES}, decode=True)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
That runs against `s3://scigantic-who` over DuckDB's httpfs extension. Inside a Scigantic notebook with the archive mounted, the same call reads the mount instead.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```console
|
|
28
|
+
$ pip install scigantic-who
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Why this exists
|
|
32
|
+
|
|
33
|
+
WHO's GHO OData API serves one indicator per request and has no bulk download. Pulling the observatory means 3,099 requests and about 6 GB of JSON, and the API serves large indicators at roughly 1 MB/s. [ghoclient](https://pypi.org/project/ghoclient/) (1.2.0, May 2026) is the existing Python client and is a good live wrapper: indicator search, country and region lists, one indicator at a time as a DataFrame. It has no bulk path, no decoding of the `Dim1`..`Dim3` codes to labels, and no DuckDB.
|
|
34
|
+
|
|
35
|
+
This package adds the mirror. `s3://scigantic-who/gho/` holds all 3,099 indicators (9.9 million observations) as parquet, rebuilt monthly, plus the lookup tables that turn every code into a label. One SQL statement over `observations` replaces thousands of API calls, and `data()` makes the pins a GHO query needs explicit. The live API is still here, in `who.live`, returning the same 25 columns so everything else works on a fresh pull too.
|
|
36
|
+
|
|
37
|
+
## The shape of a GHO indicator, and the three mistakes this package prevents
|
|
38
|
+
|
|
39
|
+
A GHO indicator file holds every disaggregation and every spatial level at once: both sexes plus male plus female, every age group plus all ages, countries plus WHO regions plus income groups plus the world. Three things follow.
|
|
40
|
+
|
|
41
|
+
**Pin the spatial level.** `data()` keeps `SpatialDimType = 'COUNTRY'` by default; pass `spatial_type=None` to see regions and the world too.
|
|
42
|
+
|
|
43
|
+
**Pin the disaggregations by type, not by slot.** `Dim1` is a sex code for one indicator and an age group for another. `dims={"SEX": "SEX_BTSX"}` matches whichever of `Dim1`..`Dim3` carries `SEX` for this indicator.
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
who.data("MORT_100", countries="NGA", years=2021,
|
|
47
|
+
dims={"SEX": who.BOTH_SEXES, "AGEGROUP": "AGEGROUP_YEARS0-4"}, decode=True)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
(`MORT_100` is under-five deaths by cause; the cause sits in `Dim3`.) "All ages" alone is spelled three ways across indicators (`AGEGROUP_AGEAll`, `AGEGROUP_YEARSALL`, `AGEGROUP_ALLAges`, listed in `who.ALL_AGES_CODES`), so look the right one up in `dimension_values` for your indicator.
|
|
51
|
+
|
|
52
|
+
**Decode on (dimension, code), never on code alone.** The same code string can exist under different dimensions. `decode=True` and `who.decode(df)` join `dimension_values` on the pair.
|
|
53
|
+
|
|
54
|
+
Three more facts worth knowing. The `GHE_*` burden series (DALYs, YLLs, YLDs by cause) exist in the GHO only as global and GHE-region aggregates for 2000 and 2012; WHO's country-level Global Health Estimates are a separate download the API does not carry. `Value` is the published string (`48.1 [45.4-50.8]`, or a category); `NumericValue`, `Low` and `High` are the numbers. And 612 of the 3,099 catalog entries have no data behind them; `indicators()` hides them unless you ask.
|
|
55
|
+
|
|
56
|
+
## What is in the mirror
|
|
57
|
+
|
|
58
|
+
| path | what |
|
|
59
|
+
|---|---|
|
|
60
|
+
| `gho/indicators.parquet` | code, name, `row_count`, first and last year, number of spatial units, `archived` |
|
|
61
|
+
| `gho/dimensions.parquet` | the 202 dimension codes |
|
|
62
|
+
| `gho/dimension_values.parquet` | 20,860 rows: every code in every dimension, with `Title`, `ParentCode`, `ParentTitle` |
|
|
63
|
+
| `gho/observations.parquet` | 9,944,921 rows, every indicator, ordered by `IndicatorCode` |
|
|
64
|
+
| `gho/data/<IndicatorCode>.parquet` | the same rows, one file per indicator |
|
|
65
|
+
| `_MANIFEST.json` | when the mirror was pulled and the row counts; `who.manifest()` |
|
|
66
|
+
| `_MIRROR.txt` | WHO's terms and the attribution they require |
|
|
67
|
+
|
|
68
|
+
## Raw SQL
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
con = who.connect() # views: indicators, dimensions, dimension_values, observations
|
|
72
|
+
con.sql("""
|
|
73
|
+
select o.SpatialDim, c.Title, o.TimeDim, o.NumericValue
|
|
74
|
+
from observations o
|
|
75
|
+
join dimension_values c on c.Dimension = 'COUNTRY' and c.Code = o.SpatialDim
|
|
76
|
+
where o.IndicatorCode = 'MDG_0000000001' and o.Dim1 = 'SEX_BTSX' and o.TimeDim = 2022
|
|
77
|
+
order by o.NumericValue desc limit 10
|
|
78
|
+
""").show()
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`who.query(sql)` does the same and returns a DataFrame. `observations.parquet` is ordered by `IndicatorCode`, so a `WHERE IndicatorCode = ...` reads a few row groups, not the file.
|
|
82
|
+
|
|
83
|
+
## Live API
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
fresh = who.live.fetch("WHOSIS_000001", odata_filter="SpatialDim eq 'JPN' and TimeDim ge 2015")
|
|
87
|
+
who.decode(fresh)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`who.live.indicators()` lists the catalog as WHO publishes it today, for spotting codes added since the last mirror run.
|
|
91
|
+
|
|
92
|
+
## Where it reads from
|
|
93
|
+
|
|
94
|
+
In order: an explicit `source=` (a directory or an `s3://` prefix), the `SCIGANTIC_WHO_PATH` environment variable, a Scigantic notebook mount (`$SCIGANTIC_MOUNT_PATH`, `/mnt/archive`, `/home/jovyan/archive`), then `s3://scigantic-who`.
|
|
95
|
+
|
|
96
|
+
## Command line
|
|
97
|
+
|
|
98
|
+
```console
|
|
99
|
+
$ scigantic-who search "under-five"
|
|
100
|
+
$ scigantic-who data MDG_0000000001 --country NGA --years 2010-2022 --dim SEX=SEX_BTSX --decode
|
|
101
|
+
$ scigantic-who query "select count(*) from observations"
|
|
102
|
+
$ scigantic-who info
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Data terms
|
|
106
|
+
|
|
107
|
+
The data is WHO's. WHO's [terms](https://www.who.int/about/policies/publishing/data-policy/terms-and-conditions) grant a royalty-free right to use, reproduce and distribute the datasets for public health purposes, require attribution in the form `WHO, Global Health Observatory data, <year>, accessed <date>` with acknowledgement of the reporting countries, and bar use in connection with the promotion of a commercial enterprise. The mirror changes storage format only; `_MIRROR.txt` carries the full notice. This package's own code is MIT-0.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "scigantic-who"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Query every WHO Global Health Observatory indicator from a public parquet mirror over DuckDB (one query instead of 3,099 API calls), decode WHO's dimension codes, or fetch a fresh indicator from the live OData API in the same shape."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT-0" }
|
|
12
|
+
authors = [{ name = "Scigantic", email = "support@scigantic.com" }]
|
|
13
|
+
keywords = ["who", "global health observatory", "gho", "public health", "epidemiology", "health indicators", "duckdb"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"License :: OSI Approved :: MIT No Attribution License (MIT-0)",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Programming Language :: Python :: 3.14",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
"Development Status :: 4 - Beta",
|
|
24
|
+
"Intended Audience :: Science/Research",
|
|
25
|
+
"Topic :: Scientific/Engineering :: Medical Science Apps.",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
dependencies = [
|
|
29
|
+
"duckdb>=0.10,<2",
|
|
30
|
+
"pandas>=1.5,<4",
|
|
31
|
+
"pyarrow>=12,<23",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = ["pytest>=7", "pytest-cov>=5", "mypy>=1.10", "pandas-stubs"]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://scigantic.com"
|
|
39
|
+
Repository = "https://github.com/Scigantic/scigantic-who"
|
|
40
|
+
Issues = "https://github.com/Scigantic/scigantic-who/issues"
|
|
41
|
+
GHO = "https://www.who.int/data/gho"
|
|
42
|
+
|
|
43
|
+
[project.scripts]
|
|
44
|
+
scigantic-who = "scigantic_who.cli:main"
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.packages.find]
|
|
47
|
+
where = ["src"]
|
|
48
|
+
|
|
49
|
+
[tool.setuptools.package-data]
|
|
50
|
+
scigantic_who = ["py.typed"]
|
|
51
|
+
|
|
52
|
+
[tool.pytest.ini_options]
|
|
53
|
+
testpaths = ["tests"]
|
|
54
|
+
|
|
55
|
+
[tool.coverage.run]
|
|
56
|
+
source = ["scigantic_who"]
|
|
57
|
+
|
|
58
|
+
[tool.mypy]
|
|
59
|
+
strict = true
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""scigantic-who: every WHO Global Health Observatory indicator, queryable in one place.
|
|
2
|
+
|
|
3
|
+
import scigantic_who as who
|
|
4
|
+
|
|
5
|
+
who.indicators("life expectancy") # find a code
|
|
6
|
+
who.data("WHOSIS_000001", countries=["JPN", "NGA"], # read it from the mirror
|
|
7
|
+
dims={"SEX": who.BOTH_SEXES}, decode=True)
|
|
8
|
+
who.live.fetch("WHOSIS_000001", odata_filter="SpatialDim eq 'JPN'") # or from WHO right now
|
|
9
|
+
who.query("SELECT ... FROM observations") # or raw SQL over everything
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from . import live
|
|
13
|
+
from ._constants import ALL_AGES_CODES, ALL_CAUSES, BOTH_SEXES
|
|
14
|
+
from .catalog import countries, dimension_values, dimensions, indicators
|
|
15
|
+
from .connection import connect, manifest, query, resolve_source
|
|
16
|
+
from .data import data, decode
|
|
17
|
+
|
|
18
|
+
__version__ = "0.1.0"
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"ALL_AGES_CODES",
|
|
22
|
+
"ALL_CAUSES",
|
|
23
|
+
"BOTH_SEXES",
|
|
24
|
+
"connect",
|
|
25
|
+
"countries",
|
|
26
|
+
"data",
|
|
27
|
+
"decode",
|
|
28
|
+
"dimension_values",
|
|
29
|
+
"dimensions",
|
|
30
|
+
"indicators",
|
|
31
|
+
"live",
|
|
32
|
+
"manifest",
|
|
33
|
+
"query",
|
|
34
|
+
"resolve_source",
|
|
35
|
+
]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Shared constants: where the mirror lives, where the live API is, and the one schema both share."""
|
|
2
|
+
|
|
3
|
+
BUCKET = "scigantic-who"
|
|
4
|
+
REGION = "us-east-1"
|
|
5
|
+
S3_PREFIX = f"s3://{BUCKET}"
|
|
6
|
+
HTTPS_PREFIX = f"https://{BUCKET}.s3.amazonaws.com"
|
|
7
|
+
|
|
8
|
+
# WHO's Global Health Observatory OData API. Public, no key, one indicator per
|
|
9
|
+
# request, no bulk download: that last fact is why the mirror exists.
|
|
10
|
+
GHO_API = "https://ghoapi.azureedge.net/api"
|
|
11
|
+
|
|
12
|
+
# Point the package at a local copy of the mirror (a Scigantic notebook mount,
|
|
13
|
+
# or a `who_mirror.py --work` build) instead of S3. Resolved in connection.py.
|
|
14
|
+
SOURCE_ENV = "SCIGANTIC_WHO_PATH"
|
|
15
|
+
MOUNT_ENV = "SCIGANTIC_MOUNT_PATH"
|
|
16
|
+
DEFAULT_MOUNTS = ("/mnt/archive", "/home/jovyan/archive")
|
|
17
|
+
|
|
18
|
+
USER_AGENT = "scigantic-who/0.1.0 (+https://github.com/Scigantic/scigantic-who)"
|
|
19
|
+
|
|
20
|
+
# The observation schema, identical in the mirror's parquet files and in what
|
|
21
|
+
# live.fetch() returns. These are the OData entity's own property names.
|
|
22
|
+
OBS_COLUMNS: tuple[str, ...] = (
|
|
23
|
+
"Id",
|
|
24
|
+
"IndicatorCode",
|
|
25
|
+
"SpatialDimType",
|
|
26
|
+
"SpatialDim",
|
|
27
|
+
"ParentLocationCode",
|
|
28
|
+
"ParentLocation",
|
|
29
|
+
"TimeDimType",
|
|
30
|
+
"TimeDim",
|
|
31
|
+
"TimeDimensionValue",
|
|
32
|
+
"TimeDimensionBegin",
|
|
33
|
+
"TimeDimensionEnd",
|
|
34
|
+
"Dim1Type",
|
|
35
|
+
"Dim1",
|
|
36
|
+
"Dim2Type",
|
|
37
|
+
"Dim2",
|
|
38
|
+
"Dim3Type",
|
|
39
|
+
"Dim3",
|
|
40
|
+
"DataSourceDimType",
|
|
41
|
+
"DataSourceDim",
|
|
42
|
+
"Value",
|
|
43
|
+
"NumericValue",
|
|
44
|
+
"Low",
|
|
45
|
+
"High",
|
|
46
|
+
"Comments",
|
|
47
|
+
"Date",
|
|
48
|
+
)
|
|
49
|
+
INT_COLUMNS = ("Id", "TimeDim")
|
|
50
|
+
FLOAT_COLUMNS = ("NumericValue", "Low", "High")
|
|
51
|
+
|
|
52
|
+
# Well-known codes, so callers do not have to remember WHO's spelling.
|
|
53
|
+
BOTH_SEXES = "SEX_BTSX"
|
|
54
|
+
# "All ages" is spelled three ways across indicators (measured on the 2026-10
|
|
55
|
+
# mirror: AGEGROUP_AGEAll in 268k rows, AGEGROUP_YEARSALL in 56k, AGEGROUP_ALLAges
|
|
56
|
+
# rarely). Look up which one your indicator uses in dimension_values; dims={"AGEGROUP":
|
|
57
|
+
# ...} accepts any of them, and ALL_AGES_CODES is the full set.
|
|
58
|
+
ALL_AGES_CODES = ("AGEGROUP_AGEAll", "AGEGROUP_YEARSALL", "AGEGROUP_ALLAges")
|
|
59
|
+
ALL_CAUSES = "GHECAUSES_GHE000"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""The catalog half: find indicators, list dimensions, decode codes."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from .connection import query
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
import pandas as pd
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def indicators(
|
|
14
|
+
search: str | None = None,
|
|
15
|
+
*,
|
|
16
|
+
include_empty: bool = False,
|
|
17
|
+
include_archived: bool = False,
|
|
18
|
+
source: str | None = None,
|
|
19
|
+
) -> "pd.DataFrame":
|
|
20
|
+
"""Indicators in the mirror, optionally filtered by a case-insensitive name/code substring.
|
|
21
|
+
|
|
22
|
+
By default hides the 612 catalog entries with no data (row_count = 0) and
|
|
23
|
+
the 36 named "Archived, see <replacement>", because a name search that
|
|
24
|
+
returns them is mostly noise. Columns: IndicatorCode, IndicatorName,
|
|
25
|
+
row_count, first_year, last_year, n_spatial_units, archived.
|
|
26
|
+
"""
|
|
27
|
+
clauses, params = [], []
|
|
28
|
+
if not include_empty:
|
|
29
|
+
clauses.append("row_count > 0")
|
|
30
|
+
if not include_archived:
|
|
31
|
+
clauses.append("NOT archived")
|
|
32
|
+
if search:
|
|
33
|
+
clauses.append("(IndicatorName ILIKE ? OR IndicatorCode ILIKE ?)")
|
|
34
|
+
params.extend([f"%{search}%", f"%{search}%"])
|
|
35
|
+
where = f"WHERE {' AND '.join(clauses)}" if clauses else ""
|
|
36
|
+
return query(f"SELECT * FROM indicators {where} ORDER BY row_count DESC, IndicatorCode", source, params)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def dimensions(source: str | None = None) -> "pd.DataFrame":
|
|
40
|
+
"""The dimension codes (COUNTRY, REGION, SEX, AGEGROUP, GHECAUSES, ...) with titles."""
|
|
41
|
+
return query("SELECT * FROM dimensions ORDER BY Code", source)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def dimension_values(dimension: str | None = None, source: str | None = None) -> "pd.DataFrame":
|
|
45
|
+
"""Every code under one dimension (or all), with Title, ParentDimension, ParentCode, ParentTitle.
|
|
46
|
+
|
|
47
|
+
This is the table that turns SpatialDim / Dim1..Dim3 codes into labels. It is
|
|
48
|
+
keyed by (Dimension, Code): the same Code string can exist under several
|
|
49
|
+
dimensions, so never join on Code alone.
|
|
50
|
+
"""
|
|
51
|
+
if dimension:
|
|
52
|
+
return query(
|
|
53
|
+
"SELECT * FROM dimension_values WHERE Dimension = ? ORDER BY Code", source, [dimension]
|
|
54
|
+
)
|
|
55
|
+
return query("SELECT * FROM dimension_values ORDER BY Dimension, Code", source)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def countries(source: str | None = None) -> "pd.DataFrame":
|
|
59
|
+
"""The COUNTRY dimension: ISO3 code, name, and the WHO region it belongs to."""
|
|
60
|
+
return query(
|
|
61
|
+
"SELECT Code AS iso3, Title AS country, ParentCode AS who_region_code, ParentTitle AS who_region "
|
|
62
|
+
"FROM dimension_values WHERE Dimension = 'COUNTRY' ORDER BY Code",
|
|
63
|
+
source,
|
|
64
|
+
)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Command-line interface: `scigantic-who search|data|query|info`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
from collections.abc import Sequence
|
|
7
|
+
|
|
8
|
+
from .catalog import indicators
|
|
9
|
+
from .connection import manifest, query as run_query, resolve_source
|
|
10
|
+
from .data import data
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _cmd_search(args: argparse.Namespace) -> int:
|
|
14
|
+
df = indicators(args.text, include_empty=args.include_empty, source=args.source)
|
|
15
|
+
print(df.to_csv(sep="\t", index=False), end="")
|
|
16
|
+
return 0
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _cmd_data(args: argparse.Namespace) -> int:
|
|
20
|
+
dims = dict(kv.split("=", 1) for kv in args.dim) if args.dim else None
|
|
21
|
+
years: tuple[int, int] | None = None
|
|
22
|
+
if args.years:
|
|
23
|
+
a, _, b = args.years.partition("-")
|
|
24
|
+
years = (int(a), int(b or a))
|
|
25
|
+
df = data(
|
|
26
|
+
args.code,
|
|
27
|
+
countries=args.country or None,
|
|
28
|
+
years=years,
|
|
29
|
+
spatial_type=None if args.all_levels else "COUNTRY",
|
|
30
|
+
dims=dims,
|
|
31
|
+
decode=args.decode,
|
|
32
|
+
source=args.source,
|
|
33
|
+
)
|
|
34
|
+
print(df.to_csv(sep="\t", index=False), end="")
|
|
35
|
+
return 0
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _cmd_query(args: argparse.Namespace) -> int:
|
|
39
|
+
print(run_query(args.sql, source=args.source).to_csv(sep="\t", index=False), end="")
|
|
40
|
+
return 0
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _cmd_info(args: argparse.Namespace) -> int:
|
|
44
|
+
src = resolve_source(args.source)
|
|
45
|
+
m = manifest(src)
|
|
46
|
+
g = m.get("gho", {})
|
|
47
|
+
print(f"source {src}")
|
|
48
|
+
print(f"mirrored {m.get('mirroredAt')}")
|
|
49
|
+
print(f"indicators {g.get('indicators')} ({g.get('indicatorsWithData')} with data)")
|
|
50
|
+
print(f"observations {g.get('observations'):,}" if g.get("observations") else "observations ?")
|
|
51
|
+
print(f"dimensions {g.get('dimensions')} / {g.get('dimensionValues')} values")
|
|
52
|
+
return 0
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
56
|
+
parser = argparse.ArgumentParser(prog="scigantic-who")
|
|
57
|
+
parser.add_argument("--source", default=None, help="mirror directory or s3:// prefix (default: auto)")
|
|
58
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
59
|
+
|
|
60
|
+
p = sub.add_parser("search", help="find indicators by name or code substring")
|
|
61
|
+
p.add_argument("text")
|
|
62
|
+
p.add_argument("--include-empty", action="store_true", help="also list indicators with no data")
|
|
63
|
+
p.set_defaults(func=_cmd_search)
|
|
64
|
+
|
|
65
|
+
p = sub.add_parser("data", help="observations for one indicator, tab-separated")
|
|
66
|
+
p.add_argument("code")
|
|
67
|
+
p.add_argument("--country", action="append", help="ISO3, repeatable")
|
|
68
|
+
p.add_argument("--years", help="YYYY or YYYY-YYYY")
|
|
69
|
+
p.add_argument("--dim", action="append", help="pin a dimension, e.g. SEX=SEX_BTSX (repeatable)")
|
|
70
|
+
p.add_argument("--all-levels", action="store_true", help="keep regions/income groups/world too")
|
|
71
|
+
p.add_argument("--decode", action="store_true", help="add *_name label columns")
|
|
72
|
+
p.set_defaults(func=_cmd_data)
|
|
73
|
+
|
|
74
|
+
p = sub.add_parser("query", help="run SQL (views: indicators, dimensions, dimension_values, observations)")
|
|
75
|
+
p.add_argument("sql")
|
|
76
|
+
p.set_defaults(func=_cmd_query)
|
|
77
|
+
|
|
78
|
+
p = sub.add_parser("info", help="which mirror is in use and when it was pulled")
|
|
79
|
+
p.set_defaults(func=_cmd_info)
|
|
80
|
+
|
|
81
|
+
args = parser.parse_args(argv)
|
|
82
|
+
result: int = args.func(args)
|
|
83
|
+
return result
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
raise SystemExit(main())
|