Skip to main content

PyLiveUpdate

PyLiveUpdate is tool to help you modify your running python code without stopping it. It is useful for modifying long-running server programs in production with zero downtime. Some modification scenario includes: inject code to profile the runtime of certain lines of code; inject code to print out a variable for debugging; apply a patch without restarting.

Install

pip install pyliveupdate

How to use

Put these two lines of code in your server program and run it

from pyliveupdatescripts import UpdateStub
UpdateStub().start()

Start a controller to modify it!

> pylu-controller -l 127.0.0.1:50050

Some predefined modification available in the controller

> FuncProfiler.profile('__main__.**') # inject the time profiling code into all functions in __main__
> LineProfiler.profile('__main__.bar', [11, 12]) # inject time profiling code into certain lines
> FuncDebugger.debug('__main__.bar') # inject code to print out function parameter and return value
> LineDebugger.debug('__main__.bar', [11, 12]) # inject code to print out variables in certain lines
> VarDebugger.debug('__main__.bar', 'b') # inject code to print out all values of a variable in different statements

You can also define your own customized modifications.

Customized modification

There are in general two kinds of modification: instrument and redefine:

Instrument code into existing functions

from pyliveupdate.update import Instrument, UpdateManager
def _line_after(a):
    print(a)
update = Instrument('__main__.bar', 
                    {('line_after', [12, 14]): _line_after})
UpdateManager.apply_update(update)

The code injects a print(a) in line 12 and 14 in function __main__.bar.

Redefine (patch) existing functions

from pyliveupdate.update import Instrument, UpdateManager
def new_bar(a):
    print('new_bar', a)
update = Redefine('__main__', None, {'__main__.bar':new_bar})
UpdateManager.apply_update(update)

The code redefines __main__.bar with new_bar.

Revert the modification

PyLiveUpdate also support to revert a modification on the fly:

> LU.ls() # list all modification
> LU.revert(1) # revert modifation with id 1

Metadata

Release files for pyliveupdate 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyliveupdate 0.3.1
File Size Uploaded Provenance Actions
pyliveupdate-0.3.1.tar.gz 43.0 kB Without provenance Details for pyliveupdate-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyliveupdate 0.3.1
File Interpreter ABI Platform Actions
pyliveupdate-0.3.1-py3-none-any.whl Python 3 none any Details for pyliveupdate-0.3.1-py3-none-any.whl

Total release size: 118.8 kB

Release files / pyliveupdate-0.3.1.tar.gz

Download URL pyliveupdate-0.3.1.tar.gz
Size 43.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f4f7a8a322616edafca04aa90a12221692500c831bd6ba5191bab4652f7718c3
BLAKE2b-256 checksum
How to use checksums
8936078a457c7595df54215d00fc05d4e5130bcd1f7cdc35c5b355b2220db2e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.6.9

Release files / pyliveupdate-0.3.1-py3-none-any.whl

Download URL pyliveupdate-0.3.1-py3-none-any.whl
Size 75.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a2ce76a69deea5fc94a22902908fc98bf80582707444320d26d1dee449cc91b
BLAKE2b-256 checksum
How to use checksums
de32318c12faee8bd090e3da9194257f1d4fc14ad1fa2e872126cbd4ab7a35a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.6.9

Security for pyliveupdate 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page