Key takeaways
- LangChain is an open-source framework for building LLM applications, with Python and JavaScript versions.
- Install the core package plus a provider integration, such as langchain-openai or langchain-ollama.
- Recent LangChain releases support current Python versions, including 3.13; check each package's requirements.
- With Ollama, pass system instructions as a system message in a chat prompt template, not inside the user text.
- Learn LLM basics and LangChain's core pieces first, then LangGraph for agents and stateful workflows.
LangChain is an open-source framework, available as a Python library, for building applications with large language models: it gives you standard interfaces for chat models, prompts, tools, retrievers and agents, plus integrations with hundreds of providers and data sources. Its companion LangGraph handles stateful agents. I build RAG and AI products in Python with FastAPI, so this page covers what LangChain is, installing it, Python 3.13, tutorials and examples, system prompts with Ollama, and how and in what order to learn LangChain and LangGraph.
What is LangChain in Python?
LangChain in Python is a set of packages that make it easier to build LLM applications: chat model wrappers with a common interface, prompt templates, output parsers, document loaders, text splitters, retrievers, tool calling and agents.
Also asked as: langchain tutorial python
Its value is standardisation: you can switch from one model provider to another by changing one class, and connect components with a consistent interface. Typical uses are RAG chatbots over documents, agents that call tools and APIs, structured data extraction, and summarisation pipelines. The ecosystem includes LangGraph for controllable agent workflows and LangSmith for tracing and evaluation. For simple apps, calling a model's SDK directly can be simpler, so use LangChain when its abstractions save you real work.
Is LangChain a Python library?
Yes. LangChain is distributed as Python packages on PyPI, mainly langchain and langchain-core, with separate integration packages such as langchain-openai, langchain-anthropic and langchain-ollama. There is also a JavaScript and TypeScript version.
The split into packages keeps dependencies light: you install only the integrations you use. langchain-core defines base interfaces; langchain contains higher-level components such as agents; langchain-community holds many third-party integrations; and LangGraph is a separate library for graph-based agents. LangChain is open source under the MIT licence, maintained by LangChain Inc. and a large community.
How do I install LangChain in Python?
Create a virtual environment, then install LangChain and the integration for your model provider with pip, for example pip install langchain langchain-openai or pip install langchain langchain-ollama. Set your provider's API key as an environment variable.
Also asked as: how to install langchain in python
Steps:
python -m venv .venv
source .venv/bin/activate # on Windows: .venv\Scripts\activate
pip install -U langchain langchain-openai
Keep API keys in environment variables or a git-ignored .env file, never in code. Pin versions in requirements.txt once your app works, because LangChain has evolved quickly and newer releases sometimes change interfaces. Check the documentation's installation page for current package names.
Can I use LangChain with Python 3.13?
Yes, recent LangChain releases support current Python versions, including 3.13. Older LangChain versions or specific integration packages may lag, so check each package's supported versions on PyPI if installation fails.
Also asked as: can we use langchain with python version 3.13
If you hit errors on Python 3.13, the cause is usually a dependency without compatible wheels yet, such as a native library used by a particular integration. Solutions: upgrade LangChain and the integration to the latest versions, use Python 3.12 for that project with a tool such as pyenv or uv, or swap the problematic integration. Newer LangChain versions have also dropped support for old Python versions, so very old Python installations may need upgrading.
Is there a good LangChain tutorial in Python?
Yes. The official LangChain documentation has tutorials for chat models, RAG, structured extraction and agents, and LangChain Academy offers free courses, including on LangGraph. Start with the official material, because many older blog tutorials use deprecated interfaces.
A suggested order:
- Call a chat model and stream a response.
- Build a prompt template and parse structured output.
- Load documents, split them, embed them and build a retriever.
- Combine retrieval and generation into a RAG chain with citations.
- Add tool calling, then build an agent with LangGraph.
- Trace runs with LangSmith or logging to debug.
Build one small project end to end rather than following many partial tutorials.
What are some LangChain examples in Python?
Common examples include a chatbot with memory, RAG over PDFs, extracting structured data from emails into a schema, summarising long documents, SQL question answering over a database, and agents that call web search or internal APIs.
Also asked as: langchain examples python
A minimal chain:
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([("system", "Answer briefly."), ("human", "{q}")])
chain = prompt | ChatOpenAI(model="gpt-4o-mini")
print(chain.invoke({"q": "What is RAG?"}).content)
The | operator composes components into a runnable chain that supports invoke, stream and batch. The documentation and the repository's cookbook contain many more examples.
What is the right way to do system prompting with Ollama in LangChain?
Use ChatOllama from the langchain-ollama package with a chat prompt template that has a separate system message. The system message goes into Ollama's system role, so the model treats it as instructions rather than user text.
Also asked as: what is the right way to do system prompting with ollama in langchain using python
from langchain_ollama import ChatOllama
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([
("system", "You are a concise assistant. Answer in two sentences."),
("human", "{question}"),
])
chain = prompt | ChatOllama(model="llama3.1")
print(chain.invoke({"question": "What is chunking?"}).content)
Avoid the older completion-style Ollama class for chat models, and check that the model you pulled supports system prompts well.
How do I learn LangChain?
Learn LLM fundamentals first, prompts, tokens, embeddings and tool calling, then LangChain's core concepts: chat models, prompts, runnables, retrievers and tools. Build a RAG app and a simple agent, using official docs and LangChain Academy.
Also asked as: how to learn langchain
Tips:
- Read the conceptual guide before copying code.
- Prefer current documentation over old videos and blog posts.
- Use LangSmith or detailed logging to see exactly what is sent to the model.
- Learn to evaluate: a small test set of questions with expected answers.
- Compare with calling the model SDK directly, to understand what the framework adds.
Discussion forums are useful for real-world pitfalls, but verify advice against the current docs.
How long does it take to learn LangChain?
With solid Python, you can build a basic RAG app or chain in a few days, and become comfortable with core components in two to four weeks of regular practice. Production-grade skills, evaluation, agents and deployment, take a few months of real projects.
Also asked as: how long to learn langchain
The framework is the smaller part; the harder skills are retrieval quality, prompt design, evaluation, cost control and handling failures. A focused plan: week one for basics and a chatbot, week two for RAG, week three for tools and agents with LangGraph, week four for evaluation and deployment with FastAPI. Building one complete project you can demo is worth more than finishing many courses.
Should I learn LangChain or LangGraph first?
Learn LangChain's core concepts first, chat models, prompts, tools and retrievers, because LangGraph builds on them. Then learn LangGraph for agents and multi-step workflows that need state, loops, branching and human approval.
LangChain's newer agent features are themselves built on LangGraph, so you will meet both. If your app is a straightforward RAG pipeline or extraction task, LangChain components may be all you need. If you are building agents that call tools repeatedly, wait for human input or recover from errors, LangGraph gives you explicit control over each step, which makes behaviour easier to debug and test.





