Skip to main content

Wildcard-import the Python standard library

Project description

stdlb

Wildcard-import the Python standard library

from stdlb import *

# Most of the standard library is now available:
print(f"Current directory: {getcwd()}")
stderr.write("Python version: {version}\n")

Install

pip install stdlb

Notes

I've found this especially useful in Jupyter notebooks, where I don't have an easy "add import statements as I add code" setup.

Importing seems to take a few milliseconds (on my Macbook Air):

%%time
from stdlb import *
# CPU times: user 914 µs, sys: 397 µs, total: 1.31 ms
# Wall time: 1.6 ms

Collisions / Aliases

In a few cases, a top-level standard library module also contains a member with the same name (e.g. datetime, shlex). stdlb makes an effort to ensure the module "wins" in this case:

from stdlb import *

datetime
# <module 'datetime' from '$PYTHON_HOME/lib/python3.9/datetime.py'>
shlex
# <module 'shlex' from '$PYTHON_HOME/lib/python3.9/shlex.py'>

For convenience, datetime.datetime is also exposed as dt:

dt.now()
# datetime.datetime(2023, 8, 3, 10, 9, 43, 981458)

Custom cached_property

One additional bit of functionality is this custom cached_property decorator, which omits an unnecessary/unserializable lock found in functools.cached_property. cpython#87634 has more info, seems like a fix is coming in Python 3.12.

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

stdlb-0.0.1.tar.gz (2.4 kB view hashes)

Uploaded Source

Built Distribution

stdlb-0.0.1-py3-none-any.whl (2.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page