downloading-batch-export-files
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDownloading batch export files
下载批量导出文件
Use this skill when a user wants a one-off downloadable export of PostHog data.
The export is started and monitored through MCP, but the final file download uses the existing REST endpoint directly.
当用户需要一次性可下载的 PostHog 数据导出时,使用此 skill。
导出通过 MCP 启动和监控,但最终文件下载直接使用现有 REST 端点。
Available MCP tools
可用的 MCP 工具
| Tool | Purpose |
|---|---|
| Start an on-demand export and return the run ID |
| Poll the run status and return file IDs after completion |
Do not rely on a generated MCP tool for the endpoint.
That endpoint is a redirecting file download endpoint, so raw HTTP/download handling is the right interface until MCP has explicit redirect support.
/download/| 工具 | 用途 |
|---|---|
| 启动按需导出并返回 run ID |
| 轮询运行状态,并在完成后返回 file ID |
不要依赖为 端点生成的 MCP 工具。
该端点是一个带重定向的文件下载端点,因此在 MCP 明确支持重定向之前,直接使用原始 HTTP 或下载处理方式是合适的接口。
/download/Workflow
工作流
1. Choose the export shape
1. 选择导出形式
Ask a short clarifying question if the user did not specify the required inputs:
- : one of
model,events,persons, orsessionshogql - and
data_interval_start: ISO 8601 datetimes. Any supplied bound may not be in the future. When both bounds are supplied, they must be ordered and at most one week apart Required fordata_interval_end,events, andpersons. Forsessions, required only for the placeholders the query references. If only one placeholder is referenced, the other bound may be omitted and the one-week limit does not apply.hogql - :
file.formatorParquet; preferJSONLinesfor compact analytics exports andParquetfor line-oriented text processingJSONLines - : optional, one of
file.compression,zstd,gzip,brotli, orlz4. Ifsnappywas chosen as format, onlyJSONLinesandgzipare supported.brotli - : part size in MiB, 1024 by default. A part can go a little over this size. Lower it when the user wants smaller parts, raise it for fewer and bigger ones, or set it to
file.max_size_mbto write a single file of any size.null
For , and are optional event-name filters.
Use them only when the user asks for specific events or wants to omit specific events.
eventsincludeexcludeFor , pass the query as and leave out and .
You may prompt the user to export a slice of data by including a WHERE clause in the HogQL query, for example limiting results from the table by bounding .
Always prefer limiting the data exported to the minimum necessary to solve the user's request.
Every column in the SELECT clause must be a field or have an alias.
This model is in closed beta and is enabled per team.
hogqlhogql_queryincludeexcludeeventstimestampA query can reference the and placeholders.
The export replaces them with the and values, so one query can export any interval.
Supply a bound for every placeholder the query references; a missing bound fails the request.
The bounds only replace placeholders and do not filter anything themselves, so a query without placeholders runs unchanged even when bounds are supplied.
Prefer placeholders over literal dates when the user wants a time range, or several consecutive ranges from the same query.
Compare with and , so consecutive ranges do not export the same row twice.
hogql{data_interval_start}{data_interval_end}data_interval_startdata_interval_end>= {data_interval_start}< {data_interval_end}如果用户未指定所需输入,请提出一个简短的澄清问题:
- :
model、events、persons或sessions之一hogql - 和
data_interval_start:ISO 8601 日期时间。提供的任何边界都不能是未来时间。当同时提供两个边界时,它们必须按先后顺序排列,且间隔最多为一周 对于data_interval_end、events和persons,这两项是必需项。 对于sessions,仅当查询引用相应占位符时才需要。如果查询只引用了一个占位符,则可以省略另一个边界,且不适用一周限制。hogql - :
file.format或Parquet;对于紧凑的分析导出,优先使用JSONLines,对于面向行的文本处理,优先使用ParquetJSONLines - :可选,可选值为
file.compression、zstd、gzip、brotli或lz4。如果选择了snappy格式,则仅支持JSONLines和gzipbrotli - :每个分片的大小,单位为 MiB,默认值为 1024。单个分片可能会略微超过此大小。 当用户希望分片更小时调低该值,希望分片更少、更大时调高该值,或将其设为
file.max_size_mb以写入任意大小的单个文件。null
对于 , 和 是可选的事件名称过滤器。
仅当用户要求特定事件或希望排除特定事件时使用它们。
eventsincludeexclude对于 ,将查询作为 传入,并省略 和 。
可以建议用户通过在 HogQL 查询中加入 子句来导出部分数据,例如通过限定 范围来限制 表中的结果。
始终优先将导出的数据限制在满足用户请求所需的最小范围内。
子句中的每一列都必须是字段或具有别名。
该模型处于 closed beta 阶段,并按团队启用。
hogqlhogql_queryincludeexcludeWHEREtimestampeventsSELECThogql{data_interval_start}{data_interval_end}data_interval_startdata_interval_end>= {data_interval_start}< {data_interval_end}2. Start the export
2. 启动导出
Call with the selected shape.
The response contains an for the export run.
posthog:file-download-batch-exports-createidExample request:
json
{
"model": "events",
"file": {
"format": "JSONLines",
"compression": "gzip"
},
"include": ["$pageview"],
"data_interval_start": "2026-05-25T00:00:00Z",
"data_interval_end": "2026-05-26T00:00:00Z"
}Example request for the model:
hogqljson
{
"model": "hogql",
"file": {
"format": "Parquet"
},
"hogql_query": "SELECT event, timestamp, properties.$current_url AS url FROM events WHERE timestamp >= {data_interval_start} AND timestamp < {data_interval_end}",
"data_interval_start": "2026-05-25T00:00:00Z",
"data_interval_end": "2026-05-26T00:00:00Z"
}根据所选配置调用 。
响应中包含导出运行的 。
posthog:file-download-batch-exports-createid示例请求:
json
{
"model": "events",
"file": {
"format": "JSONLines",
"compression": "gzip"
},
"include": ["$pageview"],
"data_interval_start": "2026-05-25T00:00:00Z",
"data_interval_end": "2026-05-26T00:00:00Z"
}hogqljson
{
"model": "hogql",
"file": {
"format": "Parquet"
},
"hogql_query": "SELECT event, timestamp, properties.$current_url AS url FROM events WHERE timestamp >= {data_interval_start} AND timestamp < {data_interval_end}",
"data_interval_start": "2026-05-25T00:00:00Z",
"data_interval_end": "2026-05-26T00:00:00Z"
}3. Poll until completion
3. 轮询直至完成
Call with the returned .
posthog:file-download-batch-exports-retrieveidStatus handling:
| Status | Action |
|---|---|
| Wait briefly and poll again |
| Read the |
| Stop and report that the run was cancelled |
| Stop and report the |
When , the array contains file UUIDs.
For single-file exports it usually contains one UUID.
For split exports, download every UUID unless the user asked for a specific part.
CompletedfilesA response also carries , the number of rows the run exported.
Report it to the user, because the count is otherwise only visible by opening every file.
Completedrecords_completed使用返回的 调用 。
状态处理:
idposthog:file-download-batch-exports-retrieve| 状态 | 操作 |
|---|---|
| 稍等片刻并再次轮询 |
| 读取 |
| 停止操作并报告该运行已取消 |
| 停止操作并报告 |
状态为 时, 数组包含文件 UUID。
对于单文件导出,该数组通常包含一个 UUID。
对于分片导出,除非用户要求特定分片,否则应下载每个 UUID。
CompletedfilesCompletedrecords_completed4. Optionally, cancel a running export
4. 可选:取消正在运行的导出
If required by the user, a running export can be cancelled by calling with the returned .
posthog:file-download-batch-exports-cancel-createidAn export that has already finished or has already failed may not be cancelled.
After cancelling an export, the may not be used anymore and the export must start again from the beginning. However, you may still use the to retrieve the export status (which will always be ).
ididCancelled如果用户要求,可以调用 并传入返回的 ,从而取消正在运行的导出。
已经完成或已经失败的导出可能无法再取消。
posthog:file-download-batch-exports-cancel-createid取消导出后, 可能无法再用于其他操作,并且必须从头重新开始导出。不过,仍可以使用该 获取导出状态,其状态将始终为 。
ididCancelled5. Download files through REST
5. 通过 REST 下载文件
Use a direct authenticated HTTP request to the existing endpoint:
text
GET /api/projects/{project_id}/file_download_batch_exports/{run_id}/download/{part}/part- a file UUID from the array returned by
filesfile-download-batch-exports-retrieve - a zero-based file index, ordered by key
If there is only one file, this also works without :
parttext
GET /api/projects/{project_id}/file_download_batch_exports/{run_id}/download/Let the HTTP client follow the redirect, or inspect the header if you need the temporary signed URL.
Use the same PostHog authentication context as other API calls.
Location对现有端点发起直接经过身份验证的 HTTP 请求:
text
GET /api/projects/{project_id}/file_download_batch_exports/{run_id}/download/{part}/part- 返回的
file-download-batch-exports-retrieve数组中的文件 UUIDfiles - 从零开始的文件索引,按 排序
key
如果只有一个文件,也可以不提供 :
parttext
GET /api/projects/{project_id}/file_download_batch_exports/{run_id}/download/可以让 HTTP 客户端自动跟随重定向,也可以在需要获取临时签名 URL 时检查 标头。
使用与其他 API 调用相同的 PostHog 身份验证上下文。
Location6. Save, do not print, file contents
6. 保存文件内容,不要打印
Treat the result as a file download, not a chat response.
Parquet is binary and must be written as bytes.
JSONLines may still be large; save it to a file rather than pasting the contents unless the user explicitly asks for a tiny sample.
Use a filename that includes the model, run ID, and part identifier when possible, for example:
text
posthog-events-<run_id>-<part>.jsonl.gz
posthog-persons-<run_id>-<part>.parquet将结果视为文件下载,而不是聊天回复。
Parquet 是二进制文件,必须以字节形式写入。
JSONLines 也可能很大;应将其保存到文件,而不是粘贴内容,除非用户明确要求提供一个小样本。
尽可能使用包含 model、run ID 和 part 标识符的文件名,例如:
text
posthog-events-<run_id>-<part>.jsonl.gz
posthog-persons-<run_id>-<part>.parquetImportant notes
重要说明
- The maximum export interval is one week. Split longer user requests into separate export runs or ask which week to export.
- The model is in closed beta and is enabled per team. A permission error that says HogQL batch exports are not enabled means the team does not have the beta. Report that instead of retrying with a different query, and tell the user they can contact PostHog support to request access.
hogql - The model runs under stricter resource limits than the other models, because user queries are less predictable. If an export fails on memory, execution time, or bytes read, suggest narrowing the query with a WHERE clause instead of retrying it unchanged.
hogql - The model accepts an optional
hogqlobject. Each modifier in it overrides the project HogQL modifier with the same name for this export only, and the project modifiers apply to all others. Unless the project sets thehogql_modifiersmodifier,convertToProjectTimezonecolumns come out in UTC, so passtimestampwhen the user wants them in the project timezone. Pass the same{"convertToProjectTimezone": true}tohogql_modifiers, so that the count matches the export.posthog:file-download-batch-exports-count-rows-create - A run can briefly report after completion while file records are being created. Poll again instead of failing immediately.
Running - Download URLs are temporary. If a URL expires, call the REST download endpoint again for a fresh redirect.
- Do not send the signed URL to unrelated services unless the user explicitly asks; it grants temporary access to the exported file.
- If the user wants all parts of a split export, iterate over every UUID in ; do not assume part
filesis enough.0 - Large batch exports may take a few minutes or even longer to complete. Suggest to the user that they can speed-up their download by including only certain events or narrowing the date range.
- 最大导出时间区间为一周。对于更长的用户请求,请拆分为多个导出运行,或询问用户希望导出哪一周的数据。
- 模型处于 closed beta 阶段,并按团队启用。如果出现权限错误,提示 HogQL 批量导出未启用,则表示该团队没有此 beta 功能的访问权限。应报告此情况,而不是换用其他查询重试,并告知用户可以联系 PostHog support 申请访问权限。
hogql - 由于用户查询的可预测性较低,模型采用比其他模型更严格的资源限制。如果导出因内存、执行时间或读取字节数而失败,建议使用
hogql子句缩小查询范围,而不是原样重试。WHERE - 模型接受可选的
hogql对象。其中的每个修改器仅在本次导出中覆盖项目级 HogQL 中同名的修改器,项目级修改器仍应用于所有其他导出。除非项目设置了hogql_modifiers修改器,否则convertToProjectTimezone列将以 UTC 输出;因此,当用户希望使用项目时区时,请传入timestamp。将相同的{"convertToProjectTimezone": true}传给hogql_modifiers,以确保计数与导出一致。posthog:file-download-batch-exports-count-rows-create - 在导出完成后、文件记录仍在创建期间,运行可能短暂显示为 。应再次轮询,而不是立即判定失败。
Running - 下载 URL 是临时的。如果 URL 过期,请再次调用 REST 下载端点以获取新的重定向。
- 除非用户明确要求,否则不要将签名 URL 发送给无关服务,因为它会授予对导出文件的临时访问权限。
- 如果用户需要分片导出的所有部分,请遍历 中的每个 UUID,不要假设分片
files就足够了。0 - 大型批量导出可能需要几分钟甚至更长时间才能完成。可以建议用户仅包含特定事件或缩小日期范围,以加快下载速度。