# Astro + Turso

> Set up Turso in your Astro project in minutes.
> Canonical HTML: https://tursodb.cn/docs/sdk/ts/guides/astro/
> Upstream Source (MIT): https://docs.turso.tech/sdk/ts/guides/astro
> Language: en

---
![Astro banner](/images/turso-docs/guides/astro-banner.png)

## Prerequisites

To get the most out of this guide, you'll need to:

* [Install the Turso CLI](/docs/cli/installation/)
* [Sign up or login to Turso](/docs/cli/authentication/#signup)
* Have an Astro project — [learn more](https://docs.astro.build/en/install/auto/#1-run-the-setup-wizard)

**1. Install the libSQL SDK**

Begin by installing the `@libsql/client` dependency in your project:



```bash npm
npm install @libsql/client
```

```bash pnpm
pnpm install @libsql/client
```

```bash yarn
yarn add @libsql/client
```

```bash deno
deno add npm:@libsql/client
```

**2. Configure database credentials**

Get the database URL:

```bash
turso db show --url <database-name>
```

Get the database authentication token:

```bash
turso db tokens create <database-name>
```

Assign credentials to the environment variables inside `.env`.

```bash
TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=
```

**3. Configure libSQL client**

```ts src/turso.ts
import { createClient } from "@libsql/client/web";

export const turso = createClient({
  url: import.meta.env.TURSO_DATABASE_URL!,
  authToken: import.meta.env.TURSO_AUTH_TOKEN,
});
```

<div class="doc-callout doc-callout-info"><div class="doc-callout-title">NOTE</div><div class="doc-callout-body">

Astro will soon introduce a new ENV API. [Take a
look](https://docs.astro.build/en/reference/configuration-reference/#experimentalenv).

</div></div>


**4. Execute SQL**

```ts
---
import { turso } from './turso'

const { rows } = await turso.execute('SELECT * FROM table_name')
---
```

## Examples

<div class="doc-cards">
<a class="doc-card" href="https://github.com/tursodatabase/examples/tree/master/app-tustro-blog" target="_blank" rel="noopener noreferrer"><div class="doc-card-title"><span>Blog</span><span class="doc-card-arrow" aria-hidden="true">↗</span></div><p class="doc-card-desc">See the full source code</p></a>
</div>
