EXPLAINER

Python AI Libraries: What to Use When

Choose Python libraries by role: standard library and an HTTP client for API calls, a data library for tables, an embeddings or vector helper for retrieval, and an agent framework only when orchestration outgrows a simple loop.

Short answer: Match the role, not the hype: stdlib/HTTP for calls, data tools for tables, embedding/vector helpers for RAG, frameworks for complex tool loops. Start thin; add a layer when pain is real.

What is it?

The Python ecosystem offers many AI-related packages. This page is a decision guide by job-to-be-done, not a ranked leaderboard. Names you see in articles (HTTP clients, official provider SDKs, LangChain, LlamaIndex, NumPy/pandas, vector helpers) illustrate categories. Prefer one clear tool per role.

Why it matters

Installing everything creates version conflicts and hides what your program actually does. A thin stack is easier to secure, evaluate and replace. Understanding roles also clarifies when a framework helps versus when direct API calls are enough.

How to do it

Map your need to a role:

  1. Standard library — files, JSON, CSV, urllib, argparse, logging. Enough for many scripts (JSON and CSV Handling for AI Work in Python, Calling AI and Model APIs with Python).
  2. HTTP client — use when you want connection pooling, clearer timeouts or session helpers (urllib remains valid).
  3. Provider SDK — optional convenience around one vendor's API; keep business logic outside it.
  4. Data library — tables, joins, group-bys on larger CSV/Parquet sets.
  5. Embeddings / vector helper — batch embedding, local similarity, or talking to a vector database.
  6. Agent / orchestration framework — tool registries, multi-step graphs, multi-agent wiring. Choose only after a hand-written loop hurts (How to Choose an Agent Framework).

Write a one-page ADR (architecture decision record) when you add a heavy dependency.

Example

JobLean choiceHeavier choice when needed
Call chat APIstdlib urllib + JSONOfficial SDK
Eval CSV of questionscsv modulepandas / Polars
Toy RAG over 200 fileslists + cosine in pure PythonVector DB client
Many tools + retries + tracingYour own loop firstOrchestration framework

A team might start with stdlib HTTP for chat and JSONL for eval scores, then add a vector database client when retrieval latency requires an index — without adopting an agent framework yet.

When to use it

Revisit library choices when onboarding cost rises, when cold-start scripts need twenty imports to print one completion, or when you cannot explain which package owns retries and which owns prompts.

Practical notes

When you evaluate a new package, write a twenty-line spike that performs your real job — one chat call, one embed, one retrieve — and measure latency and failure modes. Prefer libraries that let you swap the underlying HTTP client so tests can mock the network. Be wary of packages that download large models on import. Pin versions in 'requirements.txt' or a lockfile once a spike succeeds. If two libraries both claim to "do agents", pick one and delete the other from the environment; overlapping abstractions make tool permission bugs harder to see. Revisit the thin-stack choice every time you add a new production dependency.

Common mistakes

  • Adding an agent framework on day one for a single prompt.
  • Depending on two frameworks that both wrap the same API.
  • Letting a notebook install packages globally instead of a venv.
  • Treating a framework tutorial as a security model — you still validate tools (Agent Tools: How AI Agents Take Actions).
Learning path: Build with Python (step 5 of 5)