hdx-python-api 6.7.0__tar.gz → 6.7.2__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 (149) hide show
  1. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/PKG-INFO +3 -3
  2. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/documentation/index.md +100 -5
  3. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/pyproject.toml +2 -2
  4. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/api/_version.py +2 -2
  5. hdx_python_api-6.7.2/src/hdx/data/activity.py +245 -0
  6. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/data/dataset.py +27 -0
  7. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/data/location.py +23 -0
  8. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/data/organization.py +23 -0
  9. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/data/resource.py +180 -1
  10. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/data/user.py +25 -0
  11. hdx_python_api-6.7.2/tests/hdx/data/test_activity.py +196 -0
  12. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_resource.py +164 -0
  13. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/uv.lock +220 -8
  14. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/.github/workflows/publish.yaml +0 -0
  15. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/.github/workflows/run-python-tests.yaml +0 -0
  16. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/.gitignore +0 -0
  17. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/.pre-commit-config.yaml +0 -0
  18. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/CLAUDE.md +0 -0
  19. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/LICENSE +0 -0
  20. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/README.md +0 -0
  21. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/documentation/.readthedocs.yaml +0 -0
  22. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/documentation/mkdocs.yaml +0 -0
  23. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/api/__init__.py +0 -0
  24. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/api/configuration.py +0 -0
  25. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/api/hdx_base_configuration.yaml +0 -0
  26. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/api/locations.py +0 -0
  27. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/api/remotehdx.py +0 -0
  28. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/api/utilities/__init__.py +0 -0
  29. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/api/utilities/date_helper.py +0 -0
  30. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/api/utilities/filestore_helper.py +0 -0
  31. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/api/utilities/hdx_error_handler.py +0 -0
  32. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/api/utilities/hdx_state.py +0 -0
  33. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/api/utilities/url_utils.py +0 -0
  34. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/data/__init__.py +0 -0
  35. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/data/hdxobject.py +0 -0
  36. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/data/resource_matcher.py +0 -0
  37. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/data/resource_view.py +0 -0
  38. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/data/showcase.py +0 -0
  39. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/data/vocabulary.py +0 -0
  40. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/facades/__init__.py +0 -0
  41. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/facades/infer_arguments.py +0 -0
  42. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/facades/keyword_arguments.py +0 -0
  43. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/src/hdx/facades/simple.py +0 -0
  44. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/__init__.py +0 -0
  45. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/Accepted_Tags.csv +0 -0
  46. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/CKAN/hdx_dataset_static.yaml +0 -0
  47. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/Tag_Mapping.csv +0 -0
  48. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/Tag_Mapping_ChainRuleError.csv +0 -0
  49. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/empty.yaml +0 -0
  50. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_base_config.json +0 -0
  51. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_base_config.yaml +0 -0
  52. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_config.json +0 -0
  53. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_config.yaml +0 -0
  54. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_dataset_static.json +0 -0
  55. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_dataset_static.yaml +0 -0
  56. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_datasource_topline.json +0 -0
  57. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_datasource_topline.yaml +0 -0
  58. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_email_configuration.json +0 -0
  59. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_email_configuration.yaml +0 -0
  60. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_missing_site_config.json +0 -0
  61. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_organization_static.json +0 -0
  62. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_organization_static.yaml +0 -0
  63. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_resource_static.json +0 -0
  64. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_resource_static.yaml +0 -0
  65. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_resource_view_static.json +0 -0
  66. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_resource_view_static.yaml +0 -0
  67. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_showcase_static.json +0 -0
  68. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_showcase_static.yaml +0 -0
  69. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_user_static.json +0 -0
  70. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_user_static.yaml +0 -0
  71. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_vocabulary_static.json +0 -0
  72. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/hdx_vocabulary_static.yaml +0 -0
  73. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/project_configuration.json +0 -0
  74. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/project_configuration.yaml +0 -0
  75. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/user_agent_config.yaml +0 -0
  76. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/user_agent_config2.yaml +0 -0
  77. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/user_agent_config3.yaml +0 -0
  78. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/config/user_agent_config_wrong.yaml +0 -0
  79. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/dataset_search_results.yaml +0 -0
  80. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/download_gen_resource/conflict_data_alg.csv +0 -0
  81. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/download_gen_resource/min_qc_conflict_data_alg.csv +0 -0
  82. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/download_gen_resource/qc_conflict_data_alg.csv +0 -0
  83. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/download_gen_resource/test_data_no_data.csv +0 -0
  84. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/download_gen_resource/test_data_no_years.csv +0 -0
  85. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/empty.csv +0 -0
  86. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/gen_resource/conflict_data_alg.csv +0 -0
  87. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/gen_resource/min_qc_conflict_data_alg.csv +0 -0
  88. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/gen_resource/qc_conflict_data_alg.csv +0 -0
  89. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/gen_resource/test_data_no_data.csv +0 -0
  90. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/gen_resource/test_data_no_years.csv +0 -0
  91. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/location/location_list_all_fields.yaml +0 -0
  92. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/location/location_show_results.yaml +0 -0
  93. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/organization/organization_list_all_fields.yaml +0 -0
  94. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/organization/organization_show_results.yaml +0 -0
  95. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/qc_from_rows/qc_conflict_data_alg.csv +0 -0
  96. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/qc_from_rows/qc_conflict_data_alg_one_col.csv +0 -0
  97. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/resource_formats.json +0 -0
  98. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/showcase_all_search_results.yaml +0 -0
  99. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/size_hash/ACLED-All-Africa-File_20170101-to-20170708.xlsx +0 -0
  100. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/state/analysis_dates.txt +0 -0
  101. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/state/last_build_date.txt +0 -0
  102. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/test_data.csv +0 -0
  103. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/test_data.zip +0 -0
  104. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_dataset_resources/dem_data_zwe.csv +0 -0
  105. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_dataset_resources/dem_indicatorlist_zwe.csv +0 -0
  106. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_dataset_resources/expected_resources_to_update.json +0 -0
  107. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_dataset_resources/opri_data_zwe.csv +0 -0
  108. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_dataset_resources/opri_indicatorlist_zwe.csv +0 -0
  109. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_dataset_resources/opri_metadata_zwe.csv +0 -0
  110. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_dataset_resources/qc_sdg_data_zwe.csv +0 -0
  111. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_dataset_resources/sdg_data_zwe.csv +0 -0
  112. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_dataset_resources/sdg_indicatorlist_zwe.csv +0 -0
  113. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_dataset_resources/sdg_metadata_zwe.csv +0 -0
  114. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_dataset_resources/unesco_dataset.json +0 -0
  115. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_dataset_resources/unesco_update_dataset.json +0 -0
  116. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_logic/update_logic_resources.yaml +0 -0
  117. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/fixtures/update_logic/update_logic_resources_new.yaml +0 -0
  118. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/__init__.py +0 -0
  119. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/api/__init__.py +0 -0
  120. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/api/test_ckan.py +0 -0
  121. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/api/test_configuration.py +0 -0
  122. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/api/test_locations.py +0 -0
  123. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/api/utilities/__init__.py +0 -0
  124. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/api/utilities/test_filestore_helper.py +0 -0
  125. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/api/utilities/test_hdx_error_handler.py +0 -0
  126. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/api/utilities/test_hdx_state.py +0 -0
  127. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/api/utilities/test_url_utils.py +0 -0
  128. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/conftest.py +0 -0
  129. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/__init__.py +0 -0
  130. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_dataset_add_hapi_error.py +0 -0
  131. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_dataset_core.py +0 -0
  132. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_dataset_noncore.py +0 -0
  133. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_dataset_resource_generation.py +0 -0
  134. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_location.py +0 -0
  135. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_organization.py +0 -0
  136. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_resource_view.py +0 -0
  137. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_showcase.py +0 -0
  138. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_update_dataset_resources.py +0 -0
  139. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_update_logic.py +0 -0
  140. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_user.py +0 -0
  141. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/data/test_vocabulary.py +0 -0
  142. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/facades/__init__.py +0 -0
  143. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/facades/test_infer_arguments.py +0 -0
  144. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/facades/test_keyword_arguments.py +0 -0
  145. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/tests/hdx/facades/test_simple.py +0 -0
  146. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/workingexample/my_code.py +0 -0
  147. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/workingexample/my_resource.csv +0 -0
  148. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/workingexample/my_resource.xlsx +0 -0
  149. {hdx_python_api-6.7.0 → hdx_python_api-6.7.2}/workingexample/run.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: hdx-python-api
