Skip to main content

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

PyLiveDev

pypi version MIT License

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

pylivedev-1.2.1.tar.gz (14.5 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page