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.2.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.2-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.2-cp313-cp313-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

firehot-0.3.2-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.2-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.2.tar.gz.

File metadata

  • Download URL: firehot-0.3.2.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.2.tar.gz
Algorithm Hash digest
SHA256 70dabe0da7829c778509a2b216efd0959225e8e7894c3cd35ade6019d7d0db90
MD5 81e8ebbbc3f0219c41f5b65b219f41af
BLAKE2b-256 7e6b653baad9e22343cd84fa56574af3c79941e0bb071dd070927abbd6ef9c79

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.2-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 73a3fcab49076edcfccde28459c17aed04b30cca81e8d1477e2635d98775122f
MD5 1d37e5f45b8731c0ef57cf5e58fab228
BLAKE2b-256 06099340dbc5e8a0c53c394ffb757a3b20756d96e1c296bfb05e1e90030eae10

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bb7919a952ddad34251690f5d87664932f42101f20ef06df712b50dcb76ce8f8
MD5 bcee4c4d6f70d10c2d63a512d4250a94
BLAKE2b-256 330a4afdf695aa8930c19640909e29f79f054d8a6e65f6ebd4c490672cb75870

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.2-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 17e850f814cbe31bd5d85ed08202c4a58849d8b54178b117d082cb18baa9d3b4
MD5 169ac7aeba00d81dca764c15fd2f4ad0
BLAKE2b-256 14503532e1ec530ccda87f8163be750381db0276de41a45c6370c3428a4352d4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8871ac69e3434a2553aa7f7bfeca2aec4f8976dfffc8fe68fcdb59d911dc7e15
MD5 79688866fb5fc620af35f43df529d780
BLAKE2b-256 8b249e9a112f1cdb182c2ef8d1a5e254e67d3a3171d98e598ee5b8ca41c5583b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.2-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 1039fbcb72ea0c5506a2e3adbb17a50d7431a89e4241e30c51760867d9583e7f
MD5 e0f59699f0c356ac091ab4a76fed8f4a
BLAKE2b-256 2ffd4991247ce9f72d5991c3b44d22870edbeeca64cfc5753357f6ccc2e43b25

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c247d502a6b44fc8c974804e7099454d0389330521a687df9ca1298f71e588d
MD5 c358c85483647e2f5c578ad5fab5c722
BLAKE2b-256 ca5eb07a49f489d6e2ad816bdb2ab5e410514a753cc95859f50d44186fcda8d9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.2-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 43bf34e5e5cd65ff797c4dd4af8f344b3552a5d2aebad02e0b2a3912fc7b451c
MD5 8168b19724b6ebfb0699130d9593f1b0
BLAKE2b-256 04552bac9b643f6f173fcab14598b356ea5a2ccd6ac47f0ad4a72ef1d4c138eb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b0866a61998a49767e0ca584a0ca3092865e551ab45efc0810005b9cc8808aa
MD5 ac91ab5dbe49805819bd1aa67fbc210b
BLAKE2b-256 4f95d1c4e8fa4dc2951dd717fc38a6abade954390bb40c84c43b4b39b64e18ac

See more details on using hashes here.

Provenance

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