Pages

Topics

Tools

↑↓navigate↵openescclose

Python guides

Every published Python guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest Python guides

Illustration of a document being loaded and split into smaller text chunks for a LangChain retrieval pipeline.
Python

Python LangChain Document Loaders and Text Splitters Explained

python langchain document loaders and text splitters: Learn how LangChain document loaders ingest files and how text splitters prepare content for embeddings, with pra...

LangChainDocument LoadersText SplittingRAG
A diagram showing an LLM agent loop connecting a model to tool functions with observations returning to the model.
Python

Building Python LangChain Tools and Agents

Learn how to build Python LangChain tools and agents: defining tools, structuring arguments, running the agent loop, handling errors, and controlling cost.

LangChainPythonLLM AgentsTool Calling
Diagram showing an LLM response being parsed into a structured Pydantic object.
Python

Python LangChain Structured Output and Parsers

Learn how to get typed, structured LLM responses in Python with LangChain output parsers, including Pydantic and JSON examples, retry logic, and production tips.

LangChainStructured OutputOutput ParsersPydantic
Diagram showing a prompt template with placeholders transforming into structured chat message bubbles that feed into a chat model icon.
Python

Python LangChain Prompt Templates and Chat Models

Learn how to use LangChain prompt templates with chat models in Python, including ChatPromptTemplate, message roles, partial variables, and output parsing.

LangChainPrompt TemplatesChat ModelsLLM
Illustration of a Python script with timeout, retry, and error handling controls for the OpenAI API
Python

Python OpenAI API: Timeouts, Retries, and Error Handling

Learn how to set timeouts, control retries, and handle errors when calling the OpenAI API from Python to build resilient applications.

OpenAIPythonTimeoutRetries
Python code submitting a batch of requests to the OpenAI Batch API, with a progress indicator and results file
Python

Python OpenAI Batch API: Submit and Process Jobs

Learn how to submit and process OpenAI batch jobs from Python: upload a JSONL request file, create a batch job, poll for status, and retrieve results.

OpenAI APIBatch ProcessingPythonJSONL
Illustration of Python code generating OpenAI embeddings that map text documents into a vector space for similarity search.
Python

Using OpenAI Embeddings in Python for Semantic Search

Create embeddings with the OpenAI Python client, understand the response structure, compute cosine similarity, and build semantic search over your documents.

openaiembeddingssemantic-searchcosine-similarity
Illustration of a Python script uploading a file to the OpenAI API, showing a file icon moving to a cloud with OpenAI branding.
Python

Python OpenAI File Upload: How to Upload Files with the API

Learn how to upload files to the OpenAI API with Python using files.create, including parameters, error handling, and use in fine-tuning and assistants.

OpenAI APIFile UploadPythonFine-tuning
Illustration of a Python script sending an image and text to an OpenAI model, with a visual representation of multimodal input.
Python

Python OpenAI Image Input and Multimodal Requests

Use the OpenAI Python SDK to send images to vision-capable models: URL images, base64 local files, multiple images, response handling, and cost considerations.

OpenAI APIMultimodalPython SDKImage Input
Diagram showing an async OpenAI client sending multiple concurrent API requests through an event loop
Python

Using the Python OpenAI Async Client

Practical guide to the Python OpenAI async client: concurrent requests, streaming, retries, timeouts, and client lifecycle management in production.

OpenAIasyncioPythonasync/await