Chapter 6. Kivy Storage

So far, every time you run your weather app, it asks you to search for a location. It would be much more convenient if it could store your last location and render it by default.

Kivy is a Python library, which means you have access to the full gamut of Python storage modules. You could use basic file I/O, compression, encryption, pickling, JSON, SQLite3, an external SQL or NoSQL database, or any number of online storage services.

Depending on the data being stored, these are certainly useful tools worth checking out. However, Kivy also provides a simple but powerful key/value storage API for storing local data. Its primary advantage is that because Kivy is aware of the module, it works across the wide variety of platforms that Kivy uses without having to take into account filesystem structure or other differences between various operating systems.

Maintaining a List of Locations

Before looking at storing the locations, update the app to have a Locations tab. This involves nothing you haven’t studied before, so you may want to think of it as an exercise. I’ll try to keep this section brief so as not to bore you with knowledge you already have. If you want to skip this section, you can download the example code from O’Reilly and proceed to the next section.

Here’s what you need to do, step by step. As mentioned, there is some example code for the more complicated steps. Note in advance that the ListView of locations behaves exactly like the ListView for search ...

Get Creating Apps in Kivy now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.