Skip to main content

Wicked fast hot reloading

Project description

Firehot

Firehot

A package to quickly hot reload large Python projects. Currently in development.

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

File metadata

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

File hashes

Hashes for firehot-0.2.2.tar.gz
Algorithm Hash digest
SHA256 288e16d086c2c24a79ce922abb70db678538426f6fb8e2f2a5cc2355a0c148e4
MD5 7457de4812d741ca40b692938898f4a5
BLAKE2b-256 68bf9a8c6c045bbac6a63e749c986b30311b3ace72adc4d1e06a4063e4f0eb43

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.2-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 49c4dbb497decf8da5cb693d1f00c877ed1207baf22a849d23f4944f7990ecd3
MD5 035379d79953aaf2f35fc1c28fbd9859
BLAKE2b-256 fc58204d4daabb71b8ea48a6962b0dd3f29e8a1ac899514253677574ba276597

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7cbf79e490c934900eb9cbc03e4e16078a110937ec709e4f8a8abae4e2f8e368
MD5 ec18e6dd188bdedebba35eaec97f3466
BLAKE2b-256 b39ec415f2ec24272ca4ac7bcd80b82ff65a8373df726c83d3f6863e1f16ec23

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.2-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 2f6a9a0989bfd39c50467ecadf146a2dcb891087938960f1d913b70ad83e68c0
MD5 c3ca6d3899aaacecafacad374120e10e
BLAKE2b-256 06b7ff6c1b3610c44af53e88b9a51c599c2bb5662d35622c008fd4b6454764a8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c4d4ab88bb0ac58d1a54c894737b9e3d42933481ba35a15ee3d1f33c97c699b7
MD5 5fd220e4be00f6afa4387e20e9506a60
BLAKE2b-256 0e23ff86bc1c96d816482efaa7f4706de836c0e4622b3f927941a061af112400

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.2-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 89c9c86493210798b7b396a0a0e92f3dad27ca0624f2a77a2b007a9c5fba8707
MD5 b49e61000706f0558d7b943e6cec085e
BLAKE2b-256 6d5377424d0859e21bbefaa59b314d594c96bab21759e8d00d621549f63e8e91

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2c384128bf6bc546b7a510ee4f93375c85947160ed17ece0ef4bc79bf9aeaa89
MD5 177e236d7f514ad9fe6d2a48d455c366
BLAKE2b-256 79d2c5abf1636813ba330e1938130f8f5f2ede02ff9dbef9d1411e0aff3f035a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.2-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 2f248d14eb7262fe31bfa70120c7f8a8a824385bf23af6f0f970e6018963d55c
MD5 9953dde95956776194c52fdeec14ca97
BLAKE2b-256 064a6263d094097ca411090fd310e1210e0910f06a8f9e785552e3a0a4e7fb3d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 277972756ecfc0aed85ceece3559d80c6e016318d602d21eee9fa00ed3175521
MD5 1a7c7edb4fd5f15779ae2e13696377f8
BLAKE2b-256 3e2af8abe52d866963abe57fb585129c87ec62c3d9bda7cbdf8ec9727969caf1

See more details on using hashes here.

Provenance

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