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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

File metadata

  • Download URL: firehot-0.2.0.tar.gz
  • Upload date:
  • Size: 16.1 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.0.tar.gz
Algorithm Hash digest
SHA256 ae978b70923611c2355fa981f231f81f55404f77a49a5d72e16c11e42a241058
MD5 61c979cfabf2c737315c88eebd5d7e51
BLAKE2b-256 2202b3ddc3d66bbca523a7f6cb482087163aa1a1c58c0c77698017e0c770283e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.0-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 4c6e18a23a6c5785ab136679b7641f5dd361e950dde0372be664bc03df3c1395
MD5 2e96747eb996d76c4de1ee9b47711f97
BLAKE2b-256 7468cb416db72afdd4415ae014be3f92be47313425e52aa13aed7c417cfe9556

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d7f1fe9ef58c83120f94016155c1e04e52aacaef86011a2904e4118a80203968
MD5 56716304f061d75b3f4765c5302aa74e
BLAKE2b-256 ac3d6972218af340eac0eaaff68a1b8e15aee9dd6100c50bee61e97daa48fd7e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 1de419965831505727111d1c017d172df2164d2805b864a74db734b400c68371
MD5 18eda05fff48172332a82d98a2d418e4
BLAKE2b-256 0ac0c1ff3e2cb7e294c2208c8d9e186f5a770bf821896de160598f27828bd60c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 41434e057788acf048705a39b366092db08f2a0d56a59cbaffa651e1aeae20e0
MD5 a9ab68c220d41b631e5767a143828645
BLAKE2b-256 cb75df0e4841d1b1e089f2bdb377858b49df934d9ff91a11d80f8acfc3818317

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.0-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 4805d779f24ede6f2adf28c119bd52658bd00c816b9885948f2216181a86d0a2
MD5 1d5c7863528e76da64ce6b36f8159d28
BLAKE2b-256 c25d3d54afe8ceb19e7a29379833a237fb2338114316c211962a1204386b1bb6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d0c63aca872963b7ad172d15adf3a93e6eee38800d962ce9c945601a8b66a3ba
MD5 e7f06bb93a9271bd4fef786c96c4440c
BLAKE2b-256 65042b8f8f3cb502bd7fb6eda89cf320244e961112ee2523a1aad33c2cec9bbb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.0-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 ccdb3f7d23ea3536c08283d0571f71a00e1978fe4c9f74870fb71525d0d50040
MD5 841aeadb161196faecab1222ba0484d0
BLAKE2b-256 6487f922cd3626b9850b75692c044a8ca02b22231b4ee71194b2b4fca13a2322

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for firehot-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 55bc2fc84054dfdcef4e00d9043e8d1eff83a3c3b2b5ee1ddafa60f43c2d732f
MD5 49e90ece1271d4da5aec6543d79675eb
BLAKE2b-256 c4b33d5365f3bcccd85e40e3ddf861289435a5a78369a2d21443ed02925daf17

See more details on using hashes here.

Provenance

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