Implementation:TobikoData Sqlmesh API Directories
| Knowledge Sources | |
|---|---|
| Domains | Web_Server, REST_API |
| Last Updated | 2026-02-07 20:00 GMT |
Overview
Concrete tool for managing project directories (create, rename, delete) provided by the SQLMesh web server.
Description
This module exposes FastAPI endpoints for directory operations within SQLMesh projects. The POST endpoint creates new directories or renames existing ones based on whether a `new_path` parameter is provided. The DELETE endpoint removes directories and their contents using `shutil.rmtree`. Path validation ensures operations are confined to the project directory.
Usage
These endpoints are called by the SQLMesh web UI file browser when users manipulate the project structure. Creating directories is used when organizing models, tests, or other project assets. Renaming directories updates the project structure, and deletion removes unused directory trees.
Code Reference
Source Location
- Repository: TobikoData_Sqlmesh
- File: web/server/api/endpoints/directories.py
Signature
@router.post("/{path:path}", response_model=models.Directory)
async def write_directory(
path: str = Depends(validate_path),
new_path: t.Optional[str] = Body(None, embed=True),
settings: Settings = Depends(get_settings),
) -> models.Directory
@router.delete("/{path:path}")
async def delete_directory(
response: Response,
path: str = Depends(validate_path),
settings: Settings = Depends(get_settings),
) -> None
Import
from web.server.api.endpoints.directories import router
I/O Contract
Inputs
| Endpoint | Method | Parameters | Description |
|---|---|---|---|
| /api/directories/{path} | POST | path, new_path (optional) | Creates directory at path or renames to new_path |
| /api/directories/{path} | DELETE | path | Deletes directory and all contents recursively |
Outputs
| Endpoint | Response Type | Description |
|---|---|---|
| /api/directories/{path} (POST) | Directory | Directory metadata with name and path |
| /api/directories/{path} (DELETE) | None | Returns 204 No Content on success |
Usage Examples
# Create a new directory
import httpx
response = httpx.post(
"http://localhost:8000/api/directories/models/staging",
json={}
)
# Rename a directory
response = httpx.post(
"http://localhost:8000/api/directories/models/old_name",
json={"new_path": "models/new_name"}
)
# Delete a directory
response = httpx.delete("http://localhost:8000/api/directories/models/unused")