3
- Version: 6.7.0
3
+ Version: 6.7.2
4
4
  Summary: HDX Python API for interacting with the Humanitarian Data Exchange
5
5
  Project-URL: Homepage, https://github.com/OCHA-DAP/hdx-python-api
6
6
  Author: Michael Rans
@@ -28,8 +28,8 @@ Requires-Python: >=3.10
28
28
  Requires-Dist: ckanapi>=4.11
29
29
  Requires-Dist: defopt>=7.0.0
30
30
  Requires-Dist: email-validator
31
- Requires-Dist: hdx-python-country>=4.1.3
32
- Requires-Dist: hdx-python-utilities>=4.1.2
31
+ Requires-Dist: hdx-python-country>=4.2.3
32
+ Requires-Dist: hdx-python-utilities>=4.2.1
33
33
  Requires-Dist: makefun
34
34
  Requires-Dist: requests
35
35
  Provides-Extra: docs
@@ -35,6 +35,7 @@ upload your datasets to HDX.
35
35
  - [Organization Management](#organization-management)
36
36
  - [Location Management](#location-management)
37
37
  - [Vocabulary Management](#vocabulary-management)
38
+ - [Activity Streams](#activity-streams)
38
39
  - [Pipeline State](#pipeline-state)
39
40
  - [Working Examples](#working-examples)
40
41
  - [Project Framework](#project-framework)
@@ -832,9 +833,13 @@ dictionary. HEADERS is either a row number (rows start counting at 1), or the
832
833
  actual headers defined as a list of strings. If not set, all rows will be
833
834
  treated as containing values:
834
835
 
835
- dataset.generate_resource("FOLDER", "FILENAME", ROWS, RESOURCE DATA, HEADERS,
836
- COLUMNS, "FORMAT", "ENCODING", DATECOL or YEARCOL or
837
- DATE_FUNCTION)
836
+ dataset.generate_resource("FOLDER", "FILENAME", ROWS, RESOURCE_DATA,
837
+ headers=HEADERS, columns=COLUMNS, format="FORMAT",
838
+ encoding="ENCODING", datecol=DATECOL)
839
+
840
+ To use years or a custom date function instead, replace `datecol=DATECOL` with
841
+ `yearcol=YEARCOL` or `date_function=DATE_FUNCTION`. Supply only one of these
842
+ three arguments, using its keyword.
838
843
 
839
844
  The first 4 parameters are mandatory, the rest are optional. A resource can be generated
840
845
  from a given list or tuple or other iterable. The method returns a tuple with a bool
@@ -868,8 +873,12 @@ and outputs a modified row.
868
873
  The rest of the arguments are the same as for `generate_resource`.
869
874
 
870
875
  dataset.download_generate_resource(DOWNLOADER, "URL", "FOLDER", "FILENAME",
871
- RESOURCE_DATA, HEADER_INSERTIONS, ROW_FUNCTION,
872
- DATECOL or YEARCOL or DATE_FUNCTION, **KWARGS)
876
+ RESOURCE_DATA, header_insertions=HEADER_INSERTIONS,
877
+ row_function=ROW_FUNCTION, datecol=DATECOL,
878
+ **KWARGS)
879
+
880
+ As with `generate_resource`, use `yearcol=YEARCOL` or
881
+ `date_function=DATE_FUNCTION` instead of `datecol=DATECOL` when appropriate.
873
882
 
874
883
  ## Resource Specific Operations
875
884
 
@@ -965,6 +974,58 @@ using the getter:
965
974
 
966
975
  data_dictionary = resource.get_hdx_data_dictionary()
967
976
 
977
+ ### Datastore
978
+
979
+ A resource's data can be loaded into the HDX datastore and queried. HDX
980
+ requires an API key for all datastore actions and dumps, including reads of
981
+ public resources. To create, update or delete the datastore for a resource:
982
+
983
+ resource.create_datastore(
984
+ [{"id": "code", "type": "text"}, {"id": "value", "type": "numeric"}],
985
+ primary_key="code",
986
+ )
987
+ resource.update_datastore([{"code": "A", "value": 1.0}]) # upsert by default
988
+ has_datastore = resource.has_datastore()
989
+ resource.delete_datastore()
990
+
991
+ To download the whole datastore (rather than the resource's file) use
992
+ **download_datastore**, which returns the URL and path like **download**.
993
+ `file_format` can be `csv` (default), `tsv`, `json` or `xml`, and `filename`
994
+ defaults to the resource name with that extension. **get_datastore_dump_url**
995
+ returns the URL without downloading:
996
+
997
+ url, path = resource.download_datastore("FOLDER_TO_DOWNLOAD_TO")
998
+ url = resource.get_datastore_dump_url(file_format="json")
999
+
1000
+ **search_datastore** wraps CKAN's `datastore_search`, returning the result
1001
+ dictionary (with keys including `records`, `fields` and `total`). It accepts
1002
+ `filters`, `q`, `fields`, `sort`, `distinct`, `limit` (default 100), `offset`
1003
+ and `include_total`, and passes any other keyword arguments to CKAN:
1004
+
1005
+ result = resource.search_datastore(
1006
+ filters={"code": ["A", "B"]}, fields=["code", "value"], sort="value desc"
1007
+ )
1008
+ records = result["records"]
1009
+
1010
+ **get_datastore_records** takes the same query parameters but pages through
1011
+ all matching rows, yielding each record (`page_size` defaults to 10000):
1012
+
1013
+ for record in resource.get_datastore_records(filters={"code": "A"}):
1014
+ ...
1015
+
1016
+ **get_datastore_fields** returns the datastore field definitions excluding the
1017
+ internal `_id` field:
1018
+
1019
+ fields = resource.get_datastore_fields()
1020
+
1021
+ **search_datastore_sql** wraps CKAN's `datastore_search_sql`, running a
1022
+ SELECT statement where tables are named by double quoted resource id and
1023
+ returning the list of records:
1024
+
1025
+ records = Resource.search_datastore_sql(
1026
+ 'SELECT code, SUM(value) AS total FROM "RESOURCE_ID" GROUP BY code'
1027
+ )
1028
+
968
1029
  ## Showcase Management
969
1030
 
970
1031
  The **Showcase** class enables you to manage showcases, creating, deleting and updating
@@ -1128,6 +1189,40 @@ If you want to add a list of tags, you do it as follows:
1128
1189
 
1129
1190
  vocabulary.add_tags(["TAG","TAG","TAG"...])
1130
1191
 
1192
+ ## Activity Streams
1193
+
1194
+ The **Activity** class wraps CKAN activities, which record who changed what and when.
1195
+ Activities are read only. You can get the activity stream of a dataset, organization,
1196
+ location or user:
1197
+
1198
+ activities = dataset.get_activities(**kwargs)
1199
+ activities = organization.get_activities(**kwargs)
1200
+ activities = location.get_activities(**kwargs)
1201
+ activities = user.get_activities(**kwargs)
1202
+
1203
+ These return a list of **Activity** objects, each with fields like `timestamp`,
1204
+ `user_id`, `object_id` and `activity_type` (eg. "changed package"). One page of results
1205
+ is returned. Its size is set by `limit` (default 31, HDX maximum 100) and where it starts
1206
+ by `offset`. Passing `all_pages=True` gets every page. Other arguments (`**kwargs`) like
1207
+ `after`, `before` and `activity_types` depend on the object type and are detailed in the
1208
+ API documentation. Getting a user's activity stream requires authorisation to view the
1209
+ user's profile.
1210
+
1211
+ You can get the activity stream of all recently added or changed datasets:
1212
+
1213
+ activities = Activity.get_recently_changed_packages(limit=10)
1214
+
1215
+ With `all_pages=True`, this stream covers the whole history of HDX so it is capped by
1216
+ `max_activities` (default 1000). Pass `max_activities=None` to remove the cap.
1217
+
1218
+ You can read a single activity, get its data (including a snapshot of the object at the
1219
+ time of the activity) or get a diff against the object's previous version. HDX requires
1220
+ permission to edit the object the activity relates to for these:
1221
+
1222
+ activity = Activity.read_from_hdx("ACTIVITY_ID")
1223
+ data = activity.get_data()
1224
+ diff = activity.get_diff(diff_type="unified") # or "context" or "html"
1225
+
1131
1226
  ## Pipeline State
1132
1227
 
1133
1228
  The HDXState class allows the reading and writing of state to a given dataset. Input
@@ -39,8 +39,8 @@ dependencies = [
39
39
  "ckanapi>=4.11",
40
40
  "defopt>=7.0.0",
41
41
  "email_validator",
42
- "hdx-python-country>=4.1.3",
43
- "hdx-python-utilities>=4.1.2",
42
+ "hdx-python-country>=4.2.3",
43
+ "hdx-python-utilities>=4.2.1",
44
44
  "makefun",
45
45
  "requests",
46
46
  ]
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '6.7.0'
22
- __version_tuple__ = version_tuple = (6, 7, 0)
21
+ __version__ = version = '6.7.2'
22
+ __version_tuple__ = version_tuple = (6, 7, 2)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -0,0 +1,245 @@
1
+ """Activity class containing all logic for reading activity streams."""
2
+
3
+ import logging
4
+ from collections.abc import Sequence
5
+ from typing import Any, Optional
6
+
7
+ from hdx.api.configuration import Configuration
8
+ from hdx.data.hdxobject import HDXError, HDXObject
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+
13
+ class Activity(HDXObject):
14
+ """Activity class containing all logic for reading activity streams. Activities
15
+ are read only.
16
+
17
+ Args:
18
+ initial_data: Initial activity metadata dictionary. Defaults to None.
19
+ configuration: HDX configuration. Defaults to global configuration.
20
+ """
21
+
22
+ def __init__(
23
+ self,
24
+ initial_data: dict | None = None,
25
+ configuration: Configuration | None = None,
26
+ ) -> None:
27
+ if not initial_data:
28
+ initial_data = {}
29
+ super().__init__(initial_data, configuration=configuration)
30
+
31
+ @staticmethod
32
+ def actions() -> dict[str, str]:
33
+ """Dictionary of actions that can be performed on object
34
+
35
+ Returns:
36
+ Dictionary of actions that can be performed on object
37
+ """
38
+ return {
39
+ "show": "activity_show",
40
+ "data_show": "activity_data_show",
41
+ "diff": "activity_diff",
42
+ "package_list": "package_activity_list",
43
+ "organization_list": "organization_activity_list",
44
+ "group_list": "group_activity_list",
45
+ "user_list": "user_activity_list",
46
+ "recently_changed_packages": "recently_changed_packages_activity_list",
47
+ }
48
+
49
+ @classmethod
50
+ def read_from_hdx(
51
+ cls, identifier: str, configuration: Configuration | None = None
52
+ ) -> Optional["Activity"]:
53
+ """Reads the activity given by identifier from HDX and returns Activity object.
54
+ HDX requires permission to edit the object the activity relates to.
55
+
56
+ Args:
57
+ identifier: Identifier of activity
58
+ configuration: HDX configuration. Defaults to global configuration.
59
+
60
+ Returns:
61
+ Activity object if successful read, None if not
62
+ """
63
+ return cls._read_from_hdx_class("activity", identifier, configuration)
64
+
65
+ def get_object_type(self) -> str:
66
+ """Get the CKAN object type the activity relates to eg. package,
67
+ organization, group or user. This is the last word of the activity type
68
+ (eg. "changed package") with "dataset" (from "follow dataset") mapped to
69
+ "package".
70
+
71
+ Returns:
72
+ Object type
73
+ """
74
+ object_type = self.data["activity_type"].split(" ")[-1]
75
+ if object_type == "dataset":
76
+ return "package"
77
+ return object_type
78
+
79
+ def get_data(self) -> dict:
80
+ """Get the data of the activity which includes a snapshot of the object
81
+ at the time of the activity. HDX requires permission to edit the object
82
+ the activity relates to.
83
+
84
+ Returns:
85
+ Activity data
86
+ """
87
+ return self._write_to_hdx("data_show", {"id": self.data["id"]}, "id")
88
+
89
+ def get_diff(self, diff_type: str = "unified") -> dict:
90
+ """Get a diff of the object compared to its previous version. HDX requires
91
+ permission to edit the object the activity relates to.
92
+
93
+ Args:
94
+ diff_type: One of unified, context or html. Defaults to unified.
95
+
96
+ Returns:
97
+ Activity diff
98
+ """
99
+ data = {
100
+ "id": self.data["id"],
101
+ "object_type": self.get_object_type(),
102
+ "diff_type": diff_type,
103
+ }
104
+ return self._write_to_hdx("diff", data, "id")
105
+
106
+ @classmethod
107
+ def _get_list(
108
+ cls,
109
+ action: str,
110
+ data: dict,
111
+ configuration: Configuration | None = None,
112
+ all_pages: bool = False,
113
+ max_activities: int | None = None,
114
+ ) -> list["Activity"]:
115
+ """Helper method to get a list of activities from HDX
116
+
117
+ Args:
118
+ action: Action to perform
119
+ data: Data to pass to CKAN including any offset and limit
120
+ configuration: HDX configuration. Defaults to global configuration.
121
+ all_pages: Whether to get all pages of results. Defaults to False.
122
+ max_activities: Maximum number of activities if all_pages is True. Defaults to None (no maximum).
123
+
124
+ Returns:
125
+ List of Activity objects
126
+ """
127
+ activity = cls(configuration=configuration)
128
+ if not all_pages:
129
+ result = activity._write_to_hdx(action, data)
130
+ return [cls(x, configuration=configuration) for x in result]
131
+ data = dict(data)
132
+ limit = data.setdefault("limit", 100)
133
+ offset = data.get("offset", 0)
134
+ activities = []
135
+ while True:
136
+ data["offset"] = offset
137
+ result = activity._write_to_hdx(action, data)
138
+ activities.extend(cls(x, configuration=configuration) for x in result)
139
+ if max_activities is not None and len(activities) >= max_activities:
140
+ return activities[:max_activities]
141
+ if len(result) < limit:
142
+ return activities
143
+ offset += limit
144
+
145
+ @classmethod
146
+ def get_activities(
147
+ cls,
148
+ object_type: str,
149
+ identifier: str,
150
+ configuration: Configuration | None = None,
151
+ all_pages: bool = False,
152
+ **kwargs: Any,
153
+ ) -> list["Activity"]:
154
+ """Get the activity stream of a CKAN object. One page of results (whose
155
+ size is given by limit) is returned unless all_pages is True.
156
+
157
+ Args:
158
+ object_type: One of package, organization, group or user
159
+ identifier: Id or name of object
160
+ configuration: HDX configuration. Defaults to global configuration.
161
+ all_pages: Whether to get all pages of results. Defaults to False.
162
+ **kwargs: See below
163
+ offset (int): Where to start getting activity items from. Defaults to 0.
164
+ limit (int): Maximum number of activities per page. Defaults to 31 (HDX maximum 100) or 100 if all_pages is True.
165
+ after (int | str): Only activities after this timestamp (package and user only)
166
+ before (int | str): Only activities before this timestamp (package and user only)
167
+ include_hidden_activity (bool): Include hidden activity, sysadmins only (package, organization and group only)
168
+ activity_types (list): Activity types to include (package only)
169
+ exclude_activity_types (list): Activity types to exclude (package only)
170
+
171
+ Returns:
172
+ List of Activity objects
173
+ """
174
+ if not identifier:
175
+ raise HDXError(f"No id or name for {object_type} to get activities!")
176
+ data = {"id": identifier}
177
+ data.update(kwargs)
178
+ return cls._get_list(f"{object_type}_list", data, configuration, all_pages)
179
+
180
+ @classmethod
181
+ def get_recently_changed_packages(
182
+ cls,
183
+ configuration: Configuration | None = None,
184
+ all_pages: bool = False,
185
+ max_activities: int | None = 1000,
186
+ **kwargs: Any,
187
+ ) -> list["Activity"]:
188
+ """Get the activity stream of all recently added or changed datasets.
189
+ One page of results (whose size is given by limit) is returned unless
190
+ all_pages is True. all_pages is capped by max_activities because the
191
+ stream covers the whole history of HDX.
192
+
193
+ Args:
194
+ configuration: HDX configuration. Defaults to global configuration.
195
+ all_pages: Whether to get all pages of results. Defaults to False.
196
+ max_activities: Maximum number of activities if all_pages is True. Defaults to 1000. None means no maximum (very slow).
197
+ **kwargs: See below
198
+ offset (int): Where to start getting activity items from. Defaults to 0.
199
+ limit (int): Maximum number of activities per page. Defaults to 31 (HDX maximum 100) or 100 if all_pages is True.
200
+
201
+ Returns:
202
+ List of Activity objects
203
+ """
204
+ return cls._get_list(
205
+ "recently_changed_packages",
206
+ kwargs,
207
+ configuration,
208
+ all_pages,
209
+ max_activities,
210
+ )
211
+
212
+ def check_required_fields(self, ignore_fields: Sequence[str] = ()) -> None:
213
+ """Activities are read only so this raises an exception
214
+
215
+ Args:
216
+ ignore_fields: Fields to ignore. Default is ().
217
+
218
+ Returns:
219
+ None
220
+ """
221
+ raise HDXError("Activities are read only!")
222
+
223
+ def update_in_hdx(self, **kwargs: Any) -> None:
224
+ """Activities are read only so this raises an exception
225
+
226
+ Returns:
227
+ None
228
+ """
229
+ raise HDXError("Activities are read only!")
230
+
231
+ def create_in_hdx(self, **kwargs: Any) -> None:
232
+ """Activities are read only so this raises an exception
233
+
234
+ Returns:
235
+ None
236
+ """
237
+ raise HDXError("Activities are read only!")
238
+
239
+ def delete_from_hdx(self) -> None:
240
+ """Activities are read only so this raises an exception
241
+
242
+ Returns:
243
+ None
244
+ """
245
+ raise HDXError("Activities are read only!")
@@ -40,6 +40,7 @@ from hdx.api.configuration import Configuration
40
40
  from hdx.api.locations import Locations
41
41
  from hdx.api.utilities.date_helper import DateHelper
42
42
  from hdx.api.utilities.filestore_helper import FilestoreHelper
43
+ from hdx.data.activity import Activity
43
44
  from hdx.data.hdxobject import HDXError, HDXObject
44
45
  from hdx.data.resource_matcher import ResourceMatcher
45
46
 
@@ -1428,6 +1429,32 @@ class Dataset(HDXObject):
1428
1429
  resources.append(resource)
1429
1430
  return resources
1430
1431
 
1432
+ def get_activities(self, all_pages: bool = False, **kwargs: Any) -> list[Activity]:
1433
+ """Get the activity stream of this dataset. One page of results (whose size
1434
+ is given by limit) is returned unless all_pages is True.
1435
+
1436
+ Args:
1437
+ all_pages: Whether to get all pages of results. Defaults to False.
1438
+ **kwargs: See below
1439
+ offset (int): Where to start getting activity items from. Defaults to 0.
1440
+ limit (int): Maximum number of activities per page. Defaults to 31 (HDX maximum 100) or 100 if all_pages is True.
1441
+ after (int | str): Only activities after this timestamp
1442
+ before (int | str): Only activities before this timestamp
1443
+ include_hidden_activity (bool): Include hidden activity (sysadmins only)
1444
+ activity_types (list): Activity types to include
1445
+ exclude_activity_types (list): Activity types to exclude
1446
+
1447
+ Returns:
1448
+ List of Activity objects
1449
+ """
1450
+ return Activity.get_activities(
1451
+ "package",
1452
+ self.data.get("id") or self.data.get("name"),
1453
+ self.configuration,
1454
+ all_pages,
1455
+ **kwargs,
1456
+ )
1457
+
1431
1458
  @classmethod
1432
1459
  def autocomplete(
1433
1460
  cls,
@@ -5,6 +5,7 @@ from collections.abc import Sequence
5
5
  from typing import Any, Optional
6
6
 
7
7
  from hdx.api.configuration import Configuration
8
+ from hdx.data.activity import Activity
8
9
  from hdx.data.hdxobject import HDXObject
9
10
 
10
11
  logger = logging.getLogger(__name__)
@@ -217,6 +218,28 @@ class Location(HDXObject):
217
218
  if len(group["name"]) == 3 and group.get("data_completeness") == "active"
218
219
  )
219
220
 
221
+ def get_activities(self, all_pages: bool = False, **kwargs: Any) -> list[Activity]:
222
+ """Get the activity stream of this location. One page of results (whose size
223
+ is given by limit) is returned unless all_pages is True.
224
+
225
+ Args:
226
+ all_pages: Whether to get all pages of results. Defaults to False.
227
+ **kwargs: See below
228
+ offset (int): Where to start getting activity items from. Defaults to 0.
229
+ limit (int): Maximum number of activities per page. Defaults to 31 (HDX maximum 100) or 100 if all_pages is True.
230
+ include_hidden_activity (bool): Include hidden activity (sysadmins only)
231
+
232
+ Returns:
233
+ List of Activity objects
234
+ """
235
+ return Activity.get_activities(
236
+ "group",
237
+ self.data.get("id") or self.data.get("name"),
238
+ self.configuration,
239
+ all_pages,
240
+ **kwargs,
241
+ )
242
+
220
243
  @classmethod
221
244
  def autocomplete(
222
245
  cls,
@@ -8,6 +8,7 @@ from typing import TYPE_CHECKING, Any, Optional, Union
8
8
  import hdx.data.dataset
9
9
  import hdx.data.user as user_module
10
10
  from hdx.api.configuration import Configuration
11
+ from hdx.data.activity import Activity
11
12
  from hdx.data.hdxobject import HDXError, HDXObject
12
13
 
13
14
  if TYPE_CHECKING:
@@ -311,6 +312,28 @@ class Organization(HDXObject):
311
312
 
312
313
  return final_orgs
313
314
 
315
+ def get_activities(self, all_pages: bool = False, **kwargs: Any) -> list[Activity]:
316
+ """Get the activity stream of this organization. One page of results (whose size
317
+ is given by limit) is returned unless all_pages is True.
318
+
319
+ Args:
320
+ all_pages: Whether to get all pages of results. Defaults to False.
321
+ **kwargs: See below
322
+ offset (int): Where to start getting activity items from. Defaults to 0.
323
+ limit (int): Maximum number of activities per page. Defaults to 31 (HDX maximum 100) or 100 if all_pages is True.
324
+ include_hidden_activity (bool): Include hidden activity (sysadmins only)
325
+
326
+ Returns:
327
+ List of Activity objects
328
+ """
329
+ return Activity.get_activities(
330
+ "organization",
331
+ self.data.get("id") or self.data.get("name"),
332
+ self.configuration,
333
+ all_pages,
334
+ **kwargs,
335
+ )
336
+
314
337
  @classmethod
315
338
  def autocomplete(
316
339
  cls,