> ## Documentation Index
> Fetch the complete documentation index at: https://docs.doconda.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to generate Office files from AWS Lambda with Python

> Package doconda in your Lambda and call documents.create: it returns a Word, PowerPoint or Excel file with its PDF, no Office libraries needed.

Add `doconda` to your Lambda function's package and call `doconda.documents.create(format=..., prompt=...)` (or with your
Markdown in `content`). The call waits until the file is ready and returns its download links; `documents.download`
gives you the bytes to store in S3 or send on.

## Steps

1. Put your Doconda API key (dashboard → **API keys**) in the function's `DOCONDA_API_KEY` environment variable,
   preferably from a secret rather than in code.
2. Package the dependency (Python 3.9 or later; its only dependency is `httpx`): `pip install doconda -t package/` and
   add your `lambda_function.py` to the zip.
3. Write the handler:

```python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
from doconda import Doconda, DocondaError

doconda = Doconda()  # reads DOCONDA_API_KEY


def lambda_handler(event, context):
    try:
        doc = doconda.documents.create(
            format=event.get("format", "docx"),
            content={"markdown": event["markdown"]},
        )
    except DocondaError as e:
        return {"error": e.code, "status": e.status}

    return {
        "id": doc["id"],
        "status": doc["status"],
        "outputs": doc["outputs"],
    }
```

Test it with an event like `{"format": "xlsx", "markdown": "# Budget\n\n| Item | Amount |\n|---|---|\n| Venue | 1200 |"}`.
To have the AI write it, pass `prompt` instead of `content`.

Raise the function's timeout: creating from your Markdown at `fast` quality takes a few seconds, but `standard` can take
several minutes (see [quality levels](/en/guides/create)). If you don't want the Lambda to wait, use
`create_in_background(...)`, which answers right away, and get notified with a webhook (`doconda.webhooks.create(url)`).

## What you get back

```json theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
{
  "id": "doc_01JAB3H8K2M7V6X5T1R0NPQ4ZW",
  "status": "ready",
  "outputs": [
    { "kind": "xlsx", "url": "https://…", "expires_at": "…" },
    { "kind": "pdf", "url": "https://…", "expires_at": "…" }
  ]
}
```

* `outputs`: the file and its PDF. Links expire after 5 minutes; `documents.outputs(id)` gives fresh ones.
* To store the file in S3: `doconda.documents.download(doc["id"], "xlsx")` returns the bytes.
* `status`: `ready`, `ready_with_warnings`, `needs_review` (check `documents.report(id)`) or `failed` (not charged).

## FAQ

<AccordionGroup>
  <Accordion title="Do I need python-docx, python-pptx or openpyxl?">
    No. The SDK only makes the call; you get the finished, editable file with its PDF.
  </Accordion>

  <Accordion title="Does it retry on network errors?">
    Yes: network errors, 429 and 5xx are retried automatically (`max_retries=2` by default) before raising
    `DocondaError`.
  </Accordion>

  <Accordion title="Where are the documents stored?">
    In the European Union (Ireland), and the AI that processes them also runs in the EU.
  </Accordion>

  <Accordion title="How much does it cost?">
    You pay per delivered document; failed ones are not charged. See [pricing](/en/guides/account#pricing).
  </Accordion>
</AccordionGroup>

## Keep reading

* [Python SDK](/en/sdk/python): every method.
* [Amazon Bedrock](/en/agents/bedrock): if the Lambda runs a Bedrock agent.
* [Quickstart](/en/quickstart).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.