Skip to main content

Library for hot reloading Python code at runtime

Project description

pip install limeade

Live module editing and development enhancement supporting hot reloading for Python 3.4+.

Travis (.org) Codecov PyPI PyPI - Downloads

Usage

Equip your app with the ability to call limeade.refresh() on command (e.g. via hotkey) and invoke after making edits to your source files!

https://github.com/CFSworks/limeade/blob/master/.github/readme/demo.gif?raw=true

Features

  • Speeds up development: Don’t restart your app, refresh your Python code!

  • Automatic: Just call to limeade.refresh(); Limeade does the rest!

  • Thorough: Updates your classes/functions even if instantiated/referenced!

  • Object reuse: Mutable objects are modified in-place; doesn’t break is!

  • Good source of vitamin A

Caveats

Limeade is still experimental. I would be deeply appreciative if you could use it and find ways in which it breaks!

The API is not yet stable. I will keep limeade.refresh() working, but that is the extent of the public API for the time being.

Some things which it cannot (even theoretically) handle are:

  • Closures: These aren’t defined at module reload time; even so, it’s unsafe to mutate code within instantiated closures. Closures will be updated the next time they are instantiated.

  • Changes in metaclass: A class can be mutated if its type (metaclass) isn’t changing, but Python does not permit changing the type of an existing class.

  • Threads: This is not incompatible with threading, but note that threads may observe the program in an inconsistent state if they’re running during a refresh operation. Make sure your threads are out of harm’s way!

Some things which it may handle in the future:

  • Renaming functions/classes: Currently, old and new definitions are matched via the qualified name. Heuristics can be used to match definitions when they are under different names, but this is not yet done.

  • Changes in __slots__ attribute: New slot descriptors cannot be created; however, Limeade could invent its own descriptors for new slots and insert those. They wouldn’t be as efficient but they would get the job done. Descriptors for deleted slots can be cached in case the slot is brought back in a future mutation.

  • Changes in base classes: Initial experiments show that Python is much more picky about this one would expect.

  • Automatic rollback: In case of refresh/mutate failure, it would be great to rollback everything to the state it was in before, so that the running app isn’t left in a half-updated state.

License

All code licensed under 3-clause BSD.

Logo licensed under CC-BY-SA 4.0 with attribution to Elizabeth Reedy.

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

limeade-0.1.1.tar.gz (7.0 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