How to create, read, and search files using the Local SDK (with unified example)
The Local SDK provides a set of methods for managing files in your project directory. This guide explains how to use these methods, referencing the actual implementation in our LangGraph React App. At the end, you’ll find a unified example script that demonstrates all file operations together.
The main file management methods are:
All file paths are relative to your SDK’s working directory. The SDK will automatically create parent directories if they don’t exist.
Tip: The SDK is designed for text files. For binary files, use encoding/decoding (see below).
str
): Path to the file, relative to working_dirstr
): Text content to writebool
): True
on success, False
otherwisestr
): Path to the file, relative to working_dirstr
or None
): File content as string, or None
if the file does not existstr
): Substring or regex to matchList[str]
, optional): Glob patterns for files to search (default: ['**/*']
)Dict[str, List[str]]
): Mapping of file paths to lists of matching linesBelow is a complete script that demonstrates how to use all file management commands together. This example is based on the actual usage in react.py
:
search_files
for performance.You can combine file operations with the code()
and code_headless()
methods for AI-powered code editing. See the AI Coding page for details.
How to create, read, and search files using the Local SDK (with unified example)
The Local SDK provides a set of methods for managing files in your project directory. This guide explains how to use these methods, referencing the actual implementation in our LangGraph React App. At the end, you’ll find a unified example script that demonstrates all file operations together.
The main file management methods are:
All file paths are relative to your SDK’s working directory. The SDK will automatically create parent directories if they don’t exist.
Tip: The SDK is designed for text files. For binary files, use encoding/decoding (see below).
str
): Path to the file, relative to working_dirstr
): Text content to writebool
): True
on success, False
otherwisestr
): Path to the file, relative to working_dirstr
or None
): File content as string, or None
if the file does not existstr
): Substring or regex to matchList[str]
, optional): Glob patterns for files to search (default: ['**/*']
)Dict[str, List[str]]
): Mapping of file paths to lists of matching linesBelow is a complete script that demonstrates how to use all file management commands together. This example is based on the actual usage in react.py
:
search_files
for performance.You can combine file operations with the code()
and code_headless()
methods for AI-powered code editing. See the AI Coding page for details.