Skip to content

Commit 9995d69

Browse files
author
Sylvain MARIE
committed
Finally added doc. Fixed #21
1 parent 40b37a9 commit 9995d69

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

docs/usage.rst

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
Usage (Or: How To Get The List of Libraries)
2-
============================================
1+
Usage
2+
=====
33

4-
The primary function that you'll care about in this package is ``stdlib_list.stdlib_list``.
4+
Getting The List of Libraries
5+
-----------------------------
6+
7+
``stdlib_list.stdlib_list`` returns the list of libraries in stdlib for any given version (by default, current python version).
58

69
In particular:
710

@@ -15,5 +18,30 @@ In particular:
1518
Out[3]: ['__future__', '__main__', '_dummy_thread', '_thread', 'abc', 'aifc']
1619

1720

21+
Checking if a Module is part of stdlib
22+
--------------------------------------
23+
24+
``stdlib_list.in_stdlib`` provides an efficient way to check if a module name is part of stdlib.
25+
It relies on ``@lru_cache`` to cache the stdlib list and query results for similar calls. Therefore it is much more efficient than ``module_name in stdlib_list()`` especially if you wish to perform multiple checks.
26+
27+
In particular:
28+
29+
::
30+
31+
>>> from stdlib_list import in_stdlib
32+
>>> in_stdlib('zipimport') # built in
33+
True
34+
>>> in_stdlib('math') # C-API stdlib module, but linked as extension (on my machine)
35+
True
36+
>>> in_stdlib('numpy') # C-API extension, not stdlib
37+
False
38+
>>> in_stdlib('sys') # built-in (and special)
39+
True
40+
>>> in_stdlib('os') # Python code in stdlib
41+
True
42+
>>> in_stdlib('requests') # Python code, not stdlib
43+
False
44+
45+
1846
.. automodule:: stdlib_list
19-
:members: stdlib_list
47+
:members: stdlib_list, in_stdlib

0 commit comments

Comments
 (0)