Skip to main content

Wicked fast hot reloading

Project description

Firehot

Firehot

A package to quickly hot reload large Python projects. Currently for Linux & OSX.

Background

Once your project gets to a certain size, the main overhead of application startup is typically the loading of 3rd party packages. Packages can do varying degrees of global initialization when they're imported. They can also require 100s or 1000s of additional files, which the AST parser has to step through one by one. Cached bytecode can help but it's not a silver bullet.

Eventually your bootup can take 5-10s just to load these modules. Fine for a production service that's intended to run continuously, but horrible for a development experience when you have to reboot after changes. Firehot solves this by importing dependencies once, then forking your environment for each exec. Think of it like building a docker image then executing it whenever you make a change.

Python Usage

from firehot import isolate_imports
from os import getpid, getppid

def run_under_environment(value: int):
   parent_pid = getppid()
   print(f"Running with value: {value} (pid: {getpid()}, parent_pid: {parent_pid})")

with isolate_imports("my_package") as environment:
   # Each exec will be run in a new process with the environment isolated, inheriting
   # the package's third party imports without having to re-import them from scratch.
   context1 = environment.exec(run_under_environment, 1)
   context2 = environment.exec(run_under_environment, 2)

   # These can potentially be long running - to wait on the completion status, you can do:
   result1 = environment.communicate_isolated(context1)
   result2 = environment.communicate_isolated(context2)

   # If you change the underlying file on disk to add an import, you can run update_environment.
   # If the files on disk don't add any new imports, it will be a no-op and keep the current
   # environment process running.
   environment.update_environment()

   # Subsequent execs will use the updated environment.
   context3 = environment.exec(run_under_environment, 3)
   result3 = environment.communicate_isolated(context3)

Logging

By default, Firehot logs at the warn level, but you can adjust this by setting the FIREHOT_LOG_LEVEL environment variable. Most of these logs come from the Rust code.

Available log levels (from most to least verbose):

  • trace: Extremely detailed information, useful for debugging specific issues
  • debug: Detailed information useful during development
  • info: General information about what's happening (default)
  • warn: Warning messages for potential issues
  • error: Error messages for actual problems

Example usage:

# Set to debug level for more detailed logs
FIREHOT_LOG_LEVEL=debug python your_script.py

# Set to error level for minimal logs
FIREHOT_LOG_LEVEL=error python your_script.py

Architecture

You launch Firehot by pointing it to your package name, which we resolve internally to a disk path that contains your code. From there, our Rust logic takes over. The pipeline will parse this directory recursively for all Python files, then parse the code's AST to determine which imports are used by your project.

It will then launch a continuously running process that caches only the 3rd party packages/modules. We think of this as the "template" process because it establishes the environment that will be used to run your code. None of your user code is run in this process.

When code changes are made in your project, we will:

  • Determine if your changes affected the imported packages
  • If not, we can fork the parent process and pass in your user code. This will load all modules from scratch, but because importlib caches the modules in global space, it will be a no-op because of the template.
  • If so, we will tear down the current parent process and start a new one with the full 3rd party packages imported. Then we'll fork the environment as normal.

Local Experiments

To test how firehot works with a real project, we bundle a mypackage and external-package library in this repo.

# To do a regular, fast development build
(make build-develop && cd mypackage && uv run test-hotreload)
# To pass the args we use in a release
(make build-develop MATURIN_ARGS="--release --strip" && cd mypackage && uv run test-hotreload)

Unit tests

cargo test

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

