For Windows:
As of now, the development environment cannot be setup regularly on Windows.
Instead, the Windows Subsystem for Linux (WSL) could be used. Open command
prompt as administrator, then run wsl --install
and restart your machine.
After, download Ubuntu for WSL from https://ubuntu.com/wsl. You should now be
able to open the Ubuntu terminal and follow the commands for Mac & Linux users.
For Mac & Linux:
- Make sure that Python 3.8 or higher is installed and being used (see
python --version
) - Navigate to the
python
directory iniidda-tools
repository (i.e. navigate toiidda-tools/python
) - Optional: establish a Python virtual environment for this repo -- for example
- (one-time) make a virtual environment with something like this
/usr/local/anaconda3/bin/python -m venv venv
(here I'm pointing explicitly to the python that I want) - If another version of python was installed and you cannot create a virtual environment with that version, you may have to install the corresponding Python venv (
sudo apt-get install python3.X-dev python3.X-venv
where X represents the Python version). - (every-time) then activate the virtual environment with this
source venv/bin/activate
- (one-time) make a virtual environment with something like this
- (whenever package dependencies change) Execute
pip install -r requirements.txt
- (whenever
iidda_api
package changes) Executepip install .
to install theiidda_api
package (and potentially others) - (whenever your GitHub personal access tokens expire) Start a Python process and do the following:
from iidda_api import generate_config
generate_config(token="TOKEN", repository="canmod/iidda-test-assets")
- Generate your personal access token here.
- Note: You may need to enable
repo
in the Scopes when generating the token
- Note: You may need to enable
- To find the location of your config file do the following
from iidda_api import config_path
config_path()
-
You can update the configuration simply by re-generating the configuration file, or you can edit this config file (in
config_path()
) directly instead of re-generating it- Confirm that you included your personal access token in the config file. (Replace "TOKEN" with your access token when running
generate_config
in Python, or edit the config file to haveaccess_token = (The personal access token you generated)
). The config file has the structure below:
[github_info] access_token = TOKEN repository = canmod/iidda-test-assets webhook_secret = [local_info] use_local_csv_files = false local_derived_data =
- Confirm that you included your personal access token in the config file. (Replace "TOKEN" with your access token when running
-
Confirm that you are an admin of
iidda-test-assets
repository (if not, it may lead to the app not returning anything when ran)
Note:
If the uvloop
package is installed on your computer, you may get the error:
ValueError: Can't patch loop of type <class 'uvloop.Loop’>
. Simply uninstall
the uvloop
package to fix this error.
The API can be used in a few ways.
We are working to get https://davidearn.mcmaster.ca/iidda/ back up as a deployed version of the API in this repository. It is not currently up 😢.
- Follow the instructions above to set up a development environment
- From a terminal in the
python
directory, executeuvicorn main:app
- If all goes well, open http://127.0.0.1:8000/docs or http://127.0.0.1:8000/redoc in a browser, which will reveal interactive documentation
The iidda.api package can be used to interact with the API.
Making many requests to the GitHub API can be a performance bottleneck. This occurs for example when a filter requires data from many individual tables to be combined. In such a case, the GitHub API must be called for every table. To enhance API performance, we cache the results that come back from the GitHub API. In the deployed version of the IIDDA API we use a GitHub webhook to automatically clear the cache if there has been an update to the archive. This approach is not available for a local development deployment and so if the archive is updated the cache must be manually cleared using these Python commands.
from iidda_api import get_dataset_list
get_dataset_list(clear_cache=True, subset=[])
Sometimes it is convenient for developers to have the API pull from a local
repository of files as opposed a GitHub release. Working in this mode makes
it easier to make experimental changes to data files. To set up this local
mode for the API one should set the local_derived_data
variable in the
config.ini
file under the [local_info]
section. This variable should give
a path to a directory within which one can recursively find directories
named after the datasets and containing the dataset assets (e.g. the dataset
csv file itself, the json metadata). One also needs to set
use_local_csv_files = true
under the [local_info]
section, and can use
this variable to turn local pulling on and off.