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(f"Python version: {version}\n")
print(f"Today: {dt.now()}")
data = {"key": "value"}
dumps(data) # json.dumps
Features:
-
🎯 Comprehensive coverage: 2127 symbols from 79+ stdlib modules (up from 841 symbols in v0.0.4)
-
🐍 Python 3.10-3.13 support: Automatically includes version-specific modules
-
⚡ Fast: Imports in ~57ms
-
🔒 Safe: Preserves all
__builtins__, resolves name collisions intelligently -
🧪 Well-tested: Snapshot testing tracks all exports to prevent regressions
Install
pip install stdlb
Coverage
stdlb now includes 79+ stdlib modules, including:
Core utilities: os, sys, pathlib, subprocess, tempfile, shutil, glob, fnmatch
Data structures & algorithms: collections, itertools, heapq, bisect, array, queue
Text processing: re, string, textwrap, difflib, unicodedata
Data formats: json, csv, configparser, pickle, base64, binascii
Math & numbers: math, cmath, decimal, fractions, statistics, random, secrets
Date & time: datetime, time, calendar, timeit
Functional programming: functools, operator, itertools
Type hints: typing, types, dataclasses, enum
Concurrency: threading, asyncio, subprocess, signal
Networking: socket, urllib, http, html, mimetypes
Cryptography: hashlib, hmac, secrets
Compression: zlib, zipfile
And more: logging, warnings, traceback, pprint, platform, locale, etc.
Version-specific modules
- Python 3.9+:
graphlib,zoneinfo - Python 3.11+:
tomllib
Platform-specific symbols
Some symbols vary by platform, particularly in socket, signal, and os:
- Socket constants:
AF_*,IPPROTO_*,SO_*, etc. (vary by OS) - Signal constants:
SIG*(vary by OS) - Clock constants:
CLOCK_*(vary by OS)
The library exports whatever is available on your platform. Snapshot tests are lenient about these platform-specific symbols.
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.
Import time is reasonable (~57ms) for the comprehensive coverage provided. See scripts/benchmark_import.py for detailed measurements.
Collision Resolution
__builtins vs. module members
stdlb avoids overwriting __builtins__ with conflicting module members, e.g.:
openvs.os.opencompilevs.re.compilepowvs.math.powcopyrightvs.sys.copyrightBlockingIOErrorvs.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
Path # pathlib.Path, not zipfile.Path
error # re.error, not zlib.error
compress # itertools.compress, not zlib.compress
repeat # itertools.repeat, not timeit.repeat
Use scripts/compare_versions.py to compare exports between versions and identify collisions.
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.
Development
This project uses uv for development.
# Install dependencies
uv sync
# Run tests
uv run pytest tests/ -v
# Test across multiple Python versions
for v in .venv/3.*/bin/python; do $v scripts/quick_test.py; done
# Regenerate __init__.py (if needed)
python scripts/generate_init.py > src/stdlb/__init__.py
# Update exports snapshot
python scripts/snapshot_exports.py
# Compare versions to check for regressions
python scripts/compare_versions.py v0.0.4 HEAD
Helper Scripts
Code Generation
scripts/discover_stdlib.py: Analyze the stdlib and identify useful modules to includescripts/generate_init.py: Generatesrc/stdlb/__init__.pyfrom configuration- Handles version-specific imports, module preservation, collision resolution
- Configuration in
VERSION_REQUIREMENTS,PRESERVE_MODULE,COLLISION_PREFERENCES
Testing & Quality Assurance
scripts/quick_test.py: Quick functionality test across Python versionsscripts/benchmark_import.py: Measure import time performancescripts/snapshot_exports.py: Generate JSON snapshot of all exported symbols- Output:
tests/exports_snapshot.json(2127 symbols tracked) - Used by
tests/test_exports_snapshot.pyfor regression detection
- Output:
scripts/compare_versions.py: Compare exports between git refs# Compare any two versions python scripts/compare_versions.py v0.0.4 v0.1.0 python scripts/compare_versions.py <old-ref> <new-ref> # Show only FQN changes (collisions) python scripts/compare_versions.py v0.0.4 HEAD 2>/dev/null | grep -A 50 "Changed FQN"
Metadata
Release files for stdlb 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| stdlb-0.1.1.tar.gz | 5.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| stdlb-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.3 kB
Release files / stdlb-0.1.1.tar.gz
| Download URL | stdlb-0.1.1.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
45dbebf9eefa5c4363d5e40e980ad86b25849561f0e33a788d3f7640413a677c
|
|
BLAKE2b-256 checksum How to use checksums |
7fe26efe231933a33bd9d1af2b6d0f3649f199ae797c3865159c55c509995da8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Release files / stdlb-0.1.1-py3-none-any.whl
| Download URL | stdlb-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
122b21f17ec10b20e4804898bf7e590607506182696822e698db2c6ea9b92125
|
|
BLAKE2b-256 checksum How to use checksums |
f0d9b8e183026e24b2911d674c8f12af06564e57d5e9e53a332140ad96517b48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Security for stdlb 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.