Add HOWTO + FAQ on file management #3139
Labels
documentation
An improvement required in the project's documentation.
enhancement
New features, or improvements to existing features.
What is the problem or limitation you are having?
Discord and Discussions frequently include questions about how to access and store files in a running app. The advice is almost always the same - pointing at the
app.paths
documentation.Describe the solution you'd like
We should add:
Describe alternatives you've considered
n/a
Additional context
@rmartin16 recently provided a good model answer that could be used as the start of a draft. It uses a database as a use case.
This is a common idiom in BeeWare apps: shipping an app with a seeded database to be updated by the user after installation.
In this case, you include such a database (or csv file in this case) alongside your source code; storing this database in a resources directory would make sense.
Now, at runtime, this database is available at the App's installation file path. If you're using Toga, you can use the toga.paths.Paths API to access useful file system locations; for instance, the app's installation file path is available via toga.paths.Paths().app. More simply, this same path is available via your toga.App subclass at self.paths.app. Therefore, you can access your database via self.paths.app / "resources/db.csv" at runtime.
Since it is not safe to assume the app's installation location is writable, you should copy the seeded database to a known-writable location. For this, you should use self.paths.data as a safe and persistent location to store user data.
So, all put together, you add this to your app's startup() function...and youre good to go:
The text was updated successfully, but these errors were encountered: