This repository contains materials used and showcased in the DjangoCon Africa 2025.The talk is/was about how to use the Django framework to build a STAC API implementing the STAC standard.
The repository includes the Django project that implements a STAC API.
-
Clone the repository:
git clone https://github.com/samweli/djangocon_africa_2025.git cd djangocon_africa_2025/ -
Setup Database
Install and start PostgreSQL by running:
sudo apt update
sudo apt install postgresql postgresql-contrib libpq-dev
sudo service postgresql startCreate a database and user:
```bash
sudo su -l postgres
createdb stac
psql stac
```
Grant privileges to the user
```sql
CREATE USER stac WITH PASSWORD 'stac';
GRANT ALL PRIVILEGES ON DATABASE stac TO stac;
CREATE EXTENSION postgis;
exit;
```
- Create virtual environment
mkvirtualenv stac_api- Update migrations
Copy the .env.example file to .env and
edit the file and update the database credentials.
pip install -r requirements.txt ./manage.py migrate-
Create test data(optional) Use the scripts/asset_fetch.py script to create sample test data.
pip install -r scripts/requirements.txt
Then run the script to create test data
python scripts/asset_fetch.py
After the scripts finishes a
downloadsdirectory and a geojson file will be created in the scripts folder. Use the geojson file content to populate the database using the following command../manage.py shell < import_landsat.pyFollowing output should be displayed in the console if the data was imported successfully.
Imported item: LC08_L2SP_047027_20200729_02_T1 → Asset added for LC08_L2SP_047027_20200729_02_T1 Imported item: LC08_L2SP_046027_20200722_02_T1 → Asset added for LC08_L2SP_046027_20200722_02_T1 Imported item: LC08_L2SP_047027_20200713_02_T1 → Asset added for LC08_L2SP_047027_20200713_02_T1 Imported item: LC08_L2SP_046027_20200706_02_T1 → Asset added for LC08_L2SP_046027_20200706_02_T1
-
Start and run the Django Project
./manage.py runserver
-
Once the project is running, you'll see a URL in the console output. It will look something like:
http://127.0.0.1:8000
-
Open this URL in your web browser and head over
http://127.0.0.1:8000/stac, You'll be taken to the STAC API Catalog root page..
Feel free to contribute to the project by submitting pull requests or issues on GitHub.
This project is licensed under the MIT License. See the LICENSE file for more details.
If you have any questions or issues, please reach out [email protected]