Python @ DjangoSpin

53 Handy Standard Library Modules

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 3 minutes

Handy Standard Library Modules in Python

Handy Standard Library Modules in Python

Python comes with over 200 standard library modules. In the following list, I provide to you the most commonly used ones in Python 3. Each of these modules can be imported using the import statement. Each module links to official Python documentation citing examples to work with it.

To view the helptext along with objects contained in the modules, execute help(module_name).

S. No. Module Name Description
1. sys Exposes objects and functions used by the interactive interpreter.
2. os Enables the user to use the operating system properties to ensure cross-platform compatibility.
3. re Provides the ever so powerful Regular Expressions, as found in Perl programming language.
4. pprint Enables to prettify the output while printing arbitrary data structures.
5. itertools Provides a set of functions to create various iterators.
6. functools Provides a set of useful functions and decorators to work with other functions.
7. copy Provides functions to copy objects properly in Python.
8. datetime Helps manipulate date and time.
9. tkinter Python's official GUI Toolkit.
10. calendar Enables to print and work with calendars.
11. time Provides time-related functions.
12. random Helps generate random numbers and choose randomly from a sequence.
13. argparse Helps parse command-line options, arguments and sub-commands.
14. glob Helps find pathnames matching a given pattern, like in Unix.
15. inspect Provides information on classes, functions and other live objects.
16. unittest Python's library for unit testing.
17. timeit Helps measure execution time of small code snippets.
18. webbrowser Provides interfaces for controlling Web Browsers.
19. math Functions for mathematical operations.
20. collections Specialized data structures such as namedtuple, defaultdict, deque etc.
21. csv For manipulating Comma Separated Values files.
22. sqlite3 Interface to SQLite databases, a lightweight database for internal storage.
23. json Enables encoding & decoding to/from JavaScript Object Notation, most commonly used data interchange format.
24. shelve Provides a persistent dictionary-like object for serialization in Python.
25. pickle Enables to serialize and de-serialize objects using byte streams.
26. io Offers tools for working with input/output streams.
27. shutil Provides high-level operations on files.
28. trace To trace/track execution of statements/programs.
29. traceback Helps to print stack traces of programs willingly, like in the Interactive Interpreter.
30. doctest Executes tests written in docstrings.
31. pydoc Generates documentation from modules. Serves as online help system by being invoked by the builtin help() function.
32. pdb Provides an interactive source code debugger for programs.
33. logging Implements an event-logging system for applications.
34. tempfile Generate temporary files and directories, which are deleted automatically once the context finished.
35. array Python's implementation of the array data type.
36. cmd Enables the user to write command-line oriented interpreters using a simple framework.
37. heapq Python's implementation of the heap queue algorithm, or the priority queue algorithm.
38. threading Python module to implement multi-threading programming.
39. fnmatch Filename matching with shell style wildcards.
40. gc Provides access to the garbage collector.
41. decimal Provides support for fixed point and floating point arithmetic with familiar rules and avoid the tricky representation issues associated with binary floating point.
42. statistics Provides functions for calculating statistics of data, such as averages, standard deviation, variance etc.
43. gzip Enables the user to compress and decompress files.
44. queue Provides multi-producer, multi-consumer queues for use in threaded programming.
45. abc Enables the user to define Abstract Classes in Python.
46. urlib.parse Extract different parts of a URL.
47. urllib.request Open URLs using Python.
48. smtplib Send e-mails with an SMTP protocol client.
49. getpass Have the user input password securely.
50. socket Provides access to sockets, building blocks of network programming.
51. wsgiref Provides functions for working with Web Server Gateway Interface environments
52. turtle A popular graphics library in Python.
53. contextlib Provides utilities that can be used with the with statement.

That's it for this one. If you think we missed any useful standard library module, let us know in the comments below.

See also: 60+ Handy Third-Party Modules

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply