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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

firehot-0.3.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: firehot-0.3.0.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.0.tar.gz
Algorithm Hash digest
SHA256 06aa4a06010dd08e117d89f366aa04d3aad9b9e923eaabf75117b4f20403fde8
MD5 1ac356e22433ef946c30bcfc3cf27df0
BLAKE2b-256 9e05086fda9278c6e0e2b8981dd78b6e6b35d8c2db9ee3565956292da006af72

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.0-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 b6baf94689cf349bfbfe3c87f73c9e81053f844c713584a6b7247d4fa947b429
MD5 9fb6b7301c8d6f6ac55fdb5ac9ec9f34
BLAKE2b-256 39a0a5f3cfe605147f285a36484bf71537f448522b9b7a7a2640b80215d03331

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4fc33391fea2c3ed17e9b28a180bc4af95a8295a218ab4f2a7a3d2dd9028005d
MD5 641e2fd165a491ac0f9cd590c1e335ee
BLAKE2b-256 96b8d695dccfa734fe2841bdf380762511fc857877f15240cb29dc031ef3a26f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 b951e6ee24e0a4446948e49a0538ff21685c9c57a20460e2d5635ef6242f06cd
MD5 bb9dc3fa77c3a96ef9bfd5b0bf407cdf
BLAKE2b-256 b974e8c40eae52cf0d4ce0fb9ccb8958f176cadfd1bd2a88947c224bb13cd5d4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 433d1600f964126c36bfab9b77f5cd20d683257e5dc6533d0cc923297a5ac39b
MD5 23ebd0ccbef5e2711e7be1b84c0f5162
BLAKE2b-256 65bf62529c136f4ed24990a88fe192ec7f818e7a4daf5269434ef557401bf632

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.0-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 29cadb12178369c4854774b02ed97ba7fb1652731082a0d4a37c5e4057a83c03
MD5 e51e1935dd566646129292f044adb9d6
BLAKE2b-256 6641f60249ba90a3d189fed6969448dc195570013ae42e09fd04cc48b15f008f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a2d06d963295b26fd4d2e083b24cdc713ccc546241a2a89d86c6115183a34e5d
MD5 052b754abf2ffc23d791a670584adbfa
BLAKE2b-256 c02635bc91635afda10295c780ca38cace9719d2c36cae79e61d5d65a63120c3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.0-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 9fa862c72284f084b5af614b0eefdfa802a8c4ce6fa0466850a01959ae6f8229
MD5 4924abc56cd5a1a63ab599979680324f
BLAKE2b-256 8f0cfe7ab80e55adbe5d28c9fb1b77cf055431b66bf18d3de1fcc87970a8a4a5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3f0b4a6612fe2202a096e573b233d6abf86f4e1b76ed1369e5ace7634e2f88a6
MD5 147c88be40a78129fa8797f091692c60
BLAKE2b-256 8b33c43438aef03a22a76aa1bd84e27e98bb29ca3e08c313a3c94628c560dbec

See more details on using hashes here.

Provenance

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