Data Storage
Collections
In addition to running compute provided Micros, every Deta Space app is connected to a Collection, which offers persistent data storage.
Collections offer two services:
- Deta Base: a simple and powerful NoSQL database.
- Deta Drive: simple file storage.
All the data stored with a Collection is âsandboxedâ and belongs to the end user of the app. As mentioned in the Authentication section, you can just code your app and store data as if there were only a single user, without thinking about authentication or data separation.
Deta Base
To store data, Space apps can use Deta Base, a fully-managed, fast, and secure NoSQL database. Each app can create and use as many Bases as it needs.
Base can be accessed using the Deta Base SDK or the Base HTTP API.
Read more about Base here.
Deta Drive
To store files, Space apps can use Deta Drive, a fully-managed, secure and scalable file storage service. Each app can create and use as many Drives as it needs.
Drive can be accessed using the Drive SDK or the Drive HTTP API.
Read more about Deta Drive here.
Data Keys
Authentication between any client reading or writing data to Base and Drive in a Collection happens via a Data Key. Data Keys can be generated for any Builder Project or any Collection â including Collections disconnected from any individual app or Project (âHeadless Collectionsâ).
Space automatically manages keys for Space apps and for local development with space dev
, so there is no need to manually generate them.
But you can, if you want to interact with your data outside the context of a single Space app or are using a Headless Collection.
From your Builder Project, navigate to the Develop tab and the Data sub-tab. Click Manage Data Keys, then Create New Data Key and finally enter a name for your Data Key. You will be shown your new Data Key.
From your Horizon, click your appâs context menu, click Settings, and then navigate to the Keys tab. Click Create New Data Key and finally enter a name for your Data Key. You will be shown your new Data Key. If your app is a Builder Instance, this menu is just another view for all the keys in your Builder Project.
Open the Collections app from the Horizon and open the individual Collection you want to generate a Data Key for. Click Collection Settings in the top right corner, then click Create New Data Key, and finally enter a name for your Data Key.
You will be shown your new Data Key.
From your Builder Project, navigate to the Develop tab and the Data sub-tab. Click Manage Data Keys, then Create New Data Key and finally enter a name for your Data Key. You will be shown your new Data Key.
Developing with Base and Drive
During development, you can share data between your local environment and your Builder Project in Space. You can use the Deta SDK or HTTP API to talk with Base and Drive in your Project.
Using the SDK
Using the HTTP API
Space offers a way to automatically manage Data Keys for you with space dev
, while you can also do it yourself manually.
Automatic key management
The Space CLI can automatically connect your local development environment with your Space Base & Drive using the space dev
command. space dev
will automatically inject a Data Key into your environment, which the SDK will pick up. If you are using the HTTP API, you can pull this Data Key from the injected environment variable DETA_PROJECT_KEY
.
Manual setup
If the automatic set up does not work for your use-case, you can manually set up your local development environment by generating a Data Key in your Builder Project (see the Data Keys section).
Add this as an environment variable inside your dev environment:
The Deta SDKs will detect this key to access your development Bases and Drives.
We call these keys âData Keysâ, but the SDKs still refer to them as âproject keysâ for backwards compatibility reasons. Both of them are the same keys.
If you are not using a Deta SDK, pass this Data ey using the X-API-Key
header with the Base HTTP API or Drive HTTP API.
Headless Collections
You can also use Base or Drive to store data in a Collection, without creating a Space app. This is referred to as a Headless Collection. You can programmatically interact with data in a Headless Collection via the Deta SDKs and HTTP APIs. This can be useful for all sorts of reasons, for example see this tutorial for storing data in a Deta Base from Streamlit Cloud.
To create a Collection, open the Collections app from your Horizon and then click + New Collection. Finally, give your Collection a name to create it.
In this case, you will have to generate a Data Key for authentication, which you can do from the Collection Settings.
Data GUIs
Base and Drive both come with UIs where you can easily view and edit files and data. These UIs are available inside your Builder Project under the âDevelopâ tab and âDataâ sub-tab. They are also accessible from your Horizon for every app (click the ...
and then View Data
).
For detailed guides on using these UIs, see the documentation for Base UI and Drive UI.