4
Run platypush in a virtual environment
Fabio Manganiello edited this page 2021-09-17 00:01:11 +02:00
You can run a Platypush instance in a Python virtual environment. There are several advantages for this option:
- You won't have to install dependencies at system level and you can easily create instances in user space
- The available tools will take care for the required dependencies depending on your configuration. Just write your
config.yaml
and Platypush will figure out which dependencies are required by the plugins you wish to use - You can easily copy environments to other machines, as all the required dependencies and configuration for the application to run will all be inside of the
~/.local/share/platypush/<my-device>
folder - You can create multiple instances on the same machine and easily start, stop and remove them. Note however that this option will use more disk space compared to a system installation if you decide to use virtual environments: each environment will install its own set of dependencies instead of relying on those available on the system.
The project comes with platyvenv
, a script that should be installed in your bin path upon Platypush installation.
You can use it to build, remove, start, stop and list Platypush virtual environments.
Note that both python-venv
and platypush
need to be installed on your host system for these steps to work.
Example:
- Create your own
config.yaml
file for a Platypush instance:
device_id:
my-device
logging:
level: INFO
main.db:
engine: sqlite:////home/user/.local/share/platypush/venv/my-device/usr/share/db/platypush.db
backend.pushbullet:
token: YOUR_TOKEN
device: platypush/your_device
backend.redis:
redis_args:
host: localhost
port: 6397
backend.mqtt:
host: YOUR_MQTT_HOST
backend.tcp:
port: 3333
backend.websocket:
port: 8765
backend.http:
port: 8008
tts.google:
language: en-US
ifttt:
ifttt_key: YOUR_IFTTT_KEY
autoremote:
devices:
OnePlus6:
key: KEY_1
PixelC:
key: KEY_2
- Build a virtual environment out of the configuration file using
platyvenv
:
platyvenv build -c /path/to/config.yaml
Note that platyvenv
will inspect your configuration file, automatically identify the required dependencies and install them in your virtual environment.
- Start the new environment:
platyvenv start my-device
The output of the Platypush service is printed on the terminal.
- After it's started up, if everything went smooth, you should already be able to send messages to the new environment over the available exposed service. For example, over JSON-RPC:
curl -XPOST -H 'Content-Type: application/json' \
-d '{"type":"request", "action":"shell.exec", "args": {"cmd":"hostname"}}' \
http://localhost:8008/execute | jq
- Stop a running instance:
platyvenv stop my-device
- Remove an environment:
platyvenv rm my-device