Skip to content
Start here

Export D1 Database as SQL

d1.database.export(strdatabase_id, DatabaseExportParams**kwargs) -> DatabaseExportResponse
POST/accounts/{account_id}/d1/database/{database_id}/export

Returns a URL where the SQL contents of your D1 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
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

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

Example:X-Auth-Email: user@example.com

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

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
ParametersExpand Collapse
account_id: str

Account identifier tag.

maxLength32
database_id: str

D1 database identifier (UUID).

output_format: Literal["polling"]

Specifies that you will poll this endpoint until the export completes

current_bookmark: Optional[str]

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

dump_options: Optional[DumpOptions]
no_data: Optional[bool]

Export only the table definitions, not their contents

no_schema: Optional[bool]

Export only each table's contents, not its definition

tables: Optional[SequenceNotStr[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.

ReturnsExpand Collapse
class DatabaseExportResponse:
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.

error: Optional[str]

Only present when status = 'error'. Contains the error message.

messages: Optional[List[str]]

Logs since the last time you polled

result: Optional[Result]

Only present when status = 'complete'

filename: Optional[str]

The generated SQL filename.

signed_url: Optional[str]

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

status: Optional[Literal["complete", "error"]]
One of the following:
"complete"
"error"
success: Optional[bool]
type: Optional[Literal["export"]]

Export D1 Database as SQL

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)
{
  "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
{
  "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
}