The Deta SDK

The Deta library is the easiest way to store and retrieve data from your Deta Base and Deta Drive in a Collection. Currently, we support JavaScript (Node + Browser), Python 3 and Go.

You’ll first need to install and instantiate your SDK, before you can interact with Base or Drive.

Once you have, if you’re someone who learns by theory, see the reference documentation:

If you’re someone who learns by example, there are also extensive code examples.

Installing

Terminal window
npm install deta

ℹ️ If you are using the Deta SDK within a Deta Micro, you must include deta in your package.json file to install the latest sdk version.

Instantiating

To start working with your Base or Drive, you need to import the Deta class and initialize it.

The SDK needs to be authenticated with Space to talk with a Base or Drive.

Once you’re authenticated, you can instantiate a subclass called Base with a database name of your choosing or Drive with a drive name of your choosing.

Deta Bases and Drives are created for you automatically when you start using them.

const { Deta } = require('deta'); // import Deta
// Initialize
const deta = Deta();
// This how to connect to or create a database.
const db = deta.Base('simple_db');
// This how to connect to or create a drive.
const drive = deta.Drive('my_store');
// You can create as many as you want.
const books = deta.Base('books');

Authentication

Authentication is managed for you when developing locally with the space dev command, when using the SDK inside a Micro, or when using the SDK in a Space app running in the browser (the SDK will not authenticate on public micros or public routes).

Alternatively, you can authenticate with the Deta SDK by providing a Data Key in an environment variable called DETA_PROJECT_KEY.

⚠️ Your Data Key is confidential and meant to be used by you. Anyone who has your Data Key can access your database. Please, do not share it, commit it in your code, or use it in the Browser.