check_if_file_exists
Verify the existence of a file (notebook) in the user's shared space. Provides a JSON response indicating file status, including existence and a descriptive message.
Instructions
Check if a file (notebook) exists in the user's shared space.
Args:
file_name: Name of the file to check (with or without .ipynb extension)
Returns:
JSON object with the file existence status
{
"exists": True/False,
"message": "File exists" or "File does not exist"
}
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ctx | No | ||
| file_name | Yes |
Implementation Reference
- src/api/tools/notebooks/utils.py:377-407 (handler)The handler function implementing the logic to check if a specified file exists in the user's shared or personal space using the SingleStoreDB file manager SDK.def check_if_file_exists(file_name: str, location: str = "shared") -> bool: """ Check if a file exists in the user's shared or personal space. Args: file_name: Name of the file to check (with or without .ipynb extension) location: Location to check ("shared" or "personal") Returns: Boolean indicating whether the file exists """ settings = config.get_settings() org_id = get_org_id() access_token = get_access_token() file_manager = s2.manage_files( access_token=access_token, base_url=settings.s2_api_base_url, organization_id=org_id, ) if location == "shared": return file_manager.shared_space.exists(file_name) else: # personal try: return file_manager.personal_space.exists(file_name) except AttributeError: # If personal space is not supported, return False logger.warning("Personal space not supported by SDK") return False