Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

sensors.AFRICA API

API to save and access data from deployed sensors in cities all around Africa.


The API is documented here.


Gitignore is standardized for this project using to support various development platforms. To get the project up and running:

  • Clone this repo

Virtual environment

  • Use virtualenv to create your virtual environment; virtualenv venv
  • Activate the virtual environment; source venv/bin/activate
  • Install feinstaub; pip install git+
  • Install the requirements; pip install .
  • Create a sensorsafrica database with the following sql script:
CREATE DATABASE sensorsafrica;
CREATE USER sensorsafrica WITH ENCRYPTED PASSWORD 'sensorsafrica';
GRANT ALL PRIVILEGES ON DATABASE sensorsafrica TO sensorsafrica;
  • Migrate the database; python migrate
  • Run the server; python runserver


Using docker compose:

  • Build the project; docker-compose build or make build
  • Run the project; docker-compose up -d or make up

Docker compose make commands:

  • make build
  • make up - run docker and detach
  • make log - tail logs
  • make test - run test
  • make migrate - migrate database
  • make createsuperuser - create a super user for admin
  • make compilescss
  • make enter - enter docker shell
  • make django - enter docker django shell

NOTE: docker-compose is strictly for development and testing purposes. The Dockerfile is written for production since dokku is being used and it will look for Dockerfile.


  • Virtual Environment; pytest --pylama
  • Docker; docker-compose run api pytest --pylama

NOTE: If entrypoint and start scripts are changed, make sure they have correct/required permissions since we don't grant permissions to the files using the Dockerfile. Run the commands:

chmod +x contrib/
chmod +x contrib/



On your local machine run:

git remote add dokku
git push dokku master

For more information read Deploying to Dokku.


This project uses celery to create cronjobs and flower to monitor the cron jobs as a web admin. To create your jobs, add the task to the and CELERY_BEAT_SCHEDULE in

Everything starts automatically as setup in the contrib/

celery -A sensorsafrica beat -l info &> /src/logs/celery.log  &
celery -A sensorsafrica worker -l info &> /src/logs/celery.log  &
celery -A sensorsafrica flower --basic_auth=$SENSORSAFRICA_FLOWER_ADMIN_USERNAME:$SENSORSAFRICA_FLOWER_ADMIN_PASSWORD &> /src/logs/celery.log  &

Note: If you run the project in the virtualenv you will have to start rabbitmq and pass that link to settings by the env variable SENSORSAFRICA_RABBITMQ_URL



It starts up in in the contrib/

celery -A sensorsafrica flower --basic_auth=$SENSORSAFRICA_FLOWER_ADMIN_USERNAME:$SENSORSAFRICA_FLOWER_ADMIN_PASSWORD &> /src/logs/celery.log  &


Provide channel webhook as an enivronment variable SENSORSAFRICA_CELERY_SLACK_WEBHOOK. The default options are used:

    "slack_beat_init_color": "#FFCC2B",
    "slack_broker_connect_color": "#36A64F",
    "slack_broker_disconnect_color": "#D00001",
    "slack_celery_startup_color": "#FFCC2B",
    "slack_celery_shutdown_color": "#660033",
    "slack_task_prerun_color": "#D3D3D3",
    "slack_task_success_color": "#36A64F",
    "slack_task_failure_color": "#D00001",
    "slack_request_timeout": 1,
    "flower_base_url": None,
    "show_celery_hostname": False,
    "show_task_id": True,
    "show_task_execution_time": True,
    "show_task_args": True,
    "show_task_kwargs": True,
    "show_task_exception_info": True,
    "show_task_return_value": True,
    "show_task_prerun": False,
    "show_startup": True,
    "show_shutdown": True,
    "show_beat": True,
    "show_broker": False,
    "use_fixed_width": True,
    "include_tasks": None,
    "exclude_tasks": None,
    "failures_only": False,
    "webhook": None,
    "beat_schedule": None,
    "beat_show_full_task_path": False,


Set the enivronment variable SENSORSAFRICA_SENTRY_DSN.


Archives are sent to CKAN and require environment configuration:

- CKAN_ARCHIVE_URL=<url that supports bulk uploads>


opendata-stuttgart/feinstaub-api prefer generating and applying migration to the database at the point of deployment (probably to reduce the number of changes to be applied). We, on the other hand, prefer the Django recommended approach of creating and reviewing migration files at the development time, and then applying the same migration files to different environments; dev, staging and eventually production.

Hence, with any contribution, include both sensors.AFRICA-api and opendata-stuttgart/feinstaub-api migration files by running python makemigrations command before creating a PR.



Copyright (C) 2018 Code for Africa

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see