r/learnpython • • 9h ago

Learning Python for LLM Calls and Agents

I'm a social scientist who has primarily used R for my research, but would like to learn Python so that I can more effectively use LLMs. I completed the Python Programming MOOC, so I'm familiar with basic syntax, classes, etc. I then used Claude to create a textbook with exercises to cover topics such as making API calls, validation, tools, connectors, RAG, automation, eval testing, etc.

The problem I'm facing is that the code in each exercise goes well beyond what I learned in the MOOC, so I'm getting overwhelmed and feel stuck in the weeds. For instance, there are many packages being used that I've never encountered (pydantic, pytest, os, sys, threading, argparse, hashlib, pipeline, __future__) and concepts I haven't encountered (e.g., dataclasses).

- How important is it for me to understand these concepts if I want to use LLMs for scraping, classification, running OCR on large datasets? How much would I be missing if I used codex or Claude Code to simply code the files?

- How would you recommend proceeding? On one hand, I don't want to spend excessive time on more Python tutorials at the expense of doing research, but on the other, I don't want to be missing fundamentals.

- Are there any packages/concepts you would emphasize learning beyond learning basic Python syntax?

- Could you provide resources that provide a more gentle overview of how to use Python for the purpose of using LLMs?

Thanks!

5 Upvotes

11 comments sorted by

4

u/Greedy_Ad_7658 9h ago

For scraping, classification and OCR on datasets, you don't need most of that list. The textbook Claude generated is aimed at building production software (threading, hashlib, argparse, pytest), which is more than a research pipeline needs. I'd narrow it to this:

Worth learning properly:

  • Reading and writing files and data: pathlib, csv/json, and pandas (or polars) since you're coming from R. Your data frames skills transfer well.
  • Calling an API: the requests library or the provider's SDK, handling errors, rate limits and retries, and keeping the API key in an environment variable.
  • Loops, functions, dicts and lists comfortably, plus reading a traceback.
  • Structured output: pydantic (or just a JSON schema) so the model's answer is validated. For classification this is the most useful single package. dataclasses are the lightweight cousin, and both are just "a class that holds fields".
  • Saving results as you go (write each result to disk), so a crash at row 8,000 doesn't cost you the run, and logging so you can see what happened.

Can skip for now: threading, hashlib, argparse, sys, future, packaging. Come back if a script needs them.

On using Codex or Claude Code to write the files: it's fine as long as you can read what it wrote. A good habit is to run it on 20 rows first, read the output by hand, and compare against labels you made yourself. For research, validation of the LLM's labels matters far more than elegant code, and that is a skill you already have. Ask the tool to explain any line you don't follow, and add pytest later, if at all.

For a gentler path, work on one small real task of your own (say 50 documents to classify) instead of the whole textbook, and learn each piece when that task needs it.

2

u/No_Art7806 9h ago

Perfect, this is exactly the type of advice I was looking for. I would eventually like to consider applying for some data science jobs, so maybe I would need to build on these skills, but this is an excellent and feasible starting point. Thank you!

1

u/TripNo9401 2h ago

for the save-as-you-go step on 8,000 rows, do you usually just append to a jsonl file or keep a separate checkpoint of processed IDs?

3

u/avalexva 8h ago

Adding to what others said, since you mentioned maybe applying for data science jobs later: the most transferable habit from that whole list is validating outputs (pydantic) and saving results to disk as you go. In real DS work the unglamorous core is exactly that — validate inputs, persist intermediate results, log what happened. Build your first classification script with those habits and you will be ahead of most juniors. And coming from R, give polars a look once you are comfortable — it feels closer to dplyr than pandas does.

1

u/No_Art7806 8h ago

Thank you! Now let’s see if there are any data science jobs still hiring 😆

1

u/avalexva 8h ago

We took on a couple of interns, although not as full‑time employees.

2

u/neural_dataops 6h ago

Since the other replies already narrowed down the package list nicely, two things that directly help with your last question on gentle resources and eventually pivoting toward data science roles:

For a gentle, non-bloated walkthrough of calling LLMs from Python without software-engineering overhead, the official OpenAI or Anthropic Python SDK quickstart guides paired with Simon Willison's blog posts on structured data extraction and LLM CLI workflows are much easier to follow than an AI-generated textbook. They show real 20-line scripts for classification and extraction rather than over-engineered frameworks.

For bridging from R to Python data science roles down the road, focus on translating one of your existing R research workflows (cleaning a messy dataset, running summary stats, and plotting) into pandas and scikit-learn rather than taking another broad MOOC. Having two or three clean end-to-end projects where you combine messy text classification with tabular analysis will carry far more weight in interviews than memorizing standard library modules like argparse or threading.

1

u/No_Art7806 3h ago

Thanks, appreciate this advice! I did go to the Claude Platform API documentation but was surprised to find it was all in TypeScript

1

u/TheGlitchHammer 9h ago

I have the Feeling your question is all over the place. If you want to learn Python, do it for learning python. If its a single project you want to achieve, fundamentals + AI Agent might be enough, but that also means, you hand over control to the agent, making changing, fixing and debugging harder. I also think you treat packages the wrong way or give them to much thought. They are tools, interchangeable, there to achieve what you need them to do, they all bring their own syntax, but you dont need to deep dive/do explicit lessons on a certain tool, unless you heavily rely on it. Those that you named are mostly part of the Python Standard library, so tools that are bundled up with python. I would say, you need to know those tools as much as you must, for example how you can use os/Path to handle files. But you dont need to know how they achieve it. If you Encounter unknown concepts, let LLM describe it for you and than you can decide If you want or need to use it. So there is no real advice for you, you need to decide yourself where you want to Go with your knowledge, based in how much you will be using Python or any programming language in the future. If you want a packages that i would recommended somewhat understanding, at least for Data Manipulation, its Pandas. It is unbeliebly usefull for handling and manipulating structured data.

1

u/No_Art7806 8h ago

Thanks! I’ll keep that in mind with regard to the packages

0

u/ANDRE_2512 9h ago

Learning requires visualization and interactivity. Books are great. Courses are too. But nothing helps you learn as effectively as visualization.