unicefdata 2.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.
Files changed (141) hide show
  1. unicefdata-2.1.0/LICENSE +21 -0
  2. unicefdata-2.1.0/PKG-INFO +358 -0
  3. unicefdata-2.1.0/README.md +317 -0
  4. unicefdata-2.1.0/pyproject.toml +57 -0
  5. unicefdata-2.1.0/setup.cfg +4 -0
  6. unicefdata-2.1.0/tests/test_404_fallback.py +107 -0
  7. unicefdata-2.1.0/tests/test_dimensions.py +95 -0
  8. unicefdata-2.1.0/tests/test_download.py +40 -0
  9. unicefdata-2.1.0/tests/test_fallback_fix.py +83 -0
  10. unicefdata-2.1.0/tests/test_list_dataflows.py +94 -0
  11. unicefdata-2.1.0/tests/test_metadata_manager.py +57 -0
  12. unicefdata-2.1.0/tests/test_pipeline_mocked.py +192 -0
  13. unicefdata-2.1.0/tests/test_unicef_api.py +114 -0
  14. unicefdata-2.1.0/unicefdata/__init__.py +83 -0
  15. unicefdata-2.1.0/unicefdata/config.py +156 -0
  16. unicefdata-2.1.0/unicefdata/config_loader.py +270 -0
  17. unicefdata-2.1.0/unicefdata/flows.py +217 -0
  18. unicefdata-2.1.0/unicefdata/indicator_registry.py +775 -0
  19. unicefdata-2.1.0/unicefdata/metadata/_unicefdata_sync_history.yaml +115 -0
  20. unicefdata-2.1.0/unicefdata/metadata/current/_dataflow_fallback_sequences.yaml +278 -0
  21. unicefdata-2.1.0/unicefdata/metadata/current/_unicefdata_codelists.yaml +641 -0
  22. unicefdata-2.1.0/unicefdata/metadata/current/_unicefdata_countries.yaml +464 -0
  23. unicefdata-2.1.0/unicefdata/metadata/current/_unicefdata_dataflows.yaml +639 -0
  24. unicefdata-2.1.0/unicefdata/metadata/current/_unicefdata_indicators.yaml +7270 -0
  25. unicefdata-2.1.0/unicefdata/metadata/current/_unicefdata_indicators_metadata.yaml +12860 -0
  26. unicefdata-2.1.0/unicefdata/metadata/current/_unicefdata_regions.yaml +123 -0
  27. unicefdata-2.1.0/unicefdata/metadata/current/dataflow_index.yaml +356 -0
  28. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CAUSE_OF_DEATH.yaml +52 -0
  29. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CCRI.yaml +137 -0
  30. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CHILD_RELATED_SDG.yaml +144 -0
  31. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CHLD_PVTY.yaml +77 -0
  32. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME.yaml +142 -0
  33. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_CAUSE_OF_DEATH.yaml +96 -0
  34. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_COUNTRY_PROFILES_DATA.yaml +100 -0
  35. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_DF_2021_WQ.yaml +280 -0
  36. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNATIONAL.yaml +202 -0
  37. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_AGO.yaml +179 -0
  38. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_BDI.yaml +179 -0
  39. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_BEN.yaml +179 -0
  40. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_BGD.yaml +179 -0
  41. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_CMR.yaml +179 -0
  42. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_ETH.yaml +179 -0
  43. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_GHA.yaml +179 -0
  44. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_GIN.yaml +179 -0
  45. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_HTI.yaml +179 -0
  46. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_KEN.yaml +179 -0
  47. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_LAO.yaml +179 -0
  48. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_LBR.yaml +179 -0
  49. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_LSO.yaml +179 -0
  50. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_MDG.yaml +185 -0
  51. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_MLI.yaml +179 -0
  52. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_MMR.yaml +179 -0
  53. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_MRT.yaml +179 -0
  54. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_MWI.yaml +179 -0
  55. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_NAM.yaml +179 -0
  56. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_NGA.yaml +179 -0
  57. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_NPL.yaml +179 -0
  58. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_PAK.yaml +179 -0
  59. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_RWA.yaml +179 -0
  60. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_SEN.yaml +179 -0
  61. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_SLE.yaml +179 -0
  62. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_TCD.yaml +179 -0
  63. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_TGO.yaml +174 -0
  64. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_TZA.yaml +179 -0
  65. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_UGA.yaml +178 -0
  66. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_ZMB.yaml +178 -0
  67. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/CME_SUBNAT_ZWE.yaml +179 -0
  68. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/COVID.yaml +145 -0
  69. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/COVID_CASES.yaml +89 -0
  70. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/DM.yaml +121 -0
  71. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/DM_PROJECTIONS.yaml +118 -0
  72. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/ECD.yaml +272 -0
  73. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/ECONOMIC.yaml +103 -0
  74. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/EDUCATION.yaml +156 -0
  75. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/EDUCATION_FLS.yaml +66 -0
  76. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/EDUCATION_UIS_SDG.yaml +119 -0
  77. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/FUNCTIONAL_DIFF.yaml +250 -0
  78. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/GENDER.yaml +138 -0
  79. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/GLOBAL_DATAFLOW.yaml +550 -0
  80. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/HIV_AIDS.yaml +205 -0
  81. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/IMMUNISATION.yaml +155 -0
  82. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/MG.yaml +147 -0
  83. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/MNCH.yaml +285 -0
  84. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/NUTRITION.yaml +293 -0
  85. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/PT.yaml +320 -0
  86. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/PT_CM.yaml +297 -0
  87. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/PT_CM_SUBNATIONAL.yaml +228 -0
  88. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/PT_CONFLICT.yaml +116 -0
  89. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/PT_FGM.yaml +292 -0
  90. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/SDG_PROG_ASSESSMENT.yaml +124 -0
  91. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/SOC_PROTECTION.yaml +140 -0
  92. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/WASH_HEALTHCARE_FACILITY.yaml +139 -0
  93. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/WASH_HOUSEHOLDS.yaml +146 -0
  94. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/WASH_HOUSEHOLD_MH.yaml +122 -0
  95. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/WASH_HOUSEHOLD_SUBNAT.yaml +219 -0
  96. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/WASH_SCHOOLS.yaml +123 -0
  97. unicefdata-2.1.0/unicefdata/metadata/current/dataflows/WT.yaml +237 -0
  98. unicefdata-2.1.0/unicefdata/metadata/current/unicef_indicators_metadata.yaml +4419 -0
  99. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-03/codelists.yaml +574 -0
  100. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-03/dataflows.yaml +626 -0
  101. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-03/indicators.yaml +230 -0
  102. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-03/summary.yaml +5 -0
  103. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-05/_unicefdata_codelists.yaml +628 -0
  104. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-05/_unicefdata_countries.yaml +462 -0
  105. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-05/_unicefdata_dataflows.yaml +630 -0
  106. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-05/_unicefdata_indicators.yaml +248 -0
  107. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-05/_unicefdata_regions.yaml +121 -0
  108. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-05/summary.yaml +7 -0
  109. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-07/_unicefdata_codelists.yaml +633 -0
  110. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-07/_unicefdata_countries.yaml +464 -0
  111. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-07/_unicefdata_dataflows.yaml +630 -0
  112. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-07/_unicefdata_indicators.yaml +249 -0
  113. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-07/_unicefdata_regions.yaml +123 -0
  114. unicefdata-2.1.0/unicefdata/metadata/vintages/2025-12-07/summary.yaml +7 -0
  115. unicefdata-2.1.0/unicefdata/metadata/vintages/2026-01-21/_unicefdata_codelists.yaml +641 -0
  116. unicefdata-2.1.0/unicefdata/metadata/vintages/2026-01-21/_unicefdata_countries.yaml +464 -0
  117. unicefdata-2.1.0/unicefdata/metadata/vintages/2026-01-21/_unicefdata_dataflows.yaml +639 -0
  118. unicefdata-2.1.0/unicefdata/metadata/vintages/2026-01-21/_unicefdata_indicators.yaml +9674 -0
  119. unicefdata-2.1.0/unicefdata/metadata/vintages/2026-01-21/_unicefdata_regions.yaml +123 -0
  120. unicefdata-2.1.0/unicefdata/metadata/vintages/2026-01-21/summary.yaml +7 -0
  121. unicefdata-2.1.0/unicefdata/metadata/vintages/2026-01-25/_unicefdata_codelists.yaml +641 -0
  122. unicefdata-2.1.0/unicefdata/metadata/vintages/2026-01-25/_unicefdata_countries.yaml +464 -0
  123. unicefdata-2.1.0/unicefdata/metadata/vintages/2026-01-25/_unicefdata_dataflows.yaml +639 -0
  124. unicefdata-2.1.0/unicefdata/metadata/vintages/2026-01-25/_unicefdata_indicators.yaml +9674 -0
  125. unicefdata-2.1.0/unicefdata/metadata/vintages/2026-01-25/_unicefdata_regions.yaml +123 -0
  126. unicefdata-2.1.0/unicefdata/metadata/vintages/2026-01-25/summary.yaml +7 -0
  127. unicefdata-2.1.0/unicefdata/metadata.py +1084 -0
  128. unicefdata-2.1.0/unicefdata/metadata_manager.py +281 -0
  129. unicefdata-2.1.0/unicefdata/run_sync.py +20 -0
  130. unicefdata-2.1.0/unicefdata/schema_cache.py +283 -0
  131. unicefdata-2.1.0/unicefdata/schema_sync.py +561 -0
  132. unicefdata-2.1.0/unicefdata/sdmx.py +166 -0
  133. unicefdata-2.1.0/unicefdata/sdmx_client.py +1388 -0
  134. unicefdata-2.1.0/unicefdata/unicefdata.py +1192 -0
  135. unicefdata-2.1.0/unicefdata/utils.py +616 -0
  136. unicefdata-2.1.0/unicefdata/yaml_formatter.py +333 -0
  137. unicefdata-2.1.0/unicefdata.egg-info/PKG-INFO +358 -0
  138. unicefdata-2.1.0/unicefdata.egg-info/SOURCES.txt +139 -0
  139. unicefdata-2.1.0/unicefdata.egg-info/dependency_links.txt +1 -0
  140. unicefdata-2.1.0/unicefdata.egg-info/requires.txt +15 -0
  141. unicefdata-2.1.0/unicefdata.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Joao Pedro Azevedo, UNICEF
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.
@@ -0,0 +1,358 @@
1
+ Metadata-Version: 2.4
2
+ Name: unicefdata
3
+ Version: 2.1.0
4
+ Summary: Python library for downloading UNICEF indicators via SDMX API
5
+ Author-email: Joao Pedro Azevedo <jpazevedo@unicef.org>
6
+ License: MIT
7
+ Project-URL: Homepage, https://jpazvd.github.io/
8
+ Project-URL: Documentation, https://github.com/unicef-drp/unicefData/tree/main/python
9
+ Project-URL: Repository, https://github.com/unicef-drp/unicefData
10
+ Project-URL: Changelog, https://github.com/unicef-drp/unicefData/blob/main/python/CHANGELOG.md
11
+ Project-URL: Bug Tracker, https://github.com/unicef-drp/unicefData/issues
12
+ Keywords: unicef,sdmx,indicators,data,api,statistics,sdg,development
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Natural Language :: English
17
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Operating System :: OS Independent
24
+ Requires-Python: >=3.9
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: requests>=2.28.0
28
+ Requires-Dist: pandas>=1.5.0
29
+ Requires-Dist: pyyaml>=6.0
30
+ Provides-Extra: excel
31
+ Requires-Dist: openpyxl>=3.0.0; extra == "excel"
32
+ Requires-Dist: xlrd>=2.0.0; extra == "excel"
33
+ Provides-Extra: dev
34
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
35
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
36
+ Requires-Dist: responses>=0.23.0; extra == "dev"
37
+ Requires-Dist: black>=22.0.0; extra == "dev"
38
+ Requires-Dist: flake8>=5.0.0; extra == "dev"
39
+ Requires-Dist: mypy>=0.990; extra == "dev"
40
+ Dynamic: license-file
41
+
42
+ # unicefData - Python Package
43
+
44
+ [![Python Tests](https://github.com/unicef-drp/unicefData/actions/workflows/python-tests.yaml/badge.svg)](https://github.com/unicef-drp/unicefData/actions)
45
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
46
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
47
+
48
+ **Python component of the trilingual unicefData library for downloading UNICEF SDG indicators via SDMX API**
49
+
50
+ This is the Python implementation of the **unicefData** package. For other implementations, see the links below.
51
+
52
+ > **Other languages:** [R](../R/README.md) | [Stata](../stata/README.md) | [Main README](../README.md)
53
+
54
+ ---
55
+
56
+ ## Installation
57
+
58
+ ```bash
59
+ pip install unicefdata
60
+ ```
61
+
62
+ For development:
63
+
64
+ ```bash
65
+ git clone https://github.com/unicef-drp/unicefData.git
66
+ cd unicefData/python
67
+ pip install -e ".[dev]"
68
+ ```
69
+
70
+ ---
71
+
72
+ ## Quick Start
73
+
74
+ ### Search for Indicators
75
+
76
+ ```python
77
+ from unicefdata import search_indicators, list_categories
78
+
79
+ # Search by keyword
80
+ search_indicators("mortality")
81
+ search_indicators("stunting")
82
+
83
+ # List all categories
84
+ list_categories()
85
+
86
+ # Search within a category
87
+ search_indicators(category="CME")
88
+ search_indicators("rate", category="CME")
89
+ ```
90
+
91
+ ### Download Data
92
+
93
+ ```python
94
+ from unicefdata import unicefData
95
+
96
+ # Fetch under-5 mortality (dataflow auto-detected)
97
+ df = unicefData(
98
+ indicator="CME_MRY0T4",
99
+ countries=["ALB", "USA", "BRA"],
100
+ year="2015:2023" # Range, single year, or list
101
+ )
102
+
103
+ print(df.head())
104
+ ```
105
+
106
+ ### View Dataflow Schema
107
+
108
+ ```python
109
+ from unicefdata import dataflow_schema, print_dataflow_schema
110
+
111
+ schema = dataflow_schema("CME")
112
+ print_dataflow_schema(schema)
113
+ ```
114
+
115
+ ---
116
+
117
+ ## Post-Production Options
118
+
119
+ ### Output Formats
120
+
121
+ ```python
122
+ # Long format (default)
123
+ df = unicefData(indicator="CME_MRY0T4", format="long")
124
+
125
+ # Wide format - years as columns
126
+ df = unicefData(indicator="CME_MRY0T4", format="wide")
127
+
128
+ # Wide indicators - indicators as columns
129
+ df = unicefData(
130
+ indicator=["CME_MRY0T4", "NT_ANT_HAZ_NE2_MOD"],
131
+ format="wide_indicators"
132
+ )
133
+ ```
134
+
135
+ ### Latest Value Per Country
136
+
137
+ ```python
138
+ df = unicefData(indicator="CME_MRY0T4", latest=True)
139
+ ```
140
+
141
+ ### Most Recent Values (MRV)
142
+
143
+ ```python
144
+ df = unicefData(indicator="CME_MRY0T4", mrv=3)
145
+ ```
146
+
147
+ ### Circa (Nearest Year)
148
+
149
+ ```python
150
+ df = unicefData(indicator="NT_ANT_HAZ_NE2", year=2015, circa=True)
151
+ ```
152
+
153
+ ### Add Metadata
154
+
155
+ ```python
156
+ df = unicefData(
157
+ indicator="CME_MRY0T4",
158
+ add_metadata=["region", "income_group", "continent"]
159
+ )
160
+ ```
161
+
162
+ ### Combining Options
163
+
164
+ ```python
165
+ df = unicefData(
166
+ indicator=["CME_MRY0T4", "NT_ANT_HAZ_NE2_MOD"],
167
+ format="wide_indicators",
168
+ latest=True,
169
+ add_metadata=["region", "income_group"],
170
+ dropna=True
171
+ )
172
+ ```
173
+
174
+ ---
175
+
176
+ ## API Reference
177
+
178
+ ### unicefData()
179
+
180
+ Main function for fetching UNICEF indicator data.
181
+
182
+ | Parameter | Type | Default | Description |
183
+ |-----------|------|---------|-------------|
184
+ | `indicator` | str/list | required | Indicator code(s) |
185
+ | `dataflow` | str | auto-detect | SDMX dataflow ID |
186
+ | `countries` | list | None (all) | ISO3 country codes |
187
+ | `year` | int/str/list | None (all) | Year(s) |
188
+ | `circa` | bool | False | Find closest year |
189
+ | `sex` | str | `"_T"` | Sex filter |
190
+ | `max_retries` | int | 3 | Retry attempts |
191
+
192
+ #### Post-Production Parameters
193
+
194
+ | Parameter | Type | Default | Description |
195
+ |-----------|------|---------|-------------|
196
+ | `format` | str | `"long"` | `"long"`, `"wide"`, `"wide_indicators"` |
197
+ | `latest` | bool | False | Keep only latest per country |
198
+ | `mrv` | int | None | Keep N most recent values |
199
+ | `add_metadata` | list | None | Metadata to add |
200
+ | `dropna` | bool | False | Remove missing values |
201
+ | `simplify` | bool | False | Keep only essential columns |
202
+
203
+ ### UNICEFSDMXClient (Advanced)
204
+
205
+ ```python
206
+ from unicefdata import UNICEFSDMXClient
207
+
208
+ client = UNICEFSDMXClient()
209
+
210
+ # Fetch single indicator
211
+ df = client.fetch_indicator(
212
+ "CME_MRY0T4",
213
+ countries=["ALB", "USA"],
214
+ start_year=2015,
215
+ end_year=2023
216
+ )
217
+
218
+ # Fetch multiple indicators
219
+ df = client.fetch_multiple_indicators(
220
+ ["CME_MRY0T4", "NT_ANT_HAZ_NE2_MOD"],
221
+ countries=["ALB", "USA"],
222
+ combine=True
223
+ )
224
+ ```
225
+
226
+ ### Other Functions
227
+
228
+ | Function | Description |
229
+ |----------|-------------|
230
+ | `search_indicators(query, category, limit)` | Search indicators |
231
+ | `list_categories()` | List all categories |
232
+ | `list_dataflows()` | List available dataflows |
233
+ | `dataflow_schema(dataflow)` | Get dataflow schema |
234
+ | `clear_cache()` | Clear all 5 cache layers |
235
+
236
+ ---
237
+
238
+ ## Time Period Handling
239
+
240
+ Monthly periods are converted to decimal years:
241
+
242
+ | Original | Decimal | Calculation |
243
+ |----------|---------|-------------|
244
+ | `2020` | `2020.0` | Integer year |
245
+ | `2020-01` | `2020.0833` | 2020 + 1/12 |
246
+ | `2020-06` | `2020.5000` | 2020 + 6/12 |
247
+
248
+ ---
249
+
250
+ ## Common Indicators
251
+
252
+ ### Child Mortality (SDG 3.2)
253
+ - `CME_MRM0` - Neonatal mortality rate
254
+ - `CME_MRY0T4` - Under-5 mortality rate
255
+
256
+ ### Nutrition (SDG 2.2)
257
+ - `NT_ANT_HAZ_NE2_MOD` - Stunting prevalence
258
+ - `NT_ANT_WHZ_NE2` - Wasting prevalence
259
+
260
+ ### Immunization (SDG 3.b)
261
+ - `IM_DTP3` - DTP3 coverage
262
+ - `IM_MCV1` - Measles coverage
263
+
264
+ ### WASH (SDG 6)
265
+ - `WS_PPL_W-SM` - Safely managed water
266
+ - `WS_PPL_S-SM` - Safely managed sanitation
267
+
268
+ ### Child Protection
269
+ - `PT_CHLD_Y0T4_REG` - Birth registration
270
+ - `PT_F_20-24_MRD_U18_TND` - Child marriage
271
+
272
+ ---
273
+
274
+ ## Error Handling
275
+
276
+ ```python
277
+ from unicefdata import SDMXNotFoundError, SDMXBadRequestError, SDMXTimeoutError
278
+
279
+ try:
280
+ df = unicefData(indicator="INVALID_CODE")
281
+ except SDMXNotFoundError as e:
282
+ print(f"Indicator not found: {e}")
283
+ except SDMXBadRequestError as e:
284
+ print(f"Invalid request: {e}")
285
+ except SDMXTimeoutError as e:
286
+ print(f"Request timed out: {e}")
287
+ ```
288
+
289
+ ### Configurable Timeout
290
+
291
+ ```python
292
+ from unicefdata import UNICEFSDMXClient
293
+
294
+ # Set custom timeout (default: 60s)
295
+ client = UNICEFSDMXClient(timeout=120)
296
+ ```
297
+
298
+ ---
299
+
300
+ ## Troubleshooting
301
+
302
+ ### Connection Errors
303
+
304
+ ```python
305
+ # Increase retry attempts
306
+ df = unicefData(indicator="CME_MRY0T4", max_retries=5)
307
+ ```
308
+
309
+ ### Stale Cache
310
+
311
+ ```python
312
+ from unicefdata import clear_cache
313
+ clear_cache() # Clears all 5 cache layers
314
+ ```
315
+
316
+ ---
317
+
318
+ ## Examples
319
+
320
+ See `examples/` folder:
321
+
322
+ - `00_quick_start.py` - Basic usage
323
+ - `01_indicator_discovery.py` - Finding indicators
324
+ - `02_sdg_indicators.py` - SDG queries
325
+ - `03_data_formats.py` - Output formats
326
+ - `04_metadata_options.py` - Metadata enrichment
327
+ - `05_advanced_features.py` - Advanced options
328
+
329
+ ---
330
+
331
+ ## Version History
332
+
333
+ See [CHANGELOG.md](CHANGELOG.md) for complete changelog.
334
+
335
+ ---
336
+
337
+ ## Dependencies
338
+
339
+ - pandas
340
+ - requests
341
+ - pyyaml
342
+
343
+ ---
344
+
345
+ ## License
346
+
347
+ MIT License - See [LICENSE](../LICENSE)
348
+
349
+ ## Author
350
+
351
+ **Joao Pedro Azevedo**
352
+ Chief Statistician, UNICEF Data and Analytics Section
353
+ Email: jpazevedo@unicef.org
354
+ Website: [jpazvd.github.io](https://jpazvd.github.io/)
355
+
356
+ ## Contributing
357
+
358
+ See [CONTRIBUTING.md](../CONTRIBUTING.md) for detailed guidelines.
@@ -0,0 +1,317 @@
1
+ # unicefData - Python Package
2
+
3
+ [![Python Tests](https://github.com/unicef-drp/unicefData/actions/workflows/python-tests.yaml/badge.svg)](https://github.com/unicef-drp/unicefData/actions)
4
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ **Python component of the trilingual unicefData library for downloading UNICEF SDG indicators via SDMX API**
8
+
9
+ This is the Python implementation of the **unicefData** package. For other implementations, see the links below.
10
+
11
+ > **Other languages:** [R](../R/README.md) | [Stata](../stata/README.md) | [Main README](../README.md)
12
+
13
+ ---
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install unicefdata
19
+ ```
20
+
21
+ For development:
22
+
23
+ ```bash
24
+ git clone https://github.com/unicef-drp/unicefData.git
25
+ cd unicefData/python
26
+ pip install -e ".[dev]"
27
+ ```
28
+
29
+ ---
30
+
31
+ ## Quick Start
32
+
33
+ ### Search for Indicators
34
+
35
+ ```python
36
+ from unicefdata import search_indicators, list_categories
37
+
38
+ # Search by keyword
39
+ search_indicators("mortality")
40
+ search_indicators("stunting")
41
+
42
+ # List all categories
43
+ list_categories()
44
+
45
+ # Search within a category
46
+ search_indicators(category="CME")
47
+ search_indicators("rate", category="CME")
48
+ ```
49
+
50
+ ### Download Data
51
+
52
+ ```python
53
+ from unicefdata import unicefData
54
+
55
+ # Fetch under-5 mortality (dataflow auto-detected)
56
+ df = unicefData(
57
+ indicator="CME_MRY0T4",
58
+ countries=["ALB", "USA", "BRA"],
59
+ year="2015:2023" # Range, single year, or list
60
+ )
61
+
62
+ print(df.head())
63
+ ```
64
+
65
+ ### View Dataflow Schema
66
+
67
+ ```python
68
+ from unicefdata import dataflow_schema, print_dataflow_schema
69
+
70
+ schema = dataflow_schema("CME")
71
+ print_dataflow_schema(schema)
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Post-Production Options
77
+
78
+ ### Output Formats
79
+
80
+ ```python
81
+ # Long format (default)
82
+ df = unicefData(indicator="CME_MRY0T4", format="long")
83
+
84
+ # Wide format - years as columns
85
+ df = unicefData(indicator="CME_MRY0T4", format="wide")
86
+
87
+ # Wide indicators - indicators as columns
88
+ df = unicefData(
89
+ indicator=["CME_MRY0T4", "NT_ANT_HAZ_NE2_MOD"],
90
+ format="wide_indicators"
91
+ )
92
+ ```
93
+
94
+ ### Latest Value Per Country
95
+
96
+ ```python
97
+ df = unicefData(indicator="CME_MRY0T4", latest=True)
98
+ ```
99
+
100
+ ### Most Recent Values (MRV)
101
+
102
+ ```python
103
+ df = unicefData(indicator="CME_MRY0T4", mrv=3)
104
+ ```
105
+
106
+ ### Circa (Nearest Year)
107
+
108
+ ```python
109
+ df = unicefData(indicator="NT_ANT_HAZ_NE2", year=2015, circa=True)
110
+ ```
111
+
112
+ ### Add Metadata
113
+
114
+ ```python
115
+ df = unicefData(
116
+ indicator="CME_MRY0T4",
117
+ add_metadata=["region", "income_group", "continent"]
118
+ )
119
+ ```
120
+
121
+ ### Combining Options
122
+
123
+ ```python
124
+ df = unicefData(
125
+ indicator=["CME_MRY0T4", "NT_ANT_HAZ_NE2_MOD"],
126
+ format="wide_indicators",
127
+ latest=True,
128
+ add_metadata=["region", "income_group"],
129
+ dropna=True
130
+ )
131
+ ```
132
+
133
+ ---
134
+
135
+ ## API Reference
136
+
137
+ ### unicefData()
138
+
139
+ Main function for fetching UNICEF indicator data.
140
+
141
+ | Parameter | Type | Default | Description |
142
+ |-----------|------|---------|-------------|
143
+ | `indicator` | str/list | required | Indicator code(s) |
144
+ | `dataflow` | str | auto-detect | SDMX dataflow ID |
145
+ | `countries` | list | None (all) | ISO3 country codes |
146
+ | `year` | int/str/list | None (all) | Year(s) |
147
+ | `circa` | bool | False | Find closest year |
148
+ | `sex` | str | `"_T"` | Sex filter |
149
+ | `max_retries` | int | 3 | Retry attempts |
150
+
151
+ #### Post-Production Parameters
152
+
153
+ | Parameter | Type | Default | Description |
154
+ |-----------|------|---------|-------------|
155
+ | `format` | str | `"long"` | `"long"`, `"wide"`, `"wide_indicators"` |
156
+ | `latest` | bool | False | Keep only latest per country |
157
+ | `mrv` | int | None | Keep N most recent values |
158
+ | `add_metadata` | list | None | Metadata to add |
159
+ | `dropna` | bool | False | Remove missing values |
160
+ | `simplify` | bool | False | Keep only essential columns |
161
+
162
+ ### UNICEFSDMXClient (Advanced)
163
+
164
+ ```python
165
+ from unicefdata import UNICEFSDMXClient
166
+
167
+ client = UNICEFSDMXClient()
168
+
169
+ # Fetch single indicator
170
+ df = client.fetch_indicator(
171
+ "CME_MRY0T4",
172
+ countries=["ALB", "USA"],
173
+ start_year=2015,
174
+ end_year=2023
175
+ )
176
+
177
+ # Fetch multiple indicators
178
+ df = client.fetch_multiple_indicators(
179
+ ["CME_MRY0T4", "NT_ANT_HAZ_NE2_MOD"],
180
+ countries=["ALB", "USA"],
181
+ combine=True
182
+ )
183
+ ```
184
+
185
+ ### Other Functions
186
+
187
+ | Function | Description |
188
+ |----------|-------------|
189
+ | `search_indicators(query, category, limit)` | Search indicators |
190
+ | `list_categories()` | List all categories |
191
+ | `list_dataflows()` | List available dataflows |
192
+ | `dataflow_schema(dataflow)` | Get dataflow schema |
193
+ | `clear_cache()` | Clear all 5 cache layers |
194
+
195
+ ---
196
+
197
+ ## Time Period Handling
198
+
199
+ Monthly periods are converted to decimal years:
200
+
201
+ | Original | Decimal | Calculation |
202
+ |----------|---------|-------------|
203
+ | `2020` | `2020.0` | Integer year |
204
+ | `2020-01` | `2020.0833` | 2020 + 1/12 |
205
+ | `2020-06` | `2020.5000` | 2020 + 6/12 |
206
+
207
+ ---
208
+
209
+ ## Common Indicators
210
+
211
+ ### Child Mortality (SDG 3.2)
212
+ - `CME_MRM0` - Neonatal mortality rate
213
+ - `CME_MRY0T4` - Under-5 mortality rate
214
+
215
+ ### Nutrition (SDG 2.2)
216
+ - `NT_ANT_HAZ_NE2_MOD` - Stunting prevalence
217
+ - `NT_ANT_WHZ_NE2` - Wasting prevalence
218
+
219
+ ### Immunization (SDG 3.b)
220
+ - `IM_DTP3` - DTP3 coverage
221
+ - `IM_MCV1` - Measles coverage
222
+
223
+ ### WASH (SDG 6)
224
+ - `WS_PPL_W-SM` - Safely managed water
225
+ - `WS_PPL_S-SM` - Safely managed sanitation
226
+
227
+ ### Child Protection
228
+ - `PT_CHLD_Y0T4_REG` - Birth registration
229
+ - `PT_F_20-24_MRD_U18_TND` - Child marriage
230
+
231
+ ---
232
+
233
+ ## Error Handling
234
+
235
+ ```python
236
+ from unicefdata import SDMXNotFoundError, SDMXBadRequestError, SDMXTimeoutError
237
+
238
+ try:
239
+ df = unicefData(indicator="INVALID_CODE")
240
+ except SDMXNotFoundError as e:
241
+ print(f"Indicator not found: {e}")
242
+ except SDMXBadRequestError as e:
243
+ print(f"Invalid request: {e}")
244
+ except SDMXTimeoutError as e:
245
+ print(f"Request timed out: {e}")
246
+ ```
247
+
248
+ ### Configurable Timeout
249
+
250
+ ```python
251
+ from unicefdata import UNICEFSDMXClient
252
+
253
+ # Set custom timeout (default: 60s)
254
+ client = UNICEFSDMXClient(timeout=120)
255
+ ```
256
+
257
+ ---
258
+
259
+ ## Troubleshooting
260
+
261
+ ### Connection Errors
262
+
263
+ ```python
264
+ # Increase retry attempts
265
+ df = unicefData(indicator="CME_MRY0T4", max_retries=5)
266
+ ```
267
+
268
+ ### Stale Cache
269
+
270
+ ```python
271
+ from unicefdata import clear_cache
272
+ clear_cache() # Clears all 5 cache layers
273
+ ```
274
+
275
+ ---
276
+
277
+ ## Examples
278
+
279
+ See `examples/` folder:
280
+
281
+ - `00_quick_start.py` - Basic usage
282
+ - `01_indicator_discovery.py` - Finding indicators
283
+ - `02_sdg_indicators.py` - SDG queries
284
+ - `03_data_formats.py` - Output formats
285
+ - `04_metadata_options.py` - Metadata enrichment
286
+ - `05_advanced_features.py` - Advanced options
287
+
288
+ ---
289
+
290
+ ## Version History
291
+
292
+ See [CHANGELOG.md](CHANGELOG.md) for complete changelog.
293
+
294
+ ---
295
+
296
+ ## Dependencies
297
+
298
+ - pandas
299
+ - requests
300
+ - pyyaml
301
+
302
+ ---
303
+
304
+ ## License
305
+
306
+ MIT License - See [LICENSE](../LICENSE)
307
+
308
+ ## Author
309
+
310
+ **Joao Pedro Azevedo**
311
+ Chief Statistician, UNICEF Data and Analytics Section
312
+ Email: jpazevedo@unicef.org
313
+ Website: [jpazvd.github.io](https://jpazvd.github.io/)
314
+
315
+ ## Contributing
316
+
317
+ See [CONTRIBUTING.md](../CONTRIBUTING.md) for detailed guidelines.