Serious Python Black-belt advice on deployment, scalability, testing, and more
Book - 2019
"Offers experienced coders advice and tips for improving knowledge of Python coding language. Includes interviews with Python experts and covers a wide range of common topics, from scaling and testing code to designing APIs"--
Saved in:
- Subjects
- Published
-
San Francisco, CA :
No Starch Press, Inc
[2019]
- Language
- English
- Main Author
- Physical Description
- xvi, 218 pages ; 24 cm
- ISBN
- 9781593278786
- Acknowledgments
- Introduction
- Who Should Read This Book And Why
- About This Book
- 1. Starting Your Project
- Versions of Python
- Laying Out Your Project
- What to Do
- What Not to Do
- Version Numbering
- Coding Style and Automated Checks
- Tools to Catch Style Errors
- Tools to Catch Coding Errors
- Joshua Harlow on Python
- 2. Modules, Libraries, And Frameworks
- The Import System
- The sys Module
- Import Paths
- Custom Importers
- Meta Path Finders
- Useful Standard Libraries
- External Libraries
- The External Libraries Safety Checklist
- Protecting Your Code With an API Wrapper
- Package Installation: Getting More from pip
- Using and Choosing Frameworks
- Doug Hellmann, Python Core Developer, on Python Libraries
- 3. Documentation And Good API Practice
- Documenting with Sphinx
- Getting Started with Sphinx and Rest
- Sphinx Modules
- Writing a Sphinx Extension
- Managing Changes to YOUR APIs
- Numbering API Versions
- Documenting Your API Changes
- Marking Deprecated Functions with the warnings Module
- Summary
- Christophe de Vienne on Developing APIs
- 4. Handling Timestamps And Time Zones
- The Problem of Missing Time Zones
- Building Default datetime Objects
- Time Zone-Aware Timestamps with dateutil
- Serializing Time Zone-Aware datetime Objects
- Solving Ambiguous Times
- Summary
- 5. Distributing Your Software
- A Bit of setup.py History
- Packaging with setup.cfg
- The Wheel Format Distribution Standard
- Sharing Your Work with the World
- Entry Points
- Visualizing Entry Points
- Using Console Scripts
- Using Plugins and Drivers
- Summary
- Nick Coghlan on Packaging
- 6. Unit Testing
- The Basics of Testing
- Some Simple Tests
- Skipping Tests
- Running Particular Tests
- Running Tests in Parallel
- Creating Objects Used in Tests with Fixtures
- Running Test Scenarios
- Controlled Tests Using Mocking
- Revealing Untested Code with coverage
- Virtual Environments
- Setting Up a Virtual Environment
- Using virtualenv with tox
- Re-creating an Environment
- Using Different Python Versions
- Integrating Other Tests
- Testing Policy
- Robert Collins on Testing
- 7. Methods And Decorators
- Decorators and When to Use Them
- Creating Decorators
- Writing Decorators
- Stacking Decorators
- Writing Class Decorators
- How Methods Work in Python
- Static Methods
- Class Methods
- Abstract Methods
- Mixing Static, Class, and Abstract Methods
- Putting Implementations in Abstract Methods
- The Truth About super
- Summary
- 8. Functional Programming
- Creatinq Pure Functions
- Generators
- Creating a Generator
- Returning and Passing Values with yield
- Inspecting Generators
- List Comprehensions
- Functional Functions Functioning
- Applying Functions to Items with map()
- Filtering Lists with filter()
- Getting Indexes with enumerate()
- Sorting a List with sorted()
- Finding Items That Satisfy Conditions with any() and all()
- Combining Lists with zip()
- A Common Problem Solved
- Useful itertools Functions
- Summary
- 9. The Abstract Syntax Tree, HY, And Lisp-Like Attributes
- Looking at the AST
- Writing a Program Using the AST
- The AST Objects
- Walking Through an AST
- Extending flake8 with AST Checks
- Writing the Class
- Ignoring Irrelevant Code
- Checking for the Correct Decorator
- Looking for self
- A Quick Introduction to Hy
- Summary
- Paul Tagliamonte on the AST and Hy
- 10. Performances And Optimizations
- Data Structures
- Understanding Behavior Through Profiling
- cProfile
- Disassembling with the dis Module
- Defining Functions Efficiently
- Ordered Lists and bisect
- Namedtuple and Slots
- Memoization
- Faster Python With PyPy
- Achieving Zero Copy with the Buffer Protocol
- Summary
- Victor Stinner On Optimization
- 11. Scaling And Architecture
- Multithreading in Python and Its Limitations
- Multiprocessing vs. Multithreading
- Event-Driven Architecture
- Other Options and asyncio
- Service-Oriented Architecture
- Interprocess Communication with ZeroMQ
- Summary
- 12. Managing Relational Databases
- RDBMSs, ORMs, and When to Use Them
- Database Backends
- Streaming Data with Flask and PostgreSQL
- Writing the Data-Streaming Application
- Building the Application
- Dimitri Fontaine on Databases
- 13. Write Less, Code More
- Using six for Python 2 and 3 Support
- Strings And Unicode
- Handling Python Modules Moves
- The Modernize Module
- Using Python Like Lisp to Make a Single Dispatcher
- Creating Generic Methods In Lisp
- Generic Methods With Python
- Context Managers
- Less Boilerplate With attr
- Summary
- Index