Serious Python

Book description

Sharpen your Python skills as you dive deep into the Python programming language with Serious Python. You’ll cover a range of advanced topics like multithreading and memorization, get advice from experts on things like designing APIs and dealing with databases, and learn Python internals to help you gain a deeper understanding of the language itself. Written for developers and experienced programmers, Serious Python brings together over 15 years of Python experience to teach you how to avoid common mistakes, write code more efficiently, and build better programs in less time.

As you make your way through the book’s extensive tutorials, you’ll learn how to start a project and tackle topics like versioning, layouts, coding style, and automated checks. You’ll learn how to package your software for distribution, optimize performance, use the right data structures, define functions efficiently, pick the right libraries, build future-proof programs, and optimize your programs down to the bytecode.

You’ll also learn how to:

•Make and use effective decorators and methods, including abstract, static, and class methods

•Employ Python for functional programming using generators, pure functions, and functional functions

•Extend flake8 to work with the abstract syntax tree (AST) to introduce more sophisticated automatic checks into your programs

•Apply dynamic performance analysis to identify bottlenecks in your code

•Work with relational databases and effectively manage and stream data with PostgreSQL

If you’ve been looking for a way to take your Python skills from good to great, Serious Python will help you get there. Learn from the experts and get seriously good at Python with Serious Python!

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. About the Author
  5. About the Technical Reviewer
  6. BRIEF CONTENTS
  7. CONTENTS IN DETAIL
  8. ACKNOWLEDGMENTS
  9. INTRODUCTION
    1. Who Should Read This Book and Why
    2. About This Book
  10. 1 STARTING YOUR PROJECT
    1. Versions of Python
    2. Laying Out Your Project
    3. Version Numbering
    4. Coding Style and Automated Checks
    5. Joshua Harlow on Python
  11. 2 MODULES, LIBRARIES, AND FRAMEWORKS
    1. The Import System
    2. Useful Standard Libraries
    3. External Libraries
    4. Package Installation: Getting More from pip
    5. Using and Choosing Frameworks
    6. Doug Hellmann, Python Core Developer, on Python Libraries
  12. 3 DOCUMENTATION AND GOOD API PRACTICE
    1. Documenting with Sphinx
    2. Summary
    3. Christophe de Vienne on Developing APIs
  13. 4 HANDLING TIMESTAMPS AND TIME ZONES
    1. The Problem of Missing Time Zones
    2. Building Default datetime Objects
    3. Time Zone–Aware Timestamps with dateutil
    4. Serializing Time Zone–Aware datetime Objects
    5. Solving Ambiguous Times
    6. Summary
  14. 5 DISTRIBUTING YOUR SOFTWARE
    1. A Bit of setup.py History
    2. Packaging with setup.cfg
    3. The Wheel Format Distribution Standard
    4. Sharing Your Work with the World
    5. Entry Points
    6. Summary
    7. Nick Coghlan on Packaging
  15. 6 UNIT TESTING
    1. The Basics of Testing
    2. Virtual Environments
    3. Testing Policy
    4. Robert Collins on Testing
  16. 7 METHODS AND DECORATORS
    1. Decorators and When to Use Them
    2. How Methods Work in Python
    3. Static Methods
    4. Class Methods
    5. Abstract Methods
    6. Mixing Static, Class, and Abstract Methods
    7. Summary
  17. 8 FUNCTIONAL PROGRAMMING
    1. Creating Pure Functions
    2. Generators
    3. List Comprehensions
    4. Functional Functions Functioning
    5. Summary
  18. 9 THE ABSTRACT SYNTAX TREE, HY, AND LISP-LIKE ATTRIBUTES
    1. Looking at the AST
    2. Extending flake8 with AST Checks
    3. A Quick Introduction to Hy
    4. Summary
    5. Paul Tagliamonte on the AST and Hy
  19. 10 PERFORMANCES AND OPTIMIZATIONS
    1. Data Structures
    2. Understanding Behavior Through Profiling
    3. Defining Functions Efficiently
    4. Ordered Lists and bisect
    5. namedtuple and Slots
    6. Memoization
    7. Faster Python with PyPy
    8. Achieving Zero Copy with the Buffer Protocol
    9. Summary
    10. Victor Stinner on Optimization
  20. 11 SCALING AND ARCHITECTURE
    1. Multithreading in Python and Its Limitations
    2. Multiprocessing vs. Multithreading
    3. Event-Driven Architecture
    4. Other Options and asyncio
    5. Service-Oriented Architecture
    6. Interprocess Communication with ZeroMQ
    7. Summary
  21. 12 MANAGING RELATIONAL DATABASES
    1. RDBMSs, ORMs, and When to Use Them
    2. Database Backends
    3. Streaming Data with Flask and PostgreSQL
    4. Dimitri Fontaine on Databases
  22. 13 WRITE LESS, CODE MORE
    1. Using six for Python 2 and 3 Support
    2. Using Python Like Lisp to Make a Single Dispatcher
    3. Context Managers
    4. Less Boilerplate with attr
    5. Summary
  23. INDEX

Product information

  • Title: Serious Python
  • Author(s): Julien Danjou
  • Release date: December 2018
  • Publisher(s): No Starch Press
  • ISBN: 9781593278786