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.0.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.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for future_lazy_imports-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5b32d4215da5d885969d5f19a6ebbf7bb63641968e6557494cd092d83f96a86b
MD5 e6b9cae9ec216ec4f06fa7eaad0ca84a
BLAKE2b-256 50dcd899b21bf9524adaefba0c3f73687e060238c2ab5177ab24ce33e3c8c588

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for future_lazy_imports-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95111b74d4ac6fecf40bbb31dfc069d0f3b0a5dcb0ca71c265cc80a063f21c09
MD5 89af4bb58c517f4378f343f6bd5e9d4b
BLAKE2b-256 6ce68ce770cdff90c4c7c1cb1199ada2da5fa67988b60116df052b00ebea286d

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