Skip to content

rl-institut/django-oemof-api

Repository files navigation

Repo logo

django-oemof-api

A to test [django-oemof](https://github.com/rl-institut/django-oemof).

License License
Documentation Documentation
Publication  
Development open issues closes issues closes issues closes issues
Community contributions contributors counter

python 3.10 postgresql 14 or higher

  1. create a virtual environment with python 3.10
  2. install requirements in the virtual environment with
```
pip install -r requirements

```

  1. setup a postgresql database and provide the following environment variables

``` SQL_ENGINE="django.db.backends.postgresql" SQL_DATABASE="name_of_your_database" SQL_USER="name_of_your_user" SQL_PASSWORD="pw_of_your_user" SQL_HOST="localhost" SQL_PORT="postgresql port, usually 5434"

# replace 'localhost' by the name of the container if using docker CELERY_BROKER_URL="redis://localhost:6379/0" CELERY_RESULT_BACKEND="redis://localhost:6379/0"

```

  1. run migrations
```
python manage.py migrate

```

  1. run the server
```
python manage.py runserver

```

  1. visit the webapp at 127.0.0.1:8000/oemof

In order to simulate a scenario from a datapackage you should place datapackages in the django_oemof_api/data/oemof folder.

One this is done, open a new terminal with the same virtual environment and make sure you provide those two environment variables as well

``` CELERY_BROKER_URL="redis://localhost:6379/0" CELERY_RESULT_BACKEND="redis://localhost:6379/0"

``` Then start the celery worker with

` celery -A django_oemof_api.celery worker --loglevel=info -E `

Finally, you can send a post request from a third terminal

``` import requests import json

HOST = "http://127.0.0.1:8000" SIMULATE_URL = f"{HOST}/oemof/simulate"

payload = {
"scenario": "<name of a scenario datapackage within data/oemof folder>", "parameters": json.dumps({"some": "paremeters"}),

}

with requests.session() as client:
req = client.post(
SIMULATE_URL, data=payload,

) answer = json.loads(req.text) print(f"{SIMULATE_URL}}?task_id={answer['task_id']}")

```

The documentation is created with Markdown using MkDocs.
All files are stored in the docs folder of the repository.
A GitHub Actions deploys the production branch on a GitHub Page.
The documentation page is rl-institut.github.io/django-oemof-api/
Everyone is invited to develop this repository with good intentions.
Please follow the workflow described in the CONTRIBUTING.md.
The code of this repository is licensed under the MIT License (MIT).
See LICENSE.txt for rights and obligations.
See the Cite this repository function or CITATION.cff for citation of this repository.

Releases

No releases published

Packages

No packages published

Languages