Introduction¶
PyBrook - a real-time cloud computing framework for the Internet of Things. PyBrook enables users to define complex data processing models declaratively using the Python programming language. The framework also provides a generic web interface that presents the collected data in real-time.
PyBrook aims to make the development of real-time data processing services as easy as possible by utilising powerful mechanisms of the Python programming language and modern concepts like hot-reloading or deploying software in Linux Containers.
A simple docker-compose up
is enough to start playing with the framework.
Run demo with Docker¶
It is recommended to use docker-compose
for learning (you can use the docker-compose.yml
from the project repository:
docker-compose up
This command will start all the services, including Redis with Redis Gears enabled.
The following services will be available:
- OpenAPI docs (ReDoc): http://localhost:8000/redoc
- OpenAPI docs (Swagger UI): http://localhost:8000/docs
- PyBrook frontend: http://localhost:8000/panel
- Locust panel for load testing: http://localhost:8089
You should probably visit the Locust panel first and start sending some reports.
Using your own model¶
The configured model is pybrook.examples.demo
, but replacing it with your own is very easy.
First, you have to save your custom model somewhere.
For now, you can just copy the source of pybrook.examples.demo
(attached below) and save it as mymodel.py
in your working directory.
Source of pybrook.examples.demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
After creating mymodel.py
, you should add it to the api
and worker
containers, using a Docker volume.
To make PyBrook use mymodel
instead of pybrook.examples.demo
, you should also alter the arguments passed to gunicorn
and pybrook
.
You can simply add it to the default docker-compose.yml
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
Then run docker-compose up --build
again, to start PyBrook - this time using your own model.
Setup & Development¶
You can install the PyBrook from PyPi using pip
:
pip install pybrook
Running all services manually, without Docker¶
To run the pybrook.examples.demo
model, you have to start all the required services manually:
# Redis + Redis Gears
docker run --net=host -d redislabs/redisgears:1.0.9
# HTTP API based on pybrook.examples.demo - uvicorn
uvicorn pybrook.examples.demo:app --reload
# PyBrook workers based on pybrook.examples.demo
pybrook pybrook.examples.demo:brook -rg
# Locust - load testing
locust -H http://localhost:8000
Contributing¶
PyBrook uses poetry for dependency management. To install all its development dependencies, simply run this command:
poetry install
Tests¶
make test
Code quality¶
The source code of PyBrook is formatted using yapf and isort.
To run them with the correct settings, use the following command:
make format
PyBrook uses mypy
for type checking and flake8
for linting.
Use the following command to run them with the appropriate settings:
make lint