Skip to content

Skip micropip load for apps with pyproject.toml#6300

Open
FeodorFitsner wants to merge 2 commits intomainfrom
skip-micropip-load
Open

Skip micropip load for apps with pyproject.toml#6300
FeodorFitsner wants to merge 2 commits intomainfrom
skip-micropip-load

Conversation

@FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented Mar 12, 2026

Close #6259

Summary by Sourcery

Conditionally load the micropip package in the Pyodide worker only when Python dependencies need to be installed, avoiding unnecessary loading for apps that do not require micropip.

Enhancements:

  • Introduce a helper coroutine to lazily import or load micropip via pyodide_js only when requirements or explicit dependencies are present.
  • Skip installing dependencies if requirements.txt is empty to avoid redundant micropip operations.

Avoid loading micropip unconditionally at startup. Introduce an async ensure_micropip() helper that tries to import micropip and falls back to pyodide_js.loadPackage('micropip') if it's not present. Call ensure_micropip() and import micropip only when requirements.txt exists or when dependencies are provided in arguments. Also skip micropip.install when requirements.txt contains no entries. These changes reduce startup work and handle environments where micropip isn't preloaded.
Replace ensure_micropip with micropip_imported() which returns a boolean indicating whether micropip is already importable. If micropip is missing, the code now loads the micropip package via pyodide_js.loadPackage('micropip') and then conditionally imports micropip in the requirements and dependencies handling paths. This avoids always invoking the package loader unconditionally.
@cloudflare-workers-and-pages
Copy link

Deploying flet-examples with  Cloudflare Pages  Cloudflare Pages

Latest commit: cecd17f
Status: ✅  Deploy successful!
Preview URL: https://70894229.flet-examples.pages.dev
Branch Preview URL: https://skip-micropip-load.flet-examples.pages.dev

View logs

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@cloudflare-workers-and-pages
Copy link

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: cecd17f
Status: ✅  Deploy successful!
Preview URL: https://6097a012.flet-docs.pages.dev
Branch Preview URL: https://skip-micropip-load.flet-docs.pages.dev

View logs

@FeodorFitsner FeodorFitsner added this to the 0.83.0 milestone Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: Flet app built with flet build web to skip loading micropip wheel if it's already a part of app package

1 participant