4 Using a Coding Companion with Python

 

In the last chapter, you saw how a coding companion like ChatGPT can help write and refine SQL queries—especially when you guide it with clear examples and structure. Now we shift from querying data to manipulating it with code, moving from SQL to one of the most versatile tools in a data engineer’s toolbox: Python.

Python’s flexibility makes it ideal for handling real-world data engineering tasks like API interactions, parsing nested JSON, and crafting complex regular expressions. These tasks can be tedious, error-prone, and highly repetitive—perfect territory for AI assistance. Unlike SQL, where queries are often executed in one shot, Python workflows can be built up step by step, making few-shot and iterative prompting especially effective.

In this chapter, you’ll learn how to use a coding companion to write better Python—faster. We’ll explore how to generate code templates, iterate on logic, and refine solutions with targeted prompts. Whether you’re fetching data from an API or fine-tuning a regex pattern, the key is learning how to speak the AI’s language while keeping control of the outcome.

By the end of this chapter, you’ll know how to work side by side with a coding companion to tackle some of the messiest, most time-consuming parts of data engineering

4.1 Interacting with APIs Using AI Coding Companions & Python

4.1.1 Fetching Data from an API

4.1.2 Enhancing API Calls with AI Coding Companions and API Documentation

4.2 Unnesting Complex JSON Objects with AI Companions & Python

4.2.1 Simple Example: Flattening a Single Nested Field

4.2.2 Complex Example: Extracting Deeply Nested & Combined Fields

4.3 Using AI to Implement Regex Patterns

4.3.1 Extracting Phone Numbers from Text

4.3.2 Normalizing Phone Numbers with Regex and AI

4.3.3 Extracting Number Components into a DataFrame

4.4 Lab

4.5 Lab Answers