# Working locally (/notebooks/working-locally)

Sign in from your laptop with databaas login and use the same Python helpers as in Notebooks.

You can read and write the lakehouse from Python on your own laptop, as yourself. Sign in once with
`databaas login`, and the helpers from [querying data](/notebooks/querying-data) and [files, blobs
and Zarr arrays](/notebooks/files-and-arrays) work in your scripts and local notebooks unchanged.

<Callout title="What you can reach">
  Code on your laptop acts with your own data grants, the same as in Notebooks: you read and write
  only what you have been granted. See [data permissions](/catalog/data-permissions).
</Callout>

## Install databaas-utils

You need Python 3.12 or newer and a web browser on the same machine. Install `databaas-utils` with
its `local` extra into a virtual environment of its own:

```bash title="Install in a new virtual environment"
python -m venv .venv
source .venv/bin/activate
pip install "databaas-utils[local]"
```

The extra brings `pyiceberg`, `pyarrow`, `zarr` and the file-store client. Use a separate
environment because `databaas-utils` ships its own build of `obstore`, which replaces any `obstore`
you already have installed.

Add whatever else you work with to the same environment, for example `pandas`, `polars`,
`jupyterlab` or `marimo`.

## Sign in

Run `databaas login` with the address you open the portal on:

```bash title="Sign in"
databaas login https://<your-databaas-domain>
```

Your browser opens on the Databaas sign-in page. Sign in with your usual Databaas login; the command
prints who you are signed in as and saves the session as a **profile**. By default the profile is
named after the first part of the domain; choose a name with `--profile <name>`.

You do this once per Databaas environment. Your session is kept in your operating system's keychain,
or in a private file if there is none, so later Python processes do not ask you to sign in again.

Check which account a profile uses with:

```bash title="Show who you are signed in as"
databaas whoami
```

## Use the helpers

Import from `databaas_utils.user`, as in a notebook:

```python title="Read a table from your laptop"
from databaas_utils.user import get_catalog

catalog = get_catalog()

catalog.list_namespaces()
catalog.load_table("<namespace>.<table>").scan(limit=10).to_arrow()
```

`get_store()` and `get_zarr_group()` work the same way. Everything in [querying
data](/notebooks/querying-data) and [files, blobs and Zarr arrays](/notebooks/files-and-arrays)
applies, with two differences:

- Converting a scan with `to_pandas()` or `to_polars()` needs `pandas` or `polars` installed in your
  environment.
- Files you `get` from a file store land on your laptop, not on your notebook server.

## Work with more than one environment

Sign in to each environment with its own profile name. The last one you signed in to is the
default.

| Command | Does |
| ------- | ---- |
| `databaas login https://<your-databaas-domain> --profile <name>` | Sign in and save a profile |
| `databaas profile list` | List your saved profiles |
| `databaas profile use <name>` | Make a profile the default |
| `databaas whoami --profile <name>` | Show who a profile is signed in as |
| `databaas logout --profile <name>` | Sign out of a profile |
| `databaas profile delete <name>` | Sign out and remove the profile from this machine |

In Python, pass `profile="<name>"` to any helper, for example `get_catalog(profile="<name>")`, or
set the `DATABAAS_PROFILE` environment variable.

## When your session expires

Your session stays valid until it goes 30 days without use, and for at most 90 days after you signed
in. After that, the next helper call opens your browser to sign in again. You can also run
`databaas login` again at any time.

## Troubleshooting

### `databaas login` refuses the address

Pass the address you open the portal on, not one that starts with `auth.` or `catalog.`. If
`databaas login` says that address serves no client id and the address is right, ask your platform
administrator.

### Loading a table fails with a permission error

You are signed in, but you have no grant on that warehouse, namespace or table. Ask whoever manages
data access to grant it; see [data permissions](/catalog/data-permissions).

### Every new Python process opens the browser

Your saved session could not be kept. Run `databaas login` once more.