StoragePaths
Provides access to commonly used storage paths on the device.
Its methods are not supported in web mode.
Inherits: Service
Methods
get_application_cache_directory- Returns the path to the application-specific cache directory.get_application_documents_directory- Returns the path to a directory for user-generated data.get_application_support_directory- Returns the path to a directory for application support files.get_console_log_filename- Returns the path to aconsole.logfile for debugging.get_downloads_directory- Returns the path to the downloads directory.get_external_cache_directories- Returns paths to external cache directories.get_external_storage_directories- Returns paths to external storage directories.get_external_storage_directory- Returns the path to the top-level external storage directory.get_library_directory- Returns the path to the library directory.get_temporary_directory- Returns the path to the temporary directory.
Examples
Basic Example
import flet as ft
async def main(page: ft.Page):
storage_paths = ft.StoragePaths()
items = []
for label, method in [
("Application cache directory", storage_paths.get_application_cache_directory),
(
"Application documents directory",
storage_paths.get_application_documents_directory,
),
(
"Application support directory",
storage_paths.get_application_support_directory,
),
("Downloads directory", storage_paths.get_downloads_directory),
("External cache directories", storage_paths.get_external_cache_directories),
(
"External storage directories",
storage_paths.get_external_storage_directories,
),
("Library directory", storage_paths.get_library_directory),
("External storage directory", storage_paths.get_external_storage_directory),
("Temporary directory", storage_paths.get_temporary_directory),
("Console log filename", storage_paths.get_console_log_filename),
]:
try:
value = await method()
except ft.FletUnsupportedPlatformException as e:
value = f"Not supported: {e}"
except Exception as e:
value = f"Error: {e}"
else:
if isinstance(value, list):
value = ", ".join(value)
elif value is None:
value = "Unavailable"
items.append(
ft.Text(
spans=[
ft.TextSpan(
f"{label}: ", style=ft.TextStyle(weight=ft.FontWeight.BOLD)
),
ft.TextSpan(value),
]
)
)
page.add(
ft.SafeArea(
content=ft.Column(
controls=[ft.Column(items, spacing=5)],
),
)
)
if __name__ == "__main__":
ft.run(main)
Methods
get_application_cache_directoryasync
get_application_cache_directory()Returns the path to the application-specific cache directory.
If this directory does not exist, it is created automatically.
Returns:
- str - The path to a directory where the application may place cache files.
Raises:
- FletUnsupportedPlatformException - If called on the web platform.
get_application_documents_directoryasync
get_application_documents_directory()Returns the path to a directory for user-generated data.
This directory is intended for data that cannot be recreated by your application.
For non-user-generated data, consider using:
Raises:
- FletUnsupportedPlatformException - If called on the web platform.
Returns:
- str - The path to the application documents directory.
get_application_support_directoryasync
get_application_support_directory()Returns the path to a directory for application support files.
This directory is created automatically if it does not exist. Use this for files not exposed to the user. Do not use for user data files.
Raises:
- FletUnsupportedPlatformException - If called on the web platform.
Returns:
- str - The path to the application support directory.
get_console_log_filenameasync
get_console_log_filename()Returns the path to a console.log file for debugging.
This file is located in the flet.StoragePaths.get_application_cache_directory.
Raises:
- FletUnsupportedPlatformException - If called on the web platform.
Returns:
- str - The path to the console log file.
get_downloads_directoryasync
get_downloads_directory()Returns the path to the downloads directory.
The returned directory may not exist; clients should verify and create it if necessary.
Raises:
- FletUnsupportedPlatformException - If called on the web platform.
Returns:
- Optional[str] - The path to the downloads directory, or None if unavailable.
get_external_cache_directoriesasync
get_external_cache_directories()Returns paths to external cache directories.
These directories are typically on external storage (e.g., SD cards). Multiple directories may be available on some devices.
Raises:
- FletUnsupportedPlatformException - If called on the web or non-Android platforms.
Returns:
- Optional[list[str]] - A List of external cache directory paths, or
Noneif unavailable.
get_external_storage_directoriesasync
get_external_storage_directories()Returns paths to external storage directories.
These directories are typically on external storage (e.g., SD cards). Multiple directories may be available on some devices.
Raises:
- FletUnsupportedPlatformException - If called on the web or non-Android platforms.
Returns:
- Optional[list[str]] - A List of external storage directory paths, or
Noneif unavailable.
get_external_storage_directoryasync
get_external_storage_directory()Returns the path to the top-level external storage directory.
Raises:
- FletUnsupportedPlatformException - If called on the web or non-Android platforms.
Returns:
- Optional[str] - The path to the external storage directory, or
Noneif unavailable.
get_library_directoryasync
get_library_directory()Returns the path to the library directory.
This directory is for persistent, backed-up files not visible to the user (e.g., sqlite.db).
Raises:
- FletUnsupportedPlatformException - If called on the web or non-Apple platforms.
Returns:
- str - The path to the library directory.
get_temporary_directoryasync
get_temporary_directory()Returns the path to the temporary directory.
This directory is not backed up and is suitable for storing caches of downloaded files. Files may be cleared at any time. The caller is responsible for managing files within this directory.
Raises:
- FletUnsupportedPlatformException - If called on the web platform.
Returns:
- str - The path to the temporary directory.