Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Daniel Arbuckle???s Mastering Python

You're reading from   Daniel Arbuckle???s Mastering Python Build powerful Python applications

Arrow left icon
Product type Paperback
Published in Jun 2017
Publisher Packt
ISBN-13 9781787283695
Length 274 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Daniel Arbuckle Daniel Arbuckle
Author Profile Icon Daniel Arbuckle
Daniel Arbuckle
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Python Primer 2. Setting Up FREE CHAPTER 3. Making a Package 4. Basic Best Practices 5. Making a Command-Line Utility 6. Parallel Processing 7. Coroutines and Asynchronous I/O 8. Metaprogramming 9. Unit Testing 10. Reactive Programming 11. Microservices 12. Extension Modules and Compiled Code

The standard library

The library of code that comes pre-installed with Python is extensive, so we're not going into the details. The goal here is to come away with an understanding of the breadth of quality tools we have available, so if we need them in the future then we know where to look. Thus, we're going to just briefly touch on many useful things. You can find the official documentation on the standard library at https://docs.python.org/3/library/index.html.

Different types of packages

The index page contains a list of the different packages available to you in Python's standard library. Let's briefly run through them in order.

First of all, there is the Collections package, which contains even more data structures: https://docs.python.org/3/library/collections.html.

The Collections package contains the defaultdict class that we spoke about in the previous section. The Collections package also contains an OrderedDict parameter that remembers the order in which the items were inserted and gives them back in the same order when we iterate over it. A deque class is a variation on tuples that uses names to access the element and a PseudoDict parameter that provides a composite view of several other dictionaries.

There are a few other data structures in there as well. One common data structure missing from the collections package is a PriorityQueue parameter, but that's just because it has its own package called heapq:

https://docs.python.org/3/library/heapq.html

Python's PriorityQueue operations are implemented as functions that work with built-in lists to add and remove items according to the heap property.

Storing and retrieving data is an extremely common need for programs and the pickle package makes it easy:

https://docs.python.org/3/library/pickle.html

Inside the pickle package are classes and functions that facilitate transforming arbitrary Python data into a sequence of bytes that can be stored in a file, sent across the network, or whatever you need. The pickle package also has the tools to reverse the process and transform those bytes back into fully-fledged Python data objects.

Also, in the vein of storing data, the sqlite3 package provides complete access to the SQLite database manager, allowing us to take advantage of a complete transactional relational database:

https://docs.python.org/3/library/sqlite.html

Third-party packages to access other database systems follow pretty much the same interface, so it's easy to make the switch to a different database later, if needed.

The json package is also relevant to data handling. It parses or generates the de facto standard Internet Data Exchange (IDX) format:

https://docs.python.org/3/library/json.html

The json package is smart, so it handles JSON (JavaScript Object Notation) objects, arrays, strings, numbers, null values, and so on, in a sensible way.

Mapping them onto the proper Python datatypes, the base64 package encodes bytes into base64, or decodes base64 into bytes:

https://docs.python.org/3/library/base64.html

There are several other similar packages for binhex, uu code, and so on, as well.

The html and xml packages provide all sorts of utilities for dealing with the major internet markup languages, including parsers and the document object model:

https://docs.python.org/3/library/html.html

The urllib package provides us with convenient ways to retrieve data from URLs or to send data to them:

https://docs.python.org/3/library/urllib.html

In particular, the urllib.request.url open function is extremely useful.

The itertools and functools packages provide an assortment of utilities having to do with functional programming paradigms:

https://docs.python.org/3/library/itertools.html

In particular, the functools package allows for us to create partially applied functions and the itertools package lets us concatenate iterators.

The enum package contains support for creating and using named enumerations:

https://docs.python.org/3/library/enum.html

Each enumeration is a distinct data type, like a class.

The pathlib package contains classes and functions that provide a cross-platform abstraction of file and file path operations:

https://docs.python.org/3/library/pathlib.html

The inspect package is interesting and quite useful. It provides us with functions that can be used to gather information about data objects, particularly about functions and classes. If we want to know the names of functions, parameters, or we want to access an object's documentation, or any number of things along those lines, the inspect package will get us there:

https://docs.python.org/3/library/inspect.html

The packages we just looked at are by no means the complete list of what's available in the standard library, but hopefully they give some idea of the depth and breadth of what we get just by installing Python. Taking a look through the library documentation on https://www.python.org/ is highly recommended for people who want to get the most out of Python. There are some particularly useful packages that we didn't mention at all. That's because there are whole other sections devoted to them later in the book.

So, that brings us to the end of our overview of the standard library.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image