Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:TobikoData Sqlmesh API Files

From Leeroopedia


Knowledge Sources
Domains Web_Server, REST_API
Last Updated 2026-02-07 20:00 GMT

Overview

Concrete tool for managing project files (read, write, rename, delete) provided by the SQLMesh web server.

Description

This module exposes FastAPI endpoints for file operations within SQLMesh projects. The GET endpoints retrieve file trees or individual file contents. The POST endpoint creates, updates, or renames files with optional format-on-save support for SQL files. When format-on-save is enabled, SQL files are parsed and formatted using the configured dialect before writing. The DELETE endpoint removes files. All operations respect ignore patterns defined in project configuration.

Usage

These endpoints are called by the SQLMesh web UI file browser and code editor. The file tree endpoint populates the project explorer. The individual file endpoint loads file contents into the editor. The write endpoint saves edited files with automatic formatting. The delete endpoint removes unused files from the project.

Code Reference

Source Location

Signature

@router.get("", response_model=models.Directory)
def get_files(settings: Settings = Depends(get_settings)) -> models.Directory

@router.get("/{path:path}", response_model=models.File)
def get_file(
    path: str = Depends(validate_path),
    settings: Settings = Depends(get_settings)
) -> models.File

@router.post("/{path:path}", response_model=t.Optional[models.File])
async def write_file(
    response: Response,
    path: str = Depends(validate_path),
    content: str = Body("", embed=True),
    new_path: t.Optional[str] = Body(None, embed=True),
    settings: Settings = Depends(get_settings),
    context: t.Optional[Context] = Depends(get_context),
) -> t.Optional[models.File]

@router.delete("/{path:path}")
async def delete_file(
    response: Response,
    path: str = Depends(validate_path),
    settings: Settings = Depends(get_settings),
) -> None

Import

from web.server.api.endpoints.files import router

I/O Contract

Inputs

Endpoint Method Parameters Description
/api/files GET None Retrieves full project file tree with directories and files
/api/files/{path} GET path Retrieves individual file with content
/api/files/{path} POST path, content, new_path (optional) Creates, updates, or renames file with format-on-save
/api/files/{path} DELETE path Deletes file at specified path

Outputs

Endpoint Response Type Description
/api/files Directory Nested directory structure with files
/api/files/{path} (GET) File File metadata and UTF-8 content
/api/files/{path} (POST) None Returns 204 No Content on success
/api/files/{path} (DELETE) None Returns 204 No Content on success

Usage Examples

# Get project file tree
import httpx
response = httpx.get("http://localhost:8000/api/files")
file_tree = response.json()

# Get individual file content
response = httpx.get("http://localhost:8000/api/files/models/my_model.sql")
file_data = response.json()
content = file_data["content"]

# Write file with format-on-save
response = httpx.post(
    "http://localhost:8000/api/files/models/my_model.sql",
    json={"content": "SELECT * FROM my_table"}
)

# Rename file
response = httpx.post(
    "http://localhost:8000/api/files/models/old_name.sql",
    json={"new_path": "models/new_name.sql"}
)

# Delete file
response = httpx.delete("http://localhost:8000/api/files/models/unused.sql")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment