Skip to main content
GET
Read File

Overview

The read-file resource returns the full contents of a specific file in your workspace, along with metadata and encoding information.

Resource URI

Request

string
required
Resource URI with file path: pylance://file/src/main.py
string
default:"utf-8"
Character encoding (utf-8, ascii, latin-1, utf-16)
boolean
default:"true"
Include file metadata in response
object
Optional line range to read (e.g., {"start": 10, "end": 50})

Response

string
Full file contents as string
string
Absolute file path
string
Path relative to workspace root
object
File metadata (if includeMetadata=true)

Example Request

Example Response

Reading Line Ranges

Read specific line ranges for large files:
Response:

Character Encodings

Supported encodings:
Pylance automatically detects encoding from BOM (Byte Order Mark) and file headers. Specify encoding only if detection fails.

Common Use Cases

Read Complete File

Read Large File in Chunks

Get File Hash for Caching

Performance Considerations

Files larger than 10MB will be automatically chunked. Use lineRange to read specific sections.

Optimization Tips

Cache file contents using the SHA-256 hash
Use line ranges for large files (>1000 lines)
Disable metadata if not needed to reduce response size
Batch multiple file reads in parallel
Example: Parallel Reads

Error Responses

Security

Path Traversal Prevention

All paths are validated to prevent directory traversal attacks. Attempts to access files outside the workspace will be rejected.
Blocked Examples:
Allowed Examples:

Rate Limits

List Files

Get all files in workspace

Workspace Structure

View project hierarchy