firehot-0.3.1.tar.gz (16.3 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

firehot-0.3.1-cp313-cp313-manylinux_2_39_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

firehot-0.3.1-cp313-cp313-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

firehot-0.3.1-cp312-cp312-manylinux_2_39_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

firehot-0.3.1-cp312-cp312-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

firehot-0.3.1-cp311-cp311-manylinux_2_39_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.39+ x86-64

firehot-0.3.1-cp311-cp311-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

firehot-0.3.1-cp310-cp310-manylinux_2_39_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.39+ x86-64

firehot-0.3.1-cp310-cp310-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file firehot-0.3.1.tar.gz.

File metadata

  • Download URL: firehot-0.3.1.tar.gz
  • Upload date:
  • Size: 16.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for firehot-0.3.1.tar.gz
Algorithm Hash digest
SHA256 19ae6e6878b2722b872303428f97e881153530ab080df6c406c23d228680b7ec
MD5 b67a60a7d415ac95bd5e93e74248a1b7
BLAKE2b-256 2b941beb350b8d43f85c1e1058e92ee96da4af40abb3481ab5ec614e88f7b8b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.1.tar.gz:

Publisher: ci-build.yml on piercefreeman/firehot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file firehot-0.3.1-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for firehot-0.3.1-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 c2ca6139b7e7052c2fa83bcacbfc896e1570ee6eddcae390e0b52f661779cf23
MD5 f71a80f1c7be9fe90e9d34a623926a25
BLAKE2b-256 a94331ad8eddda49f905bbb33ce6e3e6d1aee6f031a51bc68205b30e6f05fdd8

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.1-cp313-cp313-manylinux_2_39_x86_64.whl:

Publisher: ci-build.yml on piercefreeman/firehot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file firehot-0.3.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for firehot-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6d5d4fd7986d2b961495db82c7deb6070f4f2e7ed8e1274ec9078be2c3802df8
MD5 4089d50d35b4ac80c1301cba7f3cd89c
BLAKE2b-256 11cf6daf184e00e193fa4173bec85080200d2bd48befb89ba646961b845bd1fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.1-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: ci-build.yml on piercefreeman/firehot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file firehot-0.3.1-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for firehot-0.3.1-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 36a05aead60c3bf3b8971f389e9a030ba0547bd576de608b953b1f3176623812
MD5 bda9a2c196fa022105085bb1f6e4e262
BLAKE2b-256 1c96b14bbbec01ba666356c103976b20912de7606e6446d43c831446a6eadcd4

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.1-cp312-cp312-manylinux_2_39_x86_64.whl:

Publisher: ci-build.yml on piercefreeman/firehot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file firehot-0.3.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for firehot-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ae483e779bad7d687eeffe725246e59b93c5c8aa8d7199a2d8b91c9a4fe7e403
MD5 bceccdf0845d312e4e42ee11d9e17643
BLAKE2b-256 d677ffc64a80403434ff602fd8405986d76487cd66e4e4eceed80dd1e4660fed

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: ci-build.yml on piercefreeman/firehot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file firehot-0.3.1-cp311-cp311-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for firehot-0.3.1-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 fbf5c989110be1f020bbea4bd5b2912b629301502cc94571e9e4bc4ae4a35226
MD5 cd4ddaf314c656b5c1dd9787b43a4462
BLAKE2b-256 1c478b37896226638e62365d99df55e81070efacd61c7270fd3863a8d6f99387

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.1-cp311-cp311-manylinux_2_39_x86_64.whl:

Publisher: ci-build.yml on piercefreeman/firehot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file firehot-0.3.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for firehot-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aa27f49801a7967b7b1886453e25c26f0c759192838fae4479a43020f4f00428
MD5 2b0d0f9f0ed104e055376bbd040f9d7b
BLAKE2b-256 d3aa6dd3ae781828086ca79957c27f224d79f0e9e2ff6d2b114748ff8687fc9a

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.1-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: ci-build.yml on piercefreeman/firehot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file firehot-0.3.1-cp310-cp310-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for firehot-0.3.1-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 aa525f49858c9f71a25863be4573a6e965473a0f7ab8fdc5be1b5d5ed9ed6103
MD5 b31dc57d5580af7f98abcaa8e77d2f45
BLAKE2b-256 64688089f20f3a1384f293195f2d0032923e665d98b0dab7eda0380200d971b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.1-cp310-cp310-manylinux_2_39_x86_64.whl:

Publisher: ci-build.yml on piercefreeman/firehot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file firehot-0.3.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for firehot-0.3.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6f5cd830b101abe7ba0f2313c7cb9aaffb647878ea53dd3f2cf8abc29b033fd9
MD5 b4e7578311a09be17827174d2c7eb781
BLAKE2b-256 2d1b75a4cae6db5980e2720d92723c68db8556882a8c3c5160ab6c8ff0bb7f9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.1-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: ci-build.yml on piercefreeman/firehot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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