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
Collision Resolution
__builtins
vs. module members
stdlb
avoids overwriting __builtins__
with conflicting module members, e.g.:
open
vs.os.open
compile
vs.re.compile
pow
vs.math.pow
copyright
vs.sys.copyright
BlockingIOError
vs.io.BlockingIOError
test.ipynb
is executed as part of ci.yml
to verify there are no __builtins__
are unexpectedly shadowed.
Module/Members
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
Aliases
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
Built Distribution
File details
Details for the file stdlb-0.0.4.tar.gz
.
File metadata
- Download URL: stdlb-0.0.4.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f397ef335d15a7b2fe18693f15b738310a5c6c8b6cfdc80cc54ed9926dddc62 |
|
MD5 | 9735ad49554edada28798be3189d4ba3 |
|
BLAKE2b-256 | 1245ae96cab0805c1992812d40e86f555926cf426f61862c34777c3f54a41de9 |
File details
Details for the file stdlb-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: stdlb-0.0.4-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d268f17b7960270960f8f85be4fa3b003195313525c31f32192854ab63eafe2 |
|
MD5 | 5f28ddfb3d736abd9ff89e44512d18e9 |
|
BLAKE2b-256 | 44d78147edcba4f7d56c525f1a882c84e74586c35a6339a2354519284244492a |