API Can be installed through docker or manually to local machine . To get started with docker follow GETTING_STARTED_WITH_DOCKER
- Install gdal on your machine , for example on Ubuntu
sudo apt-get update && sudo apt-get -y install gdal-bin python3-gdal && sudo apt-get -y autoremove && sudo apt-get clean
- Install redis on your system
sudo apt-get install redis
- Check Redis server
Check redis is running on your machine
Login to redis cli
redis-cli
Hit ping
it should return pong
If REDIS is not running check out its documentation
- Clone the Repo to your machine
git clone https://github.com/hotosm/export-tool-api.git
Navigate to repo
cd export-tool-api
- Install python dependencies
pip install -r requirements.txt
Make sure you have https://www.postgresql.org/ setup in your machine or you can use docker
Setup necessary config for API from docs/CONFIG.DOC
uvicorn API.main:app --reload
You should be able to start celery worker by running following command on different shell
celery --app API.api_worker worker --loglevel=INFO
API uses flower for monitoring the Celery distributed queue. Run this command on different shell , if you are running redis on same machine your broker could be redis://localhost:6379//
celery --broker=redis://redis:6379// --app API.api_worker flower --port=5000
After sucessfully running server , hit this URL on your browser
http://127.0.0.1:8000/latest/docs
Flower dashboard should be available on 5000 localhost port.
http://127.0.0.1:5000/
-
Check Authetication :
- Hit /auth/login/
- Hit Url returned on response
- You will get access_token
- You can use that access_token in all endpoints that requires authentication , To check token pass token in /auth/me/ It should return your osm profile
-
Check Extraction :
You can test with the
/snapshot/
endpoint with the following input to check both authentication , database connection and download the exportcurl -d '{"geometry":{"type":"Polygon","coordinates":[[[83.96919250488281,28.194446860487773],[83.99751663208006,28.194446860487773], [83.99751663208006,28.214869548073377],[83.96919250488281,28.214869548073377],[83.96919250488281,28.194446860487773]]]}}' -H 'Content-Type: application/json' http://127.0.0.1:8000/latest/snapshot/
Clean Setup of API can be found in github action workflow , You can follow the steps for more clarity. /workflows/build.yml
Export tool-API uses pytest for tests ,Navigate to root Dir, Install package in editable mode
pip install -e .
Make sure you have postgresql installed locally with postgis extension enabled , Now Run Pytest
py.test -v -s
Run Individual tests
py.test -k test function name
When using New Relic, save the newrelic.ini to the root of the project and run the following to start the server:
NEW_RELIC_CONFIG_FILE=newrelic.ini $PATH_TO_BIN/newrelic-admin run-program $PATH_TO_BIN/uvicorn API.main:app
Repo Sphinx for it's technical documentation.
To Setup :
Navigate to docs Folder and Build .rst files first
cd docs
sphinx-apidoc -o source ../src
sphinx-apidoc -o source ../API
Or you can export it in other supported formats by Sphinx
make html
All exported html files are inside build/html