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, time). 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'>
time      # <module 'time' (built-in)>

A few names are disambiguated with the most sensible-seeming defaults:

path  # resolves to os.path, not sys.path
join  # os.path.join, not shlex.join

For convenience, datetime.datetime is also exposed as dt, and a few of its members are exported directly:

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

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.2.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

stdlb-0.0.2-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file stdlb-0.0.2.tar.gz.

File metadata

  • Download URL: stdlb-0.0.2.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for stdlb-0.0.2.tar.gz
Algorithm Hash digest
SHA256 05699c625555f08e2124fa1b958604207bfb46ab735e57bf030d43587b159c21
MD5 b72e3ccb71f62bb66df2e034752e033e
BLAKE2b-256 6d7b8115a149182d54163518004ca58351f1c0ee5954ad1980a4b2a515d5ac49

See more details on using hashes here.

File details

Details for the file stdlb-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: stdlb-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for stdlb-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bb1584b141ded8c0b33258ef7de2692348f0c51b253920d2b42e13aaa03678da
MD5 f7acafd0e041d72a0de11f5b83513ea2
BLAKE2b-256 59ce0e41ef3d830220fdaa2d078ca42e5ec8f81f80181d1a5d1fdbc4232d1ffe

See more details on using hashes here.

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