Skip to content

Commit fe886dd

Browse files
committed
0.0.1
1 parent 8e9eec6 commit fe886dd

File tree

11 files changed

+1495
-7
lines changed

11 files changed

+1495
-7
lines changed

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
recursive-include *.txt
1+
recursive-include stdlib_list/lists *.txt
22
include README.rst

README.rst

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,95 @@
11
Python Standard Library List
22
----------------------------
33

4-
This package includes lists of all of the standard libraries for versions of Python ``>=`` 2.6, along with the code for scraping the official Python docs to get said lists.
4+
This package includes lists of all of the standard libraries for Python 2.6, 2.7, 3.2, 3.3, and 3.4, along with the code for scraping the official Python docs to get said lists.
5+
6+
Listing the modules in the standard library? Wait, why on Earth would you care about that?!
7+
===========================================================================================
8+
9+
Because knowing whether or not a module is part of the standard library will come in handy in `a project of mine <https://github.com/jackmaney/pypt>`_. `And I'm not the only one <http://stackoverflow.com/questions/6463918/how-can-i-get-a-list-of-all-the-python-standard-library-modules>`_ who would find this useful. Or, the TL;DR answer is that it's handy in situations when you're analyzing Python code and would like to find module dependencies.
10+
11+
After googling for a way to generate a list of Python standard libraries (and looking through the answers to the previously-linked Stack Overflow question), I decided that I didn't like the existing solutions.
12+
13+
So, I decided to brute force it a bit, by putting together a scraper for the TOC of the standard library page of the official Python docs (eg `here is the page for Python 2.7 <https://docs.python.org/2/library/index.html>`_).
14+
15+
Usage
16+
=====
17+
18+
The only argument you need to worry about specifying is a (major and minor) version number:
19+
20+
::
21+
>>> from stdlib_list import short_versions
22+
>>> short_versions
23+
['2.6', '2.7', '3.2', '3.3', '3.4']
24+
25+
Or, if you prefer, an exact version of one of the standard library pages that I scraped:
26+
27+
::
28+
29+
>>> from stdlib_list import long_versions
30+
>>> long_versions
31+
['2.6.9', '2.7.9', '3.2.6', '3.3.6', '3.4.3']
32+
33+
With that in mind, here's how you can grab a list of standard libraries:
34+
35+
::
36+
>>> from stdlib_list import stdlib_list
37+
>>> libraries = stdlib_list("2.7")
38+
>>> libraries[:10]
39+
['AL', 'BaseHTTPServer', 'Bastion', 'CGIHTTPServer', 'ColorPicker', 'ConfigParser', 'Cookie', 'DEVICE', 'DocXMLRPCServer', 'EasyDialogs']
40+
41+
Installation
42+
============
43+
44+
The easy way is via ``pip``:
45+
46+
::
47+
pip install stdlib_list
48+
49+
The hard way is to clone this repository, go into the directory into which you cloned this repo, and do a
50+
51+
::
52+
python setup.py install
53+
54+
55+
Caveats
56+
=======
57+
58+
* No attempt was made to cull deprecated libraries. I just scraped the standard library page for the relevant version.
59+
60+
* For the sake of completion, if ``A.B`` is in the list, I also threw in ``A`` (eg, you'll find ``xml``, ``xml.etree``, and ``xml.etree.ElementTree`` in the list, even though ``xml`` isn't specifically listed in the TOC).
61+
62+
The Scraper
63+
===========
64+
65+
You shouldn't need to fiddle around with the scraper, but in case you want to (or in case the Python Software Foundation decides to change the page layout of the standard library TOC page), just do:
66+
67+
::
68+
from stdlib_list import scraper
69+
scraper.scrape("2.7") # Scrape for 2.7 only (for debugging, mainly)
70+
scraper.scrape() # Scrape for all versions listed above.
71+
72+
LICENSE
73+
=======
74+
75+
The MIT License (MIT)
76+
77+
Copyright (c) 2015 Jack Maney
78+
79+
Permission is hereby granted, free of charge, to any person obtaining a copy
80+
of this software and associated documentation files (the "Software"), to deal
81+
in the Software without restriction, including without limitation the rights
82+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
83+
copies of the Software, and to permit persons to whom the Software is
84+
furnished to do so, subject to the following conditions:
85+
86+
The above copyright notice and this permission notice shall be included in all
87+
copies or substantial portions of the Software.
88+
89+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
90+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
91+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
92+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
93+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
94+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
95+
SOFTWARE.

setup.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import setuptools
1+
import setuptools
2+
from stdlib_list import __version__
23

34

45
try:
@@ -14,13 +15,15 @@
1415

1516

1617
setuptools.setup(
17-
name='python-stdlib-list',
18+
name='stdlib-list',
1819
license='MIT',
1920
author='Jack Maney',
2021
author_email='[email protected]',
2122
url='https://github.com/jackmaney/python-stdlib-list',
22-
version='0.0.0',
23+
version=__version__,
2324
install_requires=requirements,
24-
description='Scraping the Python Docs for the names of all the standard libraries.',
25-
long_description=long_description
25+
description='A list of Python Standard Libraries (2.6-7, 3.2-4).',
26+
long_description=long_description,
27+
include_package_data=True,
28+
packages=setuptools.find_packages()
2629
)

stdlib_list/__init__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from _version import __version__
2+
3+
import os
4+
5+
6+
long_versions = ["2.6.9", "2.7.9", "3.2.6", "3.3.6", "3.4.3"]
7+
8+
short_versions = [".".join(x.split(".")[:2]) for x in long_versions]
9+
10+
base_dir = os.path.dirname(os.path.realpath(__file__))
11+
data_dir = os.path.join(base_dir, "lists")
12+
13+
14+
def get_canonical_version(version):
15+
16+
if version in long_versions:
17+
version = ".".join(version.split(".")[:2])
18+
elif version not in short_versions:
19+
raise ValueError("No such version: {}".format(version))
20+
21+
return version
22+
23+
24+
def stdlib_list(version):
25+
26+
version = get_canonical_version(version)
27+
28+
lib_file = os.path.join(data_dir, "{}.txt".format(version))
29+
30+
with open(lib_file) as f:
31+
result = [x.strip() for x in f.readlines()]
32+
33+
return result
34+
35+
import scraper

stdlib_list/_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.0.1"

0 commit comments

Comments
 (0)