PyLiveDev is used to keep track of files associated with your script so it can be re-started if any file is updated.
Project description
Python Live Development tool.
Description
I created PyLiveDev because I work a lot in the microservices/REST space and found constantly having to run/restart services while developing and keeping track of multiple logs in separate windows, to be, quite frankly, a pain in my ass.
Inspired by live updates while using create-react-app in development, I wanted to see if there was a way I could make a python program run multiple services and keep track of the files imported. This way if anything changed it could automatically restart those services and save time while developing. As a bonus, piping all stdout/stderr to one screen so I could immediately see if I wrote bad code or was returning something unexpected.
It works by you creating a JSON configuration file called .pylivedev
in the root of your python project and adding an Object member for each unique process, then running pylivedev
from the root of your project.
Install
foo@bar:~$ pip install pylivedev
Warning
If you are using PyLiveDev on a Linux kernel 2.6+, you may at some point run into an issue where the program quits, either quite immediately, or as more and more files are added to your project. This is due to a hard limit in an underlying library. When this happens add/adjust the following setting in your /etc/sysctl.conf
file (will require root access):
fs.inotify.max_user_watches=16384
The default value is 8192, so adjust accordingly then reboot. Increase as necessary until PyLiveDev stops crashing.
Run
foo@bar:~$ pylivedev
Configuration
{
"rest": {
"command": "rest",
"mode": "module",
"tracked": false,
"python": "/venv/my_project/bin/python",
"arguments": ["-v"],
"additional_files": ["config.json"],
"unbuffered": true,
"verbose": false
}
}
Name | Type | Mandatory | Description |
---|---|---|---|
command | String | Yes | The name of the script or module to run as a process. e.g. "services.rest", "main.py" |
mode | "module" | "script" | "exe" | No | Tells pylivedev whether you are trying to run a stand alone script, a python module, or a binary (or non-parsable) application. Defaults to "script". |
tracked | Boolean | No | When true, proccess is tracked via file changes. Use false for static or external modules. Defaults to true. Will be ignored if mode is set to "exe". |
python | String | No | The full path to the python intepreter to use to run your process. Defaults to the python interpreter running pylivedev. |
arguments | String[] | No | An array of additional arguments passed to the process. |
additional_files | String[] | No | An array of additional files to be watched/observed for changes. |
unbuffered | Boolean | No | Run the processed unbuffered, defaults to true. |
verbose | Boolean | No | Runs pylivedev in verbose mode to give more information on what is happening, what imports were found, what files have changed, etc. Defaults to false. |
Defaults
You can also use the special __default__
member to store values that will be the same across processes. Anything in the proccess config will always overwrite the defaults.
{
"__default__": {
"python": "/venv/my_project/bin/python",
"mode": "module",
"additional_files": ["config.json"],
},
"main": {
"command": "nodes.rest.main"
},
"admin": {
"command": "nodes.rest.admin"
},
"external": {
"command": "nodes.external"
},
"websocket": {
"command": "daemons.websocket"
}
}
The above would work for a file structure like the following
my_project/
|-- daemons/
|-- __init__.py
|-- websocket.py
|-- nodes/
|-- rest/
|-- __init__.py
|-- admin.py
|-- main.py
|-- __init__.py
|-- external.py
|-- records/
|-- __init__.py
|-- .pylivedev
|-- config.json
If, for example, nodes/rest/main.py imported the following:
from time import time
from . import Rest
from records import User
class Main(Rest):
pass
The PyLiveDev would end up with the following list of files to watch/observe for changes
- config.json
- nodes/rest/main.py
- nodes/rest/__init__.py
- records/__init__.py
Any time any of these files is saved/changed on the system, PyLiveDev would shut down the "main" process, re-parse the module looking for imports, and then restart the process.
Note system and pip imports will not be added to the list, like time
in the above example. In most cases system files don't change often and it would waste resources to watch them. If you update a pip library, or update python, it's best to shut down PyLiveDev [CRTL-C] and restart it.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pylivedev-1.2.1.tar.gz
.
File metadata
- Download URL: pylivedev-1.2.1.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09b3b2a0d03809449a41d8cd7879197c9528608413b857abd564dd5211a44568 |
|
MD5 | 4f120ff608ae4da62892fa091201672d |
|
BLAKE2b-256 | 7e1cc2dd4232e81976fc61a38a31b77ad450e29db53eb42d64f835f5db454897 |