Introduction
The HDX Python Library is designed to simplify using the HDX JSON API which is built on top of CKAN. The underlying GET and POST requests are wrapped in Python methods and the . The HDX objects like , such as datasets and resources, are represented by Python classes. The UML diagram below shows the relationships between the major classes in the library.
Drawio | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Keeping it Simple
The major goal of the library is to make interacting with HDX as simple as possible for the user. There are several ways this is achieved.
- The library avoids CKAN syntax instead using
...
- HDX terminology.
...
- The user does not need to learn about CKAN and makes it easier to understand what will be
...
- the result in HDX when calling a Python method
...
- .
- The class structure of the library should be as logical as possible (within the restrictions of the CKAN API it relies on). In HDX, a datasets can contain zero or more resources and a gallery (consisting of gallery items), so the library reflects this even though the CKAN API presents a different interface for gallery items to resources.
- Datasets, resources and gallery items can use dictionary methods like square brackets (eg. dataset['name'] = 'My Dataset') to handle metadata which feels natural. (The HDXObject class extends UserDict.).
- Static metadata can be imported from a YAML file, recommended for being very human readable, or a JSON file. Static metadata can be passed in as a dictionary on initialisation of a dataset, resource or gallery item.
- The code is very well documented. Detailed API documentation (generated from Google style docstrings using Sphinx) can be found here: http://mcarans.github.io/hdx-python-api/
- The method arguments and return parameter have type hints. (Although this is a feature of Python 3.5, it has been backported.) Type hints enable sophisticated IDEs like PyCharm to warn of any inconsistencies in using types bringing one of the major benefits of statically typed languages to Python.
- Default parameters mean that there is a very easy default way to do things.
- Configuration is made as simple as possible by way of