# Python quickstart (/docs/sdks/python-quickstart)
In a few minutes you'll install `docklee`, write a memory with `Dock`, read it back with `Lynk`, and ask an engine a question, all from Python.

## Prerequisites [#prerequisites]

- Python 3.9+.
- An API key with the **Both** capability. See [API keys](/docs/docklee/api-keys).
- A memory space ID from **DUM**, and an engine ID from **Knowledge Engines**, in the [Docklee dashboard](https://app.docklee.com).

## Store and recall from Python [#store-and-recall-from-python]

<Steps>
<Step>
### Install the package [#install-the-package]

```bash
pip install docklee
```
</Step>

<Step>
### Set your environment [#set-your-environment]

```bash
export DOCKLEE_API_KEY="your-api-key"
export DOCKLEE_MEMORY_SPACE_ID="your-memory-space-id"
export DOCKLEE_ENGINE_ID="your-engine-id"
```

`Dock` and `Lynk` read these on creation, so your code never holds the key.
</Step>

<Step>
### Write a memory [#write-a-memory]

`capture` returns at once. `flush_sync()` sends the buffer and waits for the result:

```python
from docklee import Dock

dock = Dock()
dock.capture("Maya prefers email over phone calls.", type="preference", end_user="user_8f2c")
result = dock.flush_sync()
print(result.accepted, result.rejected)
```

```text
1 0
```
</Step>

<Step>
### Recall it [#recall-it]

```python
from docklee import Lynk

lynk = Lynk()
for record in lynk.recall_sync("How does Maya like to be contacted?", end_user="user_8f2c"):
    print(record.confidence, record.content)
```

```text
0.87 Maya prefers email over phone calls.
```
</Step>

<Step>
### Ask an engine [#ask-an-engine]

```python
result = lynk.query_sync("What is the refund window?")
print(result.answer)
```

```text
Customers can request a refund within 30 days of purchase.
```
</Step>
</Steps>

## Use it from async code [#use-it-from-async-code]

Every `Lynk` method has an async form, and `Dock` has `flush` and `close`. In an async app, such as FastAPI, use those instead of the `_sync` methods:

```python
import asyncio
from docklee import Dock, Lynk


async def main() -> None:
    dock = Dock()
    lynk = Lynk()

    dock.capture("Maya renewed her plan.", type="event", end_user="user_8f2c")
    await dock.flush()

    records = await lynk.recall("What did Maya do recently?", end_user="user_8f2c")
    answer = await lynk.query("What is the refund window?")
    print(records, answer.answer)

    await dock.close()
    await lynk.close()


asyncio.run(main())
```

<Callout type="warn">
Close `Dock` before your process exits, or call `flush_sync()`. Events still in the buffer are never sent.
</Callout>

## Next steps [#next-steps]

You've used every part of the SDK once. Start with configuration, since every app sets it up a little differently.

<Cards>
  <Card title="Configuration" href="/docs/sdks/configuration" description="Environment variables and constructor options." />
  <Card title="Python reference" href="/docs/sdks/python" description="Every class and method, with its options." />
  <Card title="Errors and retries" href="/docs/sdks/errors-and-retries" description="What's retried, and what's raised." />
</Cards>
