Skip to main content

a backport of lazy imports to python<3.15

Project description

- courtesy of pycon us 2026 steering council presentation

NO

... unless

please don't use this

no seriously. I do not need another joke package of mine to be deemed "critical" to pypi 1

ok how do I use it

  1. pip install future-lazy-imports
  2. add # -*- coding: future-lazy-imports -*- to the top of your file (second line if you have a shebang)
  3. use lazy import ... and lazy from ... as normal!
# -*- coding: future-lazy-imports -*-
lazy from asyncio import run

async def hello():
    print('hello hello world!')

def main():
    run(hello())  # lazily imported!

if __name__ == '__main__':
    raise SystemExit(main())
$ time python3 t.py
hello hello world!

real    0m0.064s
user    0m0.061s
sys 0m0.007s
$ time python3  -c 'import t'

real    0m0.027s
user    0m0.023s
sys 0m0.005s

wow!

problems

this doesn't actually implement the PEP, notably __lazy_imports__ doesn't work also this adds a little bit of overhead to every function (since we don't have the freedom to add code to LOAD_GLOBAL) and I'm pretty sure lambda doesn't work ¯\_(ツ)_/¯

sometimes stacktraces point to the wrong line number (if your function starts with a block statement)

see also please don't use this

  1. with almost a million downloads per month and 45M+ total

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

future_lazy_imports-1.0.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

future_lazy_imports-1.0.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file future_lazy_imports-1.0.1.tar.gz.

File metadata

  • Download URL: future_lazy_imports-1.0.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for future_lazy_imports-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d466ba7d65a83aa7b02fcd2b99617ecd821c94d99698dc359d5958efee469363
MD5 478b1899e58a599f61be136aa1f854e1
BLAKE2b-256 400d3cdbba14a5cb95c0d3e647ffc2550b7e274d8ea7ff0f49fd488caaf0d03c

See more details on using hashes here.

File details

Details for the file future_lazy_imports-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for future_lazy_imports-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 57a8c8691467db2a39e14126a5e034c32357910fcab9b5c2f039f694aa8143f4
MD5 e7532954607811c562b3f2564216d7b9
BLAKE2b-256 ebf21083a4166e6dc642831f942e37851d9561b19fdd3c71c7e20ee6654c0381

See more details on using hashes here.

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