Fetch your projects with Valohai APIs¶
Using the Valohai APIs is rather straightforward, you’ll need to create an API token to authenticate your requests and then write your code to send & receive requests.
- Go to your profile setting and create an authentication token
- In our sample we’ll paste this directly to the file but you should consider saving this token in a configuration file or database for secure storage.
- Consider creating a custom virtual environment for Python before continuing.
python3 -m virtualenv .venv
source .venv/bin/activate
- Create a new file called
fetchVHProjects.py
import requests import json # Authenticate yourself with the token auth_token = '<your-auth-token>' headers = {'Authorization': 'Token %s' % auth_token} # Send a request (with the authentication headers) to fetch Valohai projects resp = requests.get('https://app.valohai.com/api/v0/projects/', headers=headers) resp.raise_for_status() # Print the response you've received back print('# API Response:\n') print(json.dumps(resp.json(), indent=4))
- Create a new file called
🔥 Save the code and run
python fetchVHProjects.py
to get your results (ID, name, execution count, owner, queued executions etc.)