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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: stdlb-0.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 1a852720146836dcc7cf15a8774afe1a822d7bbb1b00b9450f8ffdeb0799a4a3
MD5 116b8e6e93f9cd46dedce16d4fc7c354
BLAKE2b-256 8cab02f61f9a0ec2f776f728ab68d16c0b7512f1b6361a41bbb5e7e5bfe8ebd0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stdlb-0.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8e141777cc75d3360d51c773283ea17fcb0f5f80e7301f5e0d52f5f2fad9de83
MD5 857c67158875977566d2263e5d0a5b3f
BLAKE2b-256 de715b19ae5e298c41e08cccde4d5228c10acbe96e8b232a4bf55c3b2c79502e

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