Sub topic 12
API churn and dependency weight
This chapter covers two maintenance costs of building on a framework: how often its public API changes, and how much code you install to use it. It assumes you can use a virtual environment and pip, read a requirements.txt file, and have called an LLM chat API. The earlier chapters on framework value and on the three frameworks give the context for the trade-offs here.
Why this cost is easy to miss
A framework saves you code on day one. The bill arrives later, when you upgrade a package, when a security advisory forces you to move, or when a new teammate cannot get the project to install. Two things drive that bill:
- API churn is the rate at which a library changes or removes its public names, arguments, and behavior. Fast churn means code that worked last quarter raises errors or warns after an upgrade.
- Dependency weight is the total amount of third-party code that gets installed with a package, including indirect dependencies (the packages your dependencies need). More code means more install time, more possible version conflicts, and more places for security problems.
Both costs show up differently in a provider SDK and in a framework. A provider SDK wraps one HTTP API, so it changes when that API changes. A framework wraps many providers, vector stores, and patterns, so it changes when any of them do, and when its own authors rethink the design.
What churn looks like in practice
Churn is not abstract. The examples in this tutorial already show some of it.
- The PydanticAI example uses
output_typeandresult.output. Earlier releases used different names for both, so tutorials written a year earlier fail on a current install. - LlamaIndex moved its core classes into
llama_index.core, and moved integrations into separate packages. Old import paths such asfrom llama_index import VectorStoreIndexstopped working. - LangChain split into
langchain-core,langchain-community, and one package per provider such aslangchain-openai. Imports that used to come from one package now come from several. - Provider SDKs change too. The OpenAI Python library had a major rewrite at version 1.0, which replaced module-level calls such as
openai.ChatCompletion.createwith a client object. Newer interfaces such as the Responses API sit beside the Chat Completions interface used in this tutorial.
The pattern is the same each time. A name you depended on moves or disappears, and old blog posts, answers, and model-generated code still use the old name.
With a direct SDK call, your code sits one layer above the provider SDK. With a framework, there are usually three or four layers between your code and the HTTP API, and each layer has its own release schedule.
Measuring dependency weight
Do not guess. Install each approach into a clean virtual environment and count what arrives.
python -m venv .venv-sdk
.venv-sdk/bin/pip install openai
.venv-sdk/bin/pip list | wc -l
python -m venv .venv-lc
.venv-lc/bin/pip install langchain-openai
.venv-lc/bin/pip list | wc -lpip list prints two header lines, so subtract two from each count. The exact numbers change with every release, which is the point: record them for the versions you actually use. For a typical project you will see the SDK install pull in a modest set of packages (an HTTP client, Pydantic, and a few helpers), while a framework install adds more on top of that. Adding vector stores, document loaders, and several providers grows the list further.
To see why a package is installed, use pipdeptree.
.venv-lc/bin/pip install pipdeptree
.venv-lc/bin/pipdeptree --reverse --packages pydanticThe --reverse option shows which packages require pydantic. This helps when two packages ask for incompatible versions of the same dependency.
Why weight matters beyond install time
| Effect | What happens | Who feels it |
|---|---|---|
| Version conflicts | Two libraries require incompatible versions of a shared package, and pip cannot resolve them | Anyone adding a second library to the project |
| Image size | Container images grow, so builds and cold starts slow down | Teams deploying to serverless or small containers |
| Security surface | More packages means more advisories to read and patch | Teams with vulnerability scanning in CI |
| Import time | Importing a large package can add noticeable startup delay | Command-line tools and serverless functions |
Heavy optional integrations are the usual cause. If you install an umbrella package that bundles many integrations, you pay for all of them. Prefer the split packages (langchain-core plus langchain-openai) so you install only the providers you call.
Reading a version number
Most Python libraries use version numbers of the form MAJOR.MINOR.PATCH. In strict semantic versioning, a major bump may break your code, a minor bump adds features, and a patch bump fixes bugs. Do not rely on this for fast-moving AI libraries. Many of them are below version 1.0, and under the common convention a 0.x library may break compatibility in a minor release. Read the changelog before upgrading, even for a minor bump.
Defending against churn
You cannot stop libraries from changing, but you can limit the damage. These practices apply whichever approach you choose.
Pin your versions
Record exact versions so every install matches the one you tested. Pick a lock file tool you already use, such as pip-tools, uv, or Poetry.
pip install pip-tools
echo "openai" > requirements.in
pip-compile requirements.in --output-file requirements.txt
pip-sync requirements.txtpip-compile resolves every direct and indirect dependency to an exact version. pip-sync installs exactly that set. Upgrades then become a deliberate act: re-run pip-compile --upgrade, run your tests, and review the diff.
Keep a thin seam around the library
Do not scatter framework calls through your code base. Put them behind one function or class that your application owns. If the library changes, you edit one file.
from openai import OpenAI
client = OpenAI()
def complete(system: str, user: str, model: str = "gpt-4o-mini") -> str:
"""The only place the application talks to the model."""
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": system},
{"role": "user", "content": user},
],
)
return response.choices[0].message.content
if __name__ == "__main__":
print(complete("You are concise.", "What is dependency pinning?"))The same idea works if the body of complete calls ChatOpenAI from LangChain. Callers do not change. This seam also makes later migration cheap, which the final chapter covers.
Test the behavior you depend on
Write a few tests that call your seam with a fake model, so they run offline and fast. Add a small number of live tests that run on a schedule and tell you when an upgrade or a provider change alters real behavior.
def fake_complete(system: str, user: str, model: str = "test") -> str:
return '{"category": "billing", "urgency": 3}'
def test_ticket_parsing():
from pydantic import BaseModel
class Ticket(BaseModel):
category: str
urgency: int
ticket = Ticket.model_validate_json(fake_complete("s", "u"))
assert ticket.urgency == 3Run it with pytest. A test like this fails if a Pydantic upgrade changes the method name you rely on, which is the early warning you want.
Watch for deprecation warnings
Python hides some warnings by default. Turn them into visible failures in your test run so you see them before the removal release.
python -W error::DeprecationWarning -m pytestBe aware that warnings raised inside third-party packages can also fail the run. If that is too noisy, use pytest's filterwarnings setting to scope the error to your own modules.
Decision guidance
Churn and weight do not automatically rule out a framework. They are costs to weigh against the code the framework saves you.
- If you need one provider and one or two features, a provider SDK plus Pydantic keeps both costs low.
- If you need many integrations, such as many vector stores or document loaders, the framework's weight buys you code you would otherwise write and maintain.
- If your project is a prototype with a short life, churn matters little. If it must run for years, weigh it heavily.
- If you adopt a framework, adopt only the packages you need, pin versions, and keep the seam described above.
Common mistakes
- Installing with no version pins, then finding that a fresh install behaves differently from the one on your laptop.
- Installing an umbrella package when you need one integration.
- Upgrading several libraries at once, which makes it hard to tell which one broke the code.
- Treating a minor version bump of a
0.xlibrary as safe. - Calling framework classes from every module, so an API change touches the whole code base.
Exercise
Your team's LangChain app works locally but fails in CI with an ImportError after a teammate ran pip install --upgrade on one package. Name two practices from this chapter that would have prevented the surprise, and say how each helps.
Show answer
Pinning versions with a lock file (for example pip-compile) means CI installs the exact set that was tested, so an upgrade only happens when someone re-runs the compile step and reviews the diff. Keeping a thin seam around the framework limits the breakage to one file, so a changed import path is a single edit. Running tests that treat deprecation warnings as errors would also have flagged the problem before the removal release.
Exercise
Create two clean virtual environments, one with only openai and one with langchain-openai. How do you count the installed packages in each, and why is the count only a rough measure of weight?
Show answer
Run pip list | wc -l in each environment and subtract two for the header lines. The count is rough because it ignores package size, whether the code is imported at startup, and how often each package is updated. It also changes with each release, so record the versions alongside the numbers.