Python in Practice
The Python that shows up in real codebases: environments and packaging, type hints, generators and context managers, decorators, testing and mocking, logging, dates, HTTP, configuration and profiling. Written for someone who can already write Python and now has to maintain it.
Start courseWhat you will cover
- Virtual Environments and Dependency ManagementWhy installing packages globally eventually breaks something, what an environment actually is, and how lockfiles turn 'works on my machine' into a reproducible install.30 min
- Packaging Your Projectpyproject.toml, the src layout, editable installs and console entry points — turning a folder of scripts into something that can be installed, imported and shipped.30 min
- Type Hints That Earn Their KeepAnnotations a checker can actually use, gradual typing in an untyped codebase, Optional and unions done properly, and the hints that add noise without adding safety.30 min
- Dataclasses and Modelling DataReplacing dictionaries-as-records with types that describe themselves. dataclass, frozen instances, post-init validation, and choosing between NamedTuple, TypedDict and a validation library.30 min
- Errors as DesignException hierarchies that let callers catch the right thing, chaining so the original cause survives, and deciding when a failure should raise rather than return.30 min
- Iterators, Generators, and LazinessThe iterator protocol, yield, and pipelines that process a file larger than memory. Where laziness wins, and the bugs that appear when a generator is consumed twice.30 min
- Context ManagersGuaranteeing cleanup even when something raises: the with statement, contextlib, writing your own, and the resource leaks that appear the moment you do not.30 min
- DecoratorsWrapping a function to add behaviour around it: closures, functools.wraps and the debugging misery of forgetting it, decorators that take arguments, and when a decorator is the wrong tool.30 min
- Testing with PytestTests that fail usefully: plain assertions, fixtures, parametrisation, and choosing what to test so the suite catches regressions instead of restating the implementation.30 min
- Test Doubles and When to MockPatching, fakes and seams. Mocking at the boundary rather than in the middle, and the over-mocked test that passes happily while the code it covers is broken.30 min
- Logging Instead of PrintLevels, loggers and handlers; structured logs you can search; and what must never reach a log line. Configuring logging once, at the edge, instead of everywhere.30 min
- Working with JSON and External DataParsing data you did not create: validating shape before trusting it, custom encoders, numbers and dates that do not survive a round trip, and failing loudly at the boundary.30 min
- Dates, Times, and Time ZonesNaive versus aware datetimes, storing UTC and displaying local, zoneinfo, and the arithmetic that goes wrong twice a year when clocks change.30 min
- Regular Expressions in ModerationEnough regex to be useful — groups, anchors, greediness, compiled patterns — plus the cases where a parser, a split, or three lines of plain code is the correct answer.30 min
- Files, Paths, and the Filesystempathlib beyond the basics: globbing, temporary files, atomic writes that survive a crash mid-write, permissions, and why string paths keep breaking on someone else's machine.30 min
- Subprocesses and the ShellRunning other programs safely: argument lists versus shell strings, capturing and streaming output, exit codes, timeouts, and the injection risk in shell=True.30 min
- HTTP Clients and Talking to APIsSessions and connection reuse, timeouts you must always set, retries with backoff on the right status codes, pagination, and reading an API error instead of swallowing it.30 min
- Configuration and SecretsLayering defaults, files and environment variables; validating configuration at startup so it fails immediately; and keeping credentials out of your repository for good.30 min
- Code Quality ToolingFormatters and linters that end style arguments, pre-commit hooks that catch problems before review, and wiring the same checks into CI so they cannot be skipped.30 min
- Profiling Before OptimisingMeasuring where time actually goes: timeit for micro-questions, cProfile for real programs, reading the output, and the optimisation that made everything slower.30 min