# Quickstart

> Create a branch, connect with psql, fork it and reset it.

You need an API token (`elefork_…`) for your organization.

## 1. Install the CLI and SDK

```sh
pip install 'elefork[mcp,sql]'
export ELEFORK_URL=https://api.elefork.com
export ELEFORK_TOKEN=elefork_...
```

## 2. Create a project

```sh
elefork project create demo      # returns when its default branch "main" is running
export ELEFORK_PROJECT=demo
elefork branch list              # main never expires; note its id (br_...)
```

To start from another template, pass `--template` (`elefork templates` lists them); `--no-branch` creates an empty project.

## 3. Connect

Get short-lived credentials and connect with any Postgres client:

```sh
psql "$(elefork branch credentials br_...)"
```

The command prints a URI like this one:

```
postgresql://postgres:<token>@br-xxxx.db.elefork.com:5432/postgres?sslmode=verify-full
```

The password is a JWT that is valid for one hour by default. The hostname selects your branch (see [Connecting](/docs/concepts/connecting/)).

`sslmode=verify-full` checks the server certificate against libpq's root certificates, which default to `~/.postgresql/root.crt`. Most machines do not have that file; to use the operating system's trusted CAs instead (libpq 16 or later), set:

```sh
export PGSSLROOTCERT=system
```

(or add `&sslrootcert=system` to the URI). `elefork export` and `elefork import` do this for you when neither `PGSSLROOTCERT` nor `~/.postgresql/root.crt` is set.

Without a driver, run SQL through the API (as the `postgres` role, through the same gateway):

```sh
elefork sql br_... "create table t(id int primary key); insert into t values (1); select * from t"
```

The script runs as one transaction: if a statement fails, the statements before it are rolled back too.

The console has the same flow: create a project, copy the connection string, then use the **Tables**, **SQL Editor** and **Monitoring** tabs of a branch.

## 4. Checkpoint, fork, reset

```sh
elefork checkpoint create br_main --name seed           # snapshot
elefork branch create --checkpoint ckp_... --count 10   # 10 identical copies
elefork branch create --parent br_main                  # fork the current state
elefork branch reset br_main --checkpoint ckp_...       # back to the snapshot
```

## 5. Clean up

```sh
elefork branch delete br_...
```

L0 branches you forget about are deleted after 24 hours (see [Branches](/docs/concepts/branches/#lifetime)).

## The same in Python

```python
from elefork import Client

c = Client()                                  # reads ELEFORK_URL / ELEFORK_TOKEN
project = c.project_by_name("demo")["id"]
main = c.create_branch(project, template="pg18", name="main")
ck = c.checkpoint(main["id"], "seed")
envs = c.create_branches(project, checkpoint=ck["id"], count=10, name="env")
creds = c.credentials(main["id"])             # creds["uri"] works with psycopg, asyncpg, …
c.reset(main["id"], ck["id"])
```
