Created
January 24, 2020 09:50
-
-
Save aib/ce5bb91ee6e006bcaaa4f438879bfd7b to your computer and use it in GitHub Desktop.
Python standard library breakdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import importlib | |
import inspect | |
import sys | |
MODULES = """\ | |
string | |
re | |
difflib | |
textwrap | |
unicodedata | |
stringprep | |
readline | |
rlcompleter | |
struct | |
codecs | |
datetime | |
calendar | |
collections | |
collections.abc | |
heapq | |
bisect | |
array | |
weakref | |
types | |
copy | |
pprint | |
reprlib | |
enum | |
numbers | |
math | |
cmath | |
decimal | |
fractions | |
random | |
statistics | |
itertools | |
functools | |
operator | |
pathlib | |
os.path | |
fileinput | |
stat | |
filecmp | |
tempfile | |
glob | |
fnmatch | |
linecache | |
shutil | |
pickle | |
copyreg | |
shelve | |
marshal | |
dbm | |
sqlite3 | |
zlib | |
gzip | |
bz2 | |
lzma | |
zipfile | |
tarfile | |
csv | |
configparser | |
netrc | |
xdrlib | |
plistlib | |
hashlib | |
hmac | |
secrets | |
os | |
io | |
time | |
argparse | |
getopt | |
logging | |
logging.config | |
logging.handlers | |
getpass | |
curses | |
curses.textpad | |
curses.ascii | |
curses.panel | |
platform | |
errno | |
ctypes | |
threading | |
multiprocessing | |
concurrent.futures | |
subprocess | |
sched | |
queue | |
_thread | |
_dummy_thread | |
dummy_threading | |
asyncio | |
socket | |
ssl | |
select | |
selectors | |
asyncore | |
asynchat | |
signal | |
mmap | |
json | |
mailcap | |
mailbox | |
mimetypes | |
base64 | |
binhex | |
binascii | |
quopri | |
uu | |
html | |
html.parser | |
html.entities | |
xml.etree.ElementTree | |
xml.dom | |
xml.dom.minidom | |
xml.dom.pulldom | |
xml.sax | |
xml.sax.handler | |
xml.sax.saxutils | |
xml.sax.xmlreader | |
xml.parsers.expat | |
webbrowser | |
cgi | |
cgitb | |
wsgiref | |
urllib | |
urllib.request | |
urllib.response | |
urllib.parse | |
urllib.error | |
urllib.robotparser | |
http | |
http.client | |
ftplib | |
poplib | |
imaplib | |
nntplib | |
smtplib | |
smtpd | |
telnetlib | |
uuid | |
socketserver | |
http.server | |
http.cookies | |
http.cookiejar | |
xmlrpc | |
xmlrpc.client | |
xmlrpc.server | |
ipaddress | |
audioop | |
aifc | |
sunau | |
wave | |
chunk | |
colorsys | |
imghdr | |
sndhdr | |
ossaudiodev | |
gettext | |
locale | |
turtle | |
cmd | |
shlex | |
tkinter | |
tkinter.ttk | |
tkinter.tix | |
tkinter.scrolledtext | |
typing | |
pydoc | |
doctest | |
unittest | |
unittest.mock | |
unittest.mock | |
test | |
test.support | |
test.support.script_helper | |
bdb | |
faulthandler | |
pdb | |
timeit | |
trace | |
tracemalloc | |
distutils | |
venv | |
zipapp | |
sys | |
sysconfig | |
builtins | |
__main__ | |
warnings | |
dataclasses | |
contextlib | |
abc | |
atexit | |
traceback | |
__future__ | |
gc | |
inspect | |
site | |
code | |
codeop | |
zipimport | |
pkgutil | |
modulefinder | |
runpy | |
importlib | |
parser | |
ast | |
symtable | |
symbol | |
token | |
keyword | |
tokenize | |
tabnanny | |
pyclbr | |
py_compile | |
compileall | |
dis | |
pickletools | |
formatter | |
posix | |
pwd | |
spwd | |
grp | |
crypt | |
termios | |
tty | |
pty | |
fcntl | |
pipes | |
resource | |
nis | |
syslog | |
optparse | |
imp | |
""".splitlines() | |
def gettype(x): | |
if inspect.ismodule(x): return "module" | |
if inspect.isclass(x): return "class" | |
if inspect.isroutine(x): return "function" | |
if isinstance(x, type): return "type" | |
if x is None or x is ...: return "primitive" | |
if isinstance(x, (str, bytes)): return "primitive" | |
if isinstance(x, (float, int, complex)): return "primitive" | |
if isinstance(x, (list, dict, tuple, set, frozenset)): return "primitive" | |
return "other" | |
types = collections.defaultdict(lambda: 0) | |
processed_modules = [] | |
def process_module(module): | |
if module in processed_modules: | |
return | |
processed_modules.append(module) | |
for a in dir(module): | |
attr = getattr(module, a) | |
types[gettype(attr)] += 1 | |
if inspect.ismodule(attr): | |
process_module(attr) | |
for m in MODULES: | |
module = importlib.import_module(m) | |
process_module(module) | |
for typename, count in sorted(types.items(), key=lambda kv: kv[1], reverse=True): | |
print(count, typename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment