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 demopackage and external-package library in this repo.

# To do a regular, fast development build
(make build-develop && cd demopackage && uv run test-hotreload)
# To pass the args we use in a release
(make build-develop MATURIN_ARGS="--release --strip" && cd demopackage && 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.4.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.4-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.4-cp313-cp313-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

firehot-0.3.4-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.4-cp312-cp312-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

firehot-0.3.4-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.4-cp311-cp311-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

firehot-0.3.4-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.4-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.4.tar.gz.

File metadata

  • Download URL: firehot-0.3.4.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.4.tar.gz
Algorithm Hash digest
SHA256 5c70d6f4ea0cdb06f5fc4e9cb915f0440fcf4354b9e87c429c76a8fbb17ab960
MD5 9f389ff642ca442005a737497ca8540d
BLAKE2b-256 d253320679f81574c7c767d9bb1d4f03f707c397d5b02c99ed11985d68d1dc4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.4.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.4-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for firehot-0.3.4-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 59fa68981f70e124c0b7684218df73f00c167750018dfc98b9dc370a6fc7d386
MD5 29b9b72035d5765b673fc632176d85a0
BLAKE2b-256 bc6fcdfe30723a91dba80e5f278e9d5b4a69cef48bb04db1368f561d09f75b71

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.4-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.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for firehot-0.3.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0155daf01dd68fdd34bc0c3901cc6fbdb9b97136d65e301b172e6f4fc070d4b7
MD5 97ea3f1def45c30372e722610fe2d19a
BLAKE2b-256 02c457e2654f8e1da877c14001b78262bf325cbee51708e593cf6aa6cdebe513

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.4-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.4-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for firehot-0.3.4-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 fd050331030830a70b2bc22b75537530bb94f0f2778e34125dafddfadc87f76a
MD5 ef085840406179f931bba63f661afaa4
BLAKE2b-256 aa8e110d7e076c6a126e02b37db9ee206a87ee1a511c7aa6696fd23a80dc65ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.4-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.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for firehot-0.3.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5ff37e3ff84b52e86aebeb840681a58d2f21617e1cae44d4c27113b0f125806d
MD5 0efba57da5e4f258405da93c1cff27c8
BLAKE2b-256 ef83365bca67c4e6354f7b55df58f8e487632a42431e5447bc779846951abe00

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.4-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.4-cp311-cp311-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for firehot-0.3.4-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 136a662710833297350bed9db2cbd3a12ffe20bd0587de265c5fa893cd92be7f
MD5 5824763cb6a0667b9d9b6eaa59923659
BLAKE2b-256 80fe86e22bf19badd17b1cd9b3a0f5a85b78a21ad9dfec50b69edeac31cce452

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.4-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.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for firehot-0.3.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5f162d058a9a47f86bfdd15e4bf9917f370863da89e03e65ca4e2f523205a7d2
MD5 0824413c517dfe87627a90bb743aaa96
BLAKE2b-256 294dc41bd2015e7e56eaa370fb6faadbb4e36195009b4cdee0cca2e9d9bfde6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.4-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.4-cp310-cp310-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for firehot-0.3.4-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 2b3eb8bd1adbb10043f8099908e12f868fb6e5b49b923990701e80b8510a8827
MD5 fb123fa2cbb5677fb6084ba11a233c29
BLAKE2b-256 740a5f4077bb32c6666d66ff13ca1d02e5eb5f9d47d9f9f47404f49a12dc1b59

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.4-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.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for firehot-0.3.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5591e9da5c573c40c90f21ad2b96c2566cc8379b30d4b29fc0e026d56802f963
MD5 6bc2c8e0860c095f95cf02b57750187f
BLAKE2b-256 991945d6e0d2a2bea80f9b9bf31a7cfb91d6990bda3eaeaa9cdef927c4cd4934

See more details on using hashes here.

Provenance

The following attestation bundles were made for firehot-0.3.4-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