Title: [MNT]: Lazy imports in python 3.15+ · Issue #30933 · matplotlib/matplotlib · GitHub
Open Graph Title: [MNT]: Lazy imports in python 3.15+ · Issue #30933 · matplotlib/matplotlib
X Title: [MNT]: Lazy imports in python 3.15+ · Issue #30933 · matplotlib/matplotlib
Description: A ways off, but creating this tracking issue to collect ideas as they arise. Python 3.15 (October 2026) will introduce PEP 810 - Explicit lazy imports. This has the potential to significantly improve startup time performance - as one exa...
Open Graph Description: A ways off, but creating this tracking issue to collect ideas as they arise. Python 3.15 (October 2026) will introduce PEP 810 - Explicit lazy imports. This has the potential to significantly impro...
X Description: A ways off, but creating this tracking issue to collect ideas as they arise. Python 3.15 (October 2026) will introduce PEP 810 - Explicit lazy imports. This has the potential to significantly impro...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/30933
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[MNT]: Lazy imports in python 3.15+","articleBody":"A ways off, but creating this tracking issue to collect ideas as they arise.\n\nPython 3.15 (October 2026) will introduce [PEP 810 - Explicit lazy imports](https://peps.python.org/pep-0810). This has the potential to significantly improve startup time performance - as one example Meta reports 70% reduction in initialization time by converting its libraries to use lazy imports ([link](https://developers.facebook.com/blog/post/2022/06/15/python-lazy-imports-with-cinder/)). I expect the performance increase here to compound as our dependencies roll in lazy import support as well. With how widely used matplotlib is, I expect people to start asking for this before too long.\n\nFor backwards compatibility, we will need to use the `__lazy_modules__` approach rather than the `lazy` import syntax:\n\n```python\n__lazy_modules__ = [\"json\", \"collections.abc\"]\n\nimport requests # eager, since not in list\nimport json # lazy\nfrom json import dumps, loads # lazy, each name is a lazy proxy\nfrom collections.abc import Mapping # lazy\nfrom numpy import * # eager, but we should move away from star imports\n```\n\nSome things may currently rely on eager import-time execution (global state, ImportError checks, backend/plugin registration (?), etc). Anything relying on eager execution can be left out of the `__lazy_modules__` list and fixed at a later time.\n\nThere are a few existing issues talking about deferred imports, which I believe will be subsumed by this. We can talk about whether it's worth putting effort into those anyways for older python versions: https://github.com/matplotlib/matplotlib/issues/22247, (maybe) https://github.com/matplotlib/matplotlib/issues/30578.\n\nRough plan:\n\n- [ ] Benchmark existing startup time (should measure both `import matplotlib` and `import matplotlib.pyplot as plt`)\n- [ ] Audit code for anything relying on eager import-time execution\n- [ ] Audit code for deferred imports which can be brought up to top-level\n- [ ] Audit code for star imports\n- [ ] Any code relying on a particular import _order_ should be fixed\n- [ ] Move imports over to `__lazy_modules__` (excluding things relying on eager imports)\n- [ ] Benchmark new startup time\n- [ ] Add CI test coverage for all-eager and all-lazy import cases to catch breakage: `python -X lazy_imports=none -m pytest` `python -X lazy_imports=all -m pytest`\n\nAlternatively this could be an incremental roll-in, focusing on the heavier weight modules.","author":{"url":"https://github.com/scottshambaugh","@type":"Person","name":"scottshambaugh"},"datePublished":"2026-01-04T17:30:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/30933/matplotlib/issues/30933"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d557f5fc-e15d-240f-d778-faf423b53c72 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8962:FE603:37958F6:49506D3:696BA9C3 |
| html-safe-nonce | 3751e02e1b8dccccdaa49676c4e855c2793b2df06f7309dbd4185469434d417a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTYyOkZFNjAzOjM3OTU4RjY6NDk1MDZEMzo2OTZCQTlDMyIsInZpc2l0b3JfaWQiOiIxNDI1MjQ0MjU5OTY1NzA4NzM5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | cb4df9de5483e22c1638d44ceab369752da32ecdb0cd10495ceea45bcc0cfff1 |
| hovercard-subject-tag | issue:3779465387 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/30933/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ee5424c1375c82f7e94cbbe615be4ccea3f9dacb3db17b0b5130f978096ddd22/matplotlib/matplotlib/issues/30933 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ee5424c1375c82f7e94cbbe615be4ccea3f9dacb3db17b0b5130f978096ddd22/matplotlib/matplotlib/issues/30933 |
| og:image:alt | A ways off, but creating this tracking issue to collect ideas as they arise. Python 3.15 (October 2026) will introduce PEP 810 - Explicit lazy imports. This has the potential to significantly impro... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | scottshambaugh |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width