---
title: Export D1 Database as SQL
---

[Skip to content](#_top)

[API Reference](https://developers.cloudflare.com/api/python)

[D1](https://developers.cloudflare.com/api/python/resources/d1)

[Database](https://developers.cloudflare.com/api/python/resources/d1/subresources/database)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Export D1 Database as SQL

d1.database.export(strdatabase\_id, DatabaseExportParams\*\*kwargs) -> [DatabaseExportResponse](<https://developers.cloudflare.com/api/python/resources/d1#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)>)

POST/accounts/{account\_id}/d1/database/{database\_id}/export

Export the SQL contents of a D1 database and return a URL where they can be downloaded. Note: this process may take some time for larger DBs, during which your D1 will be unavailable to serve queries. To avoid blocking your DB unnecessarily, an in-progress export must be continually polled or will automatically cancel.

##### Security

<details>

<summary>API Token</summary>



The preferred authorization scheme for interacting with the Cloudflare API. <a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/">Create a token</a>.

**Example:**<code>Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY</code>

</details>

<details>

<summary>API Email + API Key</summary>



The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

**Example:**<code>X-Auth-Email: user@example.com</code>

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

**Example:**<code>X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194</code>

</details>

##### ParametersExpand Collapse

account\_id: str

Account identifier tag.

maxLength32

[Link to this property](<#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20account_id%20%3E%20(schema)>)

database\_id: str

D1 database identifier (UUID).

[Link to this property](<#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20database_id%20%3E%20(schema)>)

output\_format: Literal\["polling"]

Specifies that you will poll this endpoint until the export completes

[Link to this property](<#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20output_format%20%3E%20(schema)>)

current\_bookmark: Optional\[str]

To poll an in-progress export, provide the current bookmark (returned by your first polling response)

[Link to this property](<#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20current_bookmark%20%3E%20(schema)>)

<details>

<summary>

dump\_options: Optional\[<a href="https://developers.cloudflare.com/api/python/resources/d1/subresources/database/methods/export#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20dump_options%20%3E%20(schema)">DumpOptions</a>]

</summary>

no\_data: Optional\[bool]

Export only the table definitions, not their contents

<a href="#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20dump_options%20%3E%20(schema)%20%3E%20(property)%20no_data">Link to this property</a>

no\_schema: Optional\[bool]

Export only each table’s contents, not its definition

<a href="#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20dump_options%20%3E%20(schema)%20%3E%20(property)%20no_schema">Link to this property</a>

tables: Optional\[Sequence\[str]]

Filter the export to just one or more tables. Passing an empty array is the same as not passing anything and means: export all tables.

<a href="#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20dump_options%20%3E%20(schema)%20%3E%20(property)%20tables">Link to this property</a>

</details>

[Link to this property](<#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20dump_options%20%3E%20(schema)>)

##### ReturnsExpand Collapse

<details>

<summary>

class DatabaseExportResponse: …

</summary>

at\_bookmark: Optional\[str]

The current time-travel bookmark for your D1, used to poll for updates. Will not change for the duration of the export task.

<a href="#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)%20%3E%20(property)%20at_bookmark">Link to this property</a>

error: Optional\[str]

Only present when status = ‘error’. Contains the error message.

<a href="#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)%20%3E%20(property)%20error">Link to this property</a>

messages: Optional\[List\[str]]

Logs since the last time you polled

<a href="#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)%20%3E%20(property)%20messages">Link to this property</a>

<details>

<summary>

result: Optional\[Result]

Only present when status = ‘complete’

</summary>

filename: Optional\[str]

The generated SQL filename.

<a href="#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)%20%3E%20(property)%20result%20%3E%20(property)%20filename">Link to this property</a>

signed\_url: Optional\[str]

The URL to download the exported SQL. Available for one hour.

<a href="#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)%20%3E%20(property)%20result%20%3E%20(property)%20signed_url">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)%20%3E%20(property)%20result">Link to this property</a>

<details>

<summary>

status: Optional\[Literal\["complete", "error"]]

</summary>

One of the following:

"complete"

<a href="#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)%20%3E%20(property)%20status%20%3E%20(member)%200">Link to this property</a>

"error"

<a href="#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)%20%3E%20(property)%20status%20%3E%20(member)%201">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)%20%3E%20(property)%20status">Link to this property</a>

success: Optional\[bool]

<a href="#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)%20%3E%20(property)%20success">Link to this property</a>

type: Optional\[Literal\["export"]]

<a href="#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)%20%3E%20(property)%20type">Link to this property</a>

</details>

[Link to this property](<#(resource)%20d1.database%20%3E%20(model)%20database_export_response%20%3E%20(schema)>)

### Export D1 Database as SQL

Python

HTTPTypeScriptPythonGoTerraform

```
import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
response = client.d1.database.export(
    database_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    account_id="023e105f4ecef8ad9ca31a8372d0c353",
    output_format="polling",
)
print(response.at_bookmark)
```

200 example

```
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "at_bookmark": "at_bookmark",
    "error": "error",
    "messages": [
      "string"
    ],
    "result": {
      "filename": "filename",
      "signed_url": "signed_url"
    },
    "status": "complete",
    "success": true,
    "type": "export"
  },
  "success": true
}
```

##### Returns Examples

200 example

```
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "at_bookmark": "at_bookmark",
    "error": "error",
    "messages": [
      "string"
    ],
    "result": {
      "filename": "filename",
      "signed_url": "signed_url"
    },
    "status": "complete",
    "success": true,
    "type": "export"
  },
  "success": true
}
```