Chapter 7: Standard Library and Tools¶
This chapter covers essential Python standard library modules and development tools, including collections, itertools, typing, datetime, json, logging, regex, debugging, and testing.
7.1 collections Module¶
7.2 itertools Module¶
- itertools Overview
- Infinite Iterators (count, cycle, repeat)
- chain and chain.from_iterable
- islice
- product
- permutations and combinations
- groupby
- starmap
- tee
- accumulate
- zip_longest
- compress and filterfalse
- takewhile and dropwhile
- itertools Recipes
7.3 typing Module¶
- typing Overview
- Basic Annotations (int, str, list)
- Optional and Union
- List[int] vs list[int]
- Callable and TypeAlias
- TypeVar and Generic
- TypeGuard and TypeNarrowing
- TYPE_CHECKING and Forward References
- Practical Type Hint Patterns
7.4 datetime Module¶
- datetime Overview
- date, time, datetime Objects
- timedelta Arithmetic
- Formatting (strftime) and Parsing (strptime)
- Timezone Handling (timezone, zoneinfo)
- calendar Module
- Practical Patterns
7.5 json Module¶
- json Overview
- json.dumps and json.loads
- json.dump and json.load (File I/O)
- Formatting and Pretty Printing
- Custom Encoders (JSONEncoder)
- Custom Decoders (object_hook)
- JSON and Python Type Mapping
7.6 logging Module¶
- logging Overview
- Log Levels
- Logger Objects
- Handlers (Stream, File, Rotating)
- Formatters
- Configuration (dictConfig, fileConfig)
- Logging Best Practices
7.7 Modules Deep Dive¶
- sys.path and Module Search
- Relative Imports
- Package Init Files
- Package Creation
- Command Line Arguments
7.8 os and sys Modules¶
- os Module Overview
- File System Operations (os)
- Environment Variables (os.environ)
- Process Management (os)
- os.path vs pathlib
- sys Module Overview
- sys.argv and sys.exit
- sys Runtime Information
7.9 Package Managers¶
7.10 Regular Expressions¶
- re Module Overview
- Pattern Syntax Basics
- Character Classes
- Quantifiers and Anchors
- Groups and Capturing
- search, match, findall
- sub and split
- Compiling Patterns
- Lookahead and Lookbehind
- Practical Examples