Modern Python Standard Library Cookbook

Book description

Build optimized applications in Python by smartly implementing the standard library

Key Features

  • Strategic recipes for effective application development in Python
  • Techniques to create GUIs and implement security through cryptography
  • Best practices for developing readily scalable, production-ready applications

Book Description

The Python 3 Standard Library is a vast array of modules that you can use for developing various kinds of applications. It contains an exhaustive list of libraries, and this book will help you choose the best one to address specific programming problems in Python.

The Modern Python Standard Library Cookbook begins with recipes on containers and data structures and guides you in performing effective text management in Python. You will find Python recipes for command-line operations, networking, filesystems and directories, and concurrent execution. You will learn about Python security essentials in Python and get to grips with various development tools for debugging, benchmarking, inspection, error reporting, and tracing. The book includes recipes to help you create graphical user interfaces for your application. You will learn to work with multimedia components and perform mathematical operations on date and time. The recipes will also show you how to deploy different searching and sorting algorithms on your data.

By the end of the book, you will have acquired the skills needed to write clean code in Python and develop applications that meet your needs.

What you will learn

  • Store multiple values per key in associative containers
  • Create interactive character-based user interfaces
  • Work with native time and display data for your time zone
  • Read/write SGML family languages, both as a SAX and DOM parser to meet file sizes and other requirements
  • Group equivalent items using itertools and sorted features together
  • Use partials to create unary functions out of multi-argument functions
  • Implement hashing algorithms to store passwords in a safe way

Who this book is for

