tos library / API / tos.appdata
tos.appdata
A singleton instance of the internal AppData class. It exposes a single method, path(), which resolves and creates a writable directory dedicated to a single application.
Synopsis
tos.appdata.path(app_name: str) -> str
Description
Returns the absolute path to ./appdata/<app_name>/, relative to the location of tos.py. If the directory does not exist it is created with os.makedirs. The parent appdata/ folder is itself created when tos is first imported.
Parameters
| Name | Type | Description |
|---|---|---|
app_name | str | Folder name to allocate for the calling app. Any name valid on the host filesystem is accepted. |
Returns
str — absolute path to the per-app data directory.
Example
import os, json, tos
settings_dir = tos.appdata.path("trashcord")
config_file = os.path.join(settings_dir, "config.json")
with open(config_file, "w") as f:
json.dump({"theme": "dark"}, f)
Note: tos.appdata.path() has the side effect of creating the directory. It is safe to call on every launch.