Lesson 52 of 52Real projects
Wrap-Up: Python
Tie the whole Python track together: one realistic project built from an empty folder to tested, shippable code, a mixed review, and where to go next.
You started this track with The Story of Python and a single variable. Since then you have learned the core types, written functions and classes, picked up the tools that make code feel Pythonic, typed it, made it concurrent, looked under the hood, and finally organised it into a real project with tests and security checks. That is a lot of separate lessons, and on the job they never arrive separately. This lesson lines them up once more and then uses them together on one piece of work.
The path you took
Unit 1
First steps
Variables, numbers, strings, conditions and loops gave you a program that can make decisions and repeat work.
Unit 2
Collections
Lists, tuples, sets, dicts and comprehensions gave you ways to hold real data, which functions then need to process.
Unit 3
Functions
Parameters, scope, closures and higher-order functions let you break a program into small reusable pieces.
Unit 4
Objects
Classes, dataclasses, enums and the memory model let you model your own types and stop being surprised by aliasing.
Unit 5
Pythonic Python
Exceptions, decorators, generators, context managers, type hints and async turned working code into idiomatic code.
Unit 6
Types in depth
Generics, Protocols and typing patterns let a type checker guard larger code, ready for real inputs and outputs.
Unit 7
Python power tools
Files, JSON, regex, time zones, logging, scripts and the standard library connected your code to the outside world.
Unit 8
Concurrency and performance
Threads, processes and profiling showed you when Python is slow, why, and what actually fixes it.
Unit 9
Python under the hood
Descriptors and class creation explained how the frameworks you will use next do their magic.
Unit 10
Real projects
Packages, environments, layout, packaging, upgrades, tests and security turned all of it into code a team can ship.
How it fits together
The ticket: "Finance needs a nightly report of yesterday's orders by status and currency. The data is a JSON Lines export of a few million rows in a storage bucket. Exchange rates come from an internal API." Here is how the track shows up, in the order you would really work.
Setting up. You create the project with a src layout and a pyproject.toml, as in Project Structure, and a virtual environment with a lock file from Virtual Environments. You pin requires-python to a supported release, after checking the support calendar in What Changed in Python 3.11 to 3.15. The code splits into modules (models, load, report, cli), and running it with python -m orders_report avoids the import errors you learned to diagnose in Modules and Packages.
Modelling the data. An order becomes a frozen dataclass from Dataclasses, and the status becomes a StrEnum from Enums, so a typo like "shiped" fails at parse time instead of becoming a silent extra row in the report. Money stays as integer cents, for the same float reasons you met in Numbers and Strings. Everything has type hints (Type Hints), and a small Protocol from Generics and Protocols in Depth describes "anything with a get_rate method", so tests can pass in a fake rate source.
Reading the file. A few million rows will not fit comfortably in memory, so the loader is a generator (Iterators and Generators) that opens the file inside a with block (Context Managers) and yields one parsed order per line, following Files and JSON. Bad lines raise a custom InvalidOrder exception that the loader catches, counts and logs with the line number, instead of crashing or being swallowed by a bare except (Errors and Exceptions).
Filtering by day. "Yesterday" is a time zone question. Timestamps arrive in UTC, finance means yesterday in London, so you convert the boundaries with zoneinfo and compare aware datetimes, as Dates, Times and Time Zones taught. The DST change in March is exactly when a naive version would drop an hour of orders.
Aggregating. A Counter keyed by (status, currency) tuples from Dictionaries and Tuples and Sets does the grouping in one pass, and a comprehension builds the output rows (Comprehensions). sorted with a key function from Higher-Order Functions orders them for the report.
Calling the rate API. Each currency needs one HTTP call. That is I/O-bound work, so a small thread pool fetches them in parallel (Threads and the GIL). You wrap the call in a retry decorator you wrote in Decorators, and cache results with functools.cache from functools, itertools and operator.
Making it a tool. argparse, a non-zero exit code on failure and output to stdout come from Scripting and Automation. Logging is configured once at the entry point (The logging Module), so the scheduler's logs show how many lines were skipped and why.
Proving it works. Tests use pytest fixtures and parametrize from Testing with pytest. The clock and the rate API are passed in as dependencies, so a test can freeze "now" to the night of a DST change and use a fake rate source, the design from Testing Code That Touches the Outside World.
Making it safe and fast. The output path comes from an argument, so you resolve it and check it stays inside the reports folder, and you never pickle the cache to disk, both from Python Security Pitfalls. The first full run takes four minutes. Instead of guessing, you profile it (Profiling and Making Python Fast) and find a list membership check inside the loop. A set fixes it.
Notice that no lesson was used alone. The dataclass made the tests simple, the generator made the memory profile flat, and the type hints let the Protocol swap in a fake. That is what Python at work looks like.
Check yourself
What does this print?
def add_tag(tag, tags=[]):
tags.append(tag)
return tags
a = add_tag("new")
b = add_tag("sale")
print(a, a is b)What does this print?
rows = (n * 2 for n in range(3)) print(sum(rows), sum(rows))
Match each job to the tool you would reach for.
Put the steps of starting a new Python project in a sensible order.
- Tap the steps below in the right order.
except Exception: pass around the JSON parsing so bad lines do not crash the report. What is the best review comment?What you can do now
- Read most production Python and explain what it does, including decorators, generators, context managers and type hints.
- Model data with dataclasses and enums, and avoid the aliasing and mutable-default bugs that catch beginners.
- Write command-line tools that read and write files and JSON, handle time zones correctly, log usefully and exit with the right code.
- Set up a project with a virtual environment, a
srclayout andpyproject.toml, and write pytest tests that do not depend on the network or the clock. - Choose between threads, processes and async for a given workload, and profile before optimising.
- Spot the common Python security mistakes in a code review.
That is a solid junior-to-mid level in the language itself. What you do not have yet is depth in a framework, a database or a large existing codebase. That comes from the next tracks and from real projects.
Mistakes that still catch people
- Mutating something you thought was a copy. Mutable defaults,
b = aon a list, and modifying an argument inside a function all come back to names being labels. Revisit The Python Memory Model and Arguments, *args and **kwargs. - Swallowing exceptions. A broad
exceptthat hides the error turns a crash into wrong output. Revisit Errors and Exceptions and The logging Module. - Naive datetimes. Mixing aware and naive times, or doing date maths in local time, breaks twice a year. Revisit Dates, Times and Time Zones.
- Reaching for threads to speed up CPU work. On a GIL build that makes it slower. Revisit Threads and the GIL and Profiling and Making Python Fast.
- Tests that hit the real world. Tests calling the network or
datetime.now()become flaky. Revisit Testing Code That Touches the Outside World. - Installing into the wrong Python.
pip installwithout an active environment, thenModuleNotFoundErrorat run time. Revisit Virtual Environments and Modules and Packages.
Where to go next
The natural next course is SQL & Databases: almost every Python job stores data, and the report in this lesson would really read from a database. After that, Python Backend turns everything here into web APIs with FastAPI, where you will see dataclass-style models, type hints, decorators, async and dependency injection doing real work. If interviews are close, Algorithms & Patterns uses Python to drill the problem patterns interviewers ask about.
Real practice matters as much as the next course:
- Finish and extend your project. Take Project: A Habit Tracker for the Terminal through its stretch goals and onto GitHub.
- Build it for real in the Project Lab. Guided builds on your own machine, from a first package to a tested CLI shipped with uv.
- Build and publish a small tool. A CLI that cleans or summarises a dataset you care about, with tests, CI and a release on PyPI or GitHub.
- Contribute to an open-source Python project. Start with documentation or a "good first issue". Reading a mature codebase teaches structure no lesson can.
- Read the official docs. The Python tutorial and library reference at docs.python.org, and the "What's New" page for each release, will answer questions for years.
- iterator
- An object that produces values one at a time with
next()and is used up after one pass; generators are the easy way to write one. - context manager
- An object used with
withthat runs setup on entry and guaranteed cleanup on exit, even after an error. - type checker
- A tool such as mypy or pyright that reads type hints and reports mismatches before the code runs.
- I/O-bound
- Work that spends most of its time waiting on disk or network, which threads and async can overlap.
- CPU-bound
- Work limited by computation, which needs processes, a free-threaded build or native code to use more cores.
- dependency injection
- Passing a function's collaborators, like a clock or API client, in as arguments so tests can swap them for fakes.
- lock file
- A file recording the exact version of every installed dependency, so every machine installs the same set.