If you are a developer who wants to write highly responsive, manageable, scalable, and resilient code in Python, this book is for you. Prior programming knowledge in Python will help you make the most out of the book.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Modern Python Standard Library Cookbook  
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Get in touch
      1. Reviews
  6. Containers and Data Structures
    1. Introduction
    2. Counting frequencies
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Dictionary with fallback
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Unpacking multiple keyword arguments
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Ordered dictionaries
      1. How to do it...
      2. How it works...
      3. There's more...
    6. MultiDict
      1. How to do it...
      2. How it works...
      3. There's more...
    7. Prioritizing entries
      1. How to do it...
      2. How it works...
      3. There's more...
    8. Bunch
      1. How to do it...
      2. How it works...
      3. There's more...
    9. Enumerations
      1. How to do it...
      2. How it works...
      3. There's more...
  7. Text Management
    1. Introduction
    2. Pattern matching
      1. How to do it...
      2. There's more...
    3. Text similarity
      1. How to do it...
      2. There's more...
    4. Text suggestion
      1. How to do it...
    5. Templating
      1. How to do it...
      2. How it works...
      3. There's more...
    6. Splitting strings and preserving spaces
      1. How to do it...
      2. How it works...
    7. Cleanup text
      1. How to do it...
      2. How it works...
    8. Normalizing text
      1. How to do it...
      2. How it works...
    9. Aligning text
      1. How to do it...
      2. How it works...
  8. Command Line
    1. Introduction
    2. Basic logging
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Logging to file
      1. How to do it...
      2. How it works...
    4. Logging to Syslog
      1. Getting ready
      2. How to do it...
      3. There's more...
    5. Parsing arguments
      1. How to do it...
      2. How it works...
      3. There's more...
    6. Interactive shells
      1. How to do it...
      2. How it works...
    7. Sizing terminal text
      1. How to do it...
      2. How it works...
    8. Running system commands
      1. How to do it...
      2. How it works...
      3. There's more...
    9. Progress bar
      1. How to do it...
      2. How it works...
    10. Message boxes
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Input box
      1. Getting ready
      2. How to do it...
      3. How it works...
  9. Filesystem and Directories
    1. Introduction
    2. Traversing folders
      1. How to do it...
      2. How it works...
    3. Working with paths
      1. How to do it...
      2. There's more...
    4. Expanding filenames
      1. How to do it...
    5. Getting file information
      1. How to do it...
    6. Named temporary files
      1. How to do it...
    7. Memory and disk buffer
      1. How to do it...
      2. How it works...
    8. Managing filename encoding
      1. How to do it...
      2. How it works...
    9. Copying a directory
      1. How to do it...
      2. How it works...
    10. Safely replacing file's content
      1. How to do it...
      2. How it works...
  10. Date and Time
    1. Introduction
    2. Time-zone-aware datetime
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Parsing dates
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Saving dates
      1. How to do it...
      2. How it works...
    5. From timestamps to datetimes
      1. How to do it...
      2. There's more...
    6. Displaying dates in user format
      1. How to do it...
      2. How it works...
      3. There's more...
    7. Going to tomorrow
      1. How to do it...
      2. How it works...
    8. Going to next month
      1. How to do it...
      2. How it works...
    9. Weekdays
      1. How to do it...
      2. How it works...
    10. Workdays
      1. How to do it...
      2. How it works...
    11. Combining dates and times
      1. How to do it...
      2. There's more...
  11. Read/Write Data
    1. Introduction
    2. Reading and writing text data
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Reading lines of text
      1. How to do it...
      2. How it works...
    4. Reading and writing binary data
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Zipping a directory
      1. How to do it...
      2. How it works...
    6. Pickling and shelving
      1. How to do it...
      2. How it works...
      3. There's more...
    7. Reading configuration files
      1. How to do it...
      2. How it works...
      3. There's more...
    8. Writing XML/HTML content
      1. How to do it...
      2. How it works...
      3. There's more...
    9. Reading XML/HTML content
      1. How to do it...
      2. How it works...
      3. There's more...
    10. Reading and writing CSV
      1. How to do it...
      2. There's more...
    11. Reading/writing a database
      1. How to do it...
      2. How it works...
      3. There's more...
  12. Algorithms
    1. Introduction
    2. Searching, sorting, filtering
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Getting the nth element of any iterable
      1. How to do it...
      2. How it works...
    4. Grouping similar items
      1. How to do it...
      2. How it works...
    5. Zipping
      1. How to do it...
      2. How it works...
    6. Flattening a list of lists
      1. How to do it...
      2. How it works...
      3. There's more...
    7. Producing permutations and combinations
      1. How to do it...
    8. Accumulating and reducing
      1. How to do it...
      2. There's more...
    9. Memoizing
      1. How to do it...
      2. How it works...
    10. Operators to functions
      1. How to do it...
      2. How it works...
    11. Partials
      1. How to do it...
      2. How it works...
    12. Generic functions
      1. How to do it...
      2. How it works...
    13. Proper decoration
      1. How to do it...
      2. There's more...
    14. Context managers
      1. How to do it...
    15. Applying variable context managers
      1. How to do it...
  13. Cryptography
    1. Introduction
    2. Asking for passwords
      1. How to do it...
      2. How it works...
    3. Hashing passwords
      1. How to do it...
      2. How it works...
    4. Verifying a file's integrity
      1. How to do it...
      2. How it works...
    5. Verifying a message's integrity
      1. How to do it...
      2. How it works...
  14. Concurrency
    1. Introduction
    2. ThreadPools
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Coroutines
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Processes
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Futures
      1. How to do it...
      2. How it works...
      3. There's more...
    6. Scheduled tasks
      1. How to do it...
      2. How it works...
    7. Sharing data between processes
      1. How to do it...
      2. How it works...
      3. There's more...
  15. Networking
    1. Introduction
    2. Sending emails
      1. How to do it...
      2. How it works...
    3. Fetching emails
      1. How to do it...
      2. How it works...
      3. There's more...
    4. FTP
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Sockets
      1. How to do it...
      2. How it works...
    6. AsyncIO
      1. How to do it...
      2. How it works...
    7. Remote procedure calls
      1. How to do it...
      2. How it works...
      3. There's more...
  16. Web Development
    1. Introduction
    2. Treating JSON
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Parsing URLs
      1. How to do it...
      2. There's more...
    4. Consuming HTTP
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Submitting forms to HTTP
      1. How to do it...
      2. How it works...
      3. There's more...
    6. Building HTML
      1. How to do it...
      2. How it works...
    7. Serving HTTP
      1. How to do it...
      2. How it works...
      3. There's more...
    8. Serving static files
      1. How to do it...
      2. How it works...
      3. There's more...
    9. Errors in web applications
      1. How to do it...
      2. How it works...
      3. There's more...
    10. Handling forms and files
      1. How to do it...
      2. How it works...
    11. REST API
      1. How to do it...
      2. How it works...
    12. Handling cookies
      1. How to do it...
      2. How it works...
      3. There's more...
  17. Multimedia
    1. Introduction
    2. Determining the type of a file
      1. How to do it...
      2. How it works...
    3. Detecting image types
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Detecting image sizes
      1. How to do it...
      2. How it works...
    5. Playing audio/video/images
      1. How to do it...
      2. How it works...
  18. Graphical User Interfaces
    1. Introduction
    2. Alerts
      1. How to do it...
      2. How it works...
    3. Dialog boxes
      1. How to do it...
      2. How it works...
    4. ProgressBar dialog
      1. How to do it...
      2. How it works...
    5. Lists
      1. How to do it...
      2. How it works...
    6. Menus
      1. How to do it...
      2. How it works...
  19. Development Tools
    1. Introduction
    2. Debugging
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Testing
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Mocking
      1. How it works...
      2. How it works...
      3. There's more...
    5. Reporting errors in production
      1. How to do it...
      2. How it works...
    6. Benchmarking
      1. How to do it...
      2. There's more...
    7. Inspection
      1. How to do it...
      2. How it works...
      3. There's more...
    8. Code evaluation
      1. How to do it...
    9. Tracing code
      1. How to do it...
      2. How it works...
      3. There's more...
    10. Profiling
      1. How to do it...
      2. How it works...
  20. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Modern Python Standard Library Cookbook
  • Author(s): Alessandro Molina
  • Release date: August 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788830829