Real Python (@realpython) header
Real Python (@realpython) profile picture

Helping Python developers build with AI: apps, agents, models, and AI-assisted coding. Expert-reviewed tutorials and courses, read by 1M+ developers a month.

Joined August 2012
"Write a Python turtle program that draws a python reading a book." DaisyRose 27B wrote 220 lines of code and gave its coiled green snake a pair of round reading glasses. Here’s how it did on five everyday Python tasks 🧵
1
1
6
1,790
4. Got two versions of a dataset, or a train/test split? Profile each one and call .compare() for a side-by-side report of where the distributions moved. The tutorial compares flights out of LAX and ATL. Delta (DL) leads in Atlanta and SkyWest (OO) in Los Angeles.
1
58
2. The old ydata-profiling imports pkg_resources from setuptools. Newer setuptools dropped it, and Python 3.12+ venvs ship without setuptools. Either way, the import fails with ModuleNotFoundError: No module named 'pkg_resources'. On the old package, install setuptools<81.
1
2
44
YData Profiling turns a pandas DataFrame into an HTML report of missing values, correlations and data quality warnings in two lines. Before you use it at work: 1. It has a new name 2. setuptools can break it 3. One flag for speed 4. Diff two datasets 5. When to skip it 🧵
1
16
2,161
"Write a Python turtle program that draws a python reading a book." Inkling 2 Mini wrote 102 lines and 181 drawing commands. The snake waves above an open red book, and its forked tongue floats in the air beside its head. Here's how it did on 5 everyday Python tasks 🧵
1
2
1
9
1,799
1. The fix is a single line: return df.loc[df["Humidity"] >= target] It returns the same rows without a Python loop. In Spyder's Profiler, total time dropped from 3.73 s to 905.33 µs. If pandas has a built-in way to filter rows, use it before you write an iterrows() loop.
1
3
96
This pandas function loops with iterrows() to keep rows with humidity ≥ 0.90. The Spyder IDE's Profiler timed it at 3.73 s. 5 things to know: 1. The one-line fix: 905 µs 2. Why local time said 62 ms 3. Comparing runs 4. Edits your CSV never sees 5. When to skip Spyder 🧵
1
1
15
3,083
"Write a Python turtle program that draws a python reading a book." Gemini 4 Neon wrote 429 lines for it. Its python wears round reading glasses, and the open book has a tiny snake sketched on one page. Here's how it did on four more everyday Python tasks 🧵
2
1
9
2,110
Replying to @realpython @Tool
5. LangGraph won't register the same node name twice. A second add_node("parse_notice", ...) raises ValueError ("already present"). It bites when you extend a graph by pasting new add_node() calls under the old ones. The tutorial replaces the whole registration block each time.
1
1
501
Replying to @realpython @Tool
4. The tutorial notes that OpenAI models can't extract a date as a date type. So the Pydantic schema asks the LLM for a YYYY-mm-dd string, and a @computed_field turns it into a datetime.date. With exclude=True and repr=False, the string stays out of print() and model_dump().
1
41
1. Say your agent escalates a notice when the fine an LLM pulled from the email is $100,000 or more. If the email mentions no fine, you get None, and None >= 100_000 raises TypeError. The tutorial guards it with (max_fine or 0), so a missing fine counts as zero.
1
2
110
4. autopep8 -i vs Black on one messy function. autopep8 fixes the spaces around = and +, but leaves def add(a, b): alone, since that spacing might be there for readability. Black removes it. Ruff's formatter, built as a drop-in replacement for Black, does the same.
1
16
3. autopep8 fixes PEP 8 spacing and indentation. Run it as autopep8 messy.py, though, and your file stays as it was. It only prints the fixed code to the terminal. Add -i (or --in-place) to write the changes back to the file.
1
18