Search results as a CSV file
On this page
Download the program (Python)
- search_to_csv.py9.6 KB
Example output
What the program wrote when it ran against the API. The first rows are shown here; download the file for the whole of it.
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | id | date | date_kind | published | issued | implemented | added | type | level | topic | issuer | title_en | headline_zh | document_number | summary_en | teaser_zh | rc |
| 2 | 6ab8049bed91061889a10174 | 2026-09-27 | added | 2026-09-27 | opinion/plan | centre | tech | 工业和信息化部 | 1. The 2016 Project Application Guide for the National Major Science and Technology Special Project "Core Electronic Devices, High-End General Purpose Chips an… | 1 、《国家科技重大专项“核心电子器件、高端通用芯片及基础软件产品”2016年课题申报指南》 | This document is the 2016 topic application guide for the National Major Science and Technology Special Program's Core Electronic Devices, High-End General Chi… | 附件1 国家科技重大专项 核心电子器件、高端通用芯片及基础软件产品 2016年课题申报指南 课题申报单位应根据本指南中考核指标的要求,以及课题实施的实际情况,在课题申报书中进一步细化考核指标(包括技术指标和产业化指标)。申报书中的考核指标将作为课题评审及任务合同书签订的重要依据。课题申报单位应根据课题目标和任务的要求… | https://reconnectchina.org/items/6ab8049bed91061889a10174/1-the-2016-project-application-guide-for-the-national-major-science-and-technology-special-project | ||||
| 3 | 6aa7e6679220a9eac4c8bd27 | 2026-09-14 | published | 2026-09-14 | 2026-09-06 | 2026-09-14 | 2026-09-14 | notice/announcement | cities | tech | 北京市 | Notice of the Beijing Economic-Technological Development Zone Management Committee on Issuing the "Several Measures of Beijing Economic-Technological Developme… | 北京经济技术开发区管理委员会关于印发《北京经济技术开发区关于加快新材料产业创新发展的若干措施》的通知 | 京技管发〔2026〕13号 | The document, issued by the Beijing Economic and Technological Development Zone Management Committee on September 6, 2026, announces the “Several Measures for … | 京技管发〔2026〕13号 工委、管委会各机构,驻区各职能机构,各重点国有企业: 现将《北京经济技术开发区关于加快新材料产业创新发展的若干措施》印发给你们,请结合实际,认真抓好贯彻落实。 北京经济技术开发区管理委员会 2026年9月6日 (此件公开发布) 北京经济技术开发区关于加快新材料产业创新发展的若干措施 新材料… | https://reconnectchina.org/items/6aa7e6679220a9eac4c8bd27/notice-of-the-beijing-economic-technological-development-zone-management-committee-on-issuing-the |
| 4 | 6ab9963bed91061889a133d0 | 2026-09-28 | added | 2026-09-28 | notice/announcement | provinces | other | 浙江省 | Zhejiang Provincial Government Office Document No. 22 of 2019 | 浙政办发〔2019〕22号 | 浙政办发〔2019〕22号 | The General Office of the People's Government of Zhejiang Province issued the Action Plan for Accelerating the Development of the New Materials Industry (2019–… | 浙江省人民政府办公厅文件 浙政办发〔2019〕22 号 欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗欗 浙江省人民政府办公厅关于印发 浙江省加快新材料产业发展行动计划 ( 2019 —2022 年) 的通知 各市、县(市、区)人民政府,省政府直属各单位: 《浙江省加快新材料产业… | https://reconnectchina.org/items/6ab9963bed91061889a133d0/zhejiang-provincial-government-office-document-no-22-of-2019 | |||
| 5 | 6ab66c7ced91061889a0d547 | 2026-09-25 | added | 2026-09-25 | notice/announcement | centre | trade | 财政部 | Annex: Fourth Extension List of Excluded Goods Subject to Additional Tariffs on the United States | 附件 对美加征关税商品第四次排除延期清单 | The document is the fourth extension list of exclusions from the extra duties imposed on US goods, listing 79 items. It is an attachment to a notice from the M… | 附件 对美加征关税商品第四次排除延期清单 序号 EX① 税则号列② 商品名称 1 25070010 高岭土 2 25120010 硅藻土 3 25199091 化学纯氧化镁 4 25262020 已破碎或已研粉的天然滑石 5 25309020 稀土金属矿 6 26161000 银矿砂及其精矿 7 ex 2616900… | https://reconnectchina.org/items/6ab66c7ced91061889a0d547/annex-fourth-extension-list-of-excluded-goods-subject-to-additional-tariffs-on-the-united-states | ||||
| 6 | 6ab6737fed91061889a0d5fb | 2026-09-25 | added | 2026-09-25 | notice/announcement | centre | trade | 财政部 | Annex: The Thirteenth Extension List of Exclusions for Goods Subject to Additional Tariffs on the United States | 附件 对美加征关税商品第十三次排除延期清单 | The document is the 13th extension list of exclusions from the additional tariffs on US goods, issued by the Ministry of Finance. It contains 94 entries of goo… | 附件 对美加征关税商品第十三次排除延期清单 序号 1 2 3 4 5 6 EX① ex 税则号列② 03063610 04041000 12141000 12149000 23012010 27101299 7 ex 27101919 ex ex 8 9 34024200 34031900 34039900 商品名称… | https://reconnectchina.org/items/6ab6737fed91061889a0d5fb/annex-the-thirteenth-extension-list-of-exclusions-for-goods-subject-to-additional-tariffs-on-the | ||||
| 7 | 6ab672f3ed91061889a0d5d3 | 2026-09-25 | added | 2026-09-25 | notice/announcement | centre | trade | 财政部 | Annex: Ninth Extension List of Exclusions for Goods Subject to Additional Tariffs on the United States | 附件 对美加征关税商品第九次排除延期清单 | The document is the "Attachment: Ninth Extension List of Exclusions for Goods Subject to Additional Tariffs on the United States." It lists 94 goods, each with… | 附件 对美加征关税商品第九次排除延期清单 序号 1 2 3 4 5 6 EX① ex 税则号列② 03063610 04041000 12141000 12149000 23012010 27101299 7 ex 27101919 ex ex 8 9 34024200 34031900 34039900 商品名称 … | https://reconnectchina.org/items/6ab672f3ed91061889a0d5d3/annex-ninth-extension-list-of-exclusions-for-goods-subject-to-additional-tariffs-on-the-united |
What it does
This program runs one search, pages through every result and writes one row per document to a CSV file: its dates, what kind of document it is, who issued it, its title in English and Chinese, a short English summary and the link back to ReConnect China. From there you count, plot, write a report or train a model, in whatever tool you like.
A CSV file is plain text, one row after another. Excel opens it, pandas loads it, Python reads
it with its built-in csv module, and most other languages have a library for it. Use one
rather than splitting the text at line breaks yourself: the English summaries in this file run
over several lines inside a single cell.
A CSV file can also be written and read a row at a time. That is why this program writes each page of results as it arrives rather than collecting them first: the file can grow larger than your computer's memory, and a program that reads it row by row still gets through it. Excel does not read it that way, and has a limit of its own: see Opening the file in Excel below.
What you need
Python 3.11 or later, and the packages this program uses:
pip install reconnectchinaThen run python search_to_csv.py. With uv, uv run search_to_csv.py installs what it needs by itself.
import csv
import sys
from datetime import date, datetime, timedelta, timezone
from reconnectchina import (
Client,
ConsolePrompt,
ScopeId,
SearchFirstPage,
SearchPage,
SearchParameters,
Summary,
Type,
)What to search for
Change these to your own search. from_ says how far back to go: without it, a search covers
the last seven days. The terms and the dates are written as on the API documentation's Terms
and Instants pages. page_size is how many results each page holds: 100 rather than the
default ten reads the same results in a tenth of the requests.
type_in keeps to the kinds of document that set or announce policy: laws and decrees,
regulations, notices and announcements, opinions and plans. ReConnect China's classifier
assigns each document its kind, as the API documentation's Type explains. Leave type_in
out to search every kind, news and reports included.
To run a search you saved, set SAVED_SEARCH to its name. PARAMETERS is then not used.
SCOPE is where it was saved: account for your own searches, organization for one a
colleague shared with everyone in your organization (see Saved searches from a keyword
workbook).
The file is named for the day the program runs, such as search-2026-10-01.csv, so a run
never overwrites an earlier day's results and every file says when it was made.
POLICY: list[Type] = ["law/decree", "regulation", "notice/announcement", "opinion/plan"]
PARAMETERS = SearchParameters(
term="半导体 || semiconductor",
strategy="body",
type_in=POLICY,
from_="now-1M",
page_size=100,
)
SAVED_SEARCH: str | None = None
SCOPE: ScopeId = "account"
OUTPUT = f"search-{date.today()}.csv"Dates in China
The API gives every date as an instant in UTC. A date a source page prints, such as 12 May 2026, is midnight in China, which is 16:00 UTC on 11 May. So the calendar date is taken in China's time zone, UTC+8, or every printed date comes out a day early. China has kept that one offset since 1991, so a fixed offset is enough.
CHINA = timezone(timedelta(hours=8))
def china_date(instant: datetime | None) -> str:
"""The calendar date in China, such as `2026-05-12`, or nothing when there is no date."""
if instant is None:
return ""
return instant.astimezone(CHINA).date().isoformat()One row per document
Every document has a date, one of the dates in the columns after it. date_kind says which:
published, issued, implemented, or added, the day ReConnect China collected the
document, which can be later than the document's own date. It sits in the next column, so
that anyone reading the file later can tell a publication date from the day the document was
collected.
document_number is the number the document bears (文号), such as
国办发〔2026〕12号, when it has one: what a citation of a Chinese government document gives.
The English summary can run to several paragraphs and lists, and its line breaks carry them,
so it goes into its cell as it is. A Chinese headline can have several lines, joined into one
cell. rc is the link to the document on ReConnect China, and it is how you cite it.
Your organization's agreement can leave out some fields of a document, such as its Chinese
text. A field left out is absent, and the document's hidden names it. Its cell stays empty,
and so does a field the document does not have, such as a teaser.
COLUMNS = [
"id",
"date",
"date_kind",
"published",
"issued",
"implemented",
"added",
"type",
"level",
"topic",
"issuer",
"title_en",
"headline_zh",
"document_number",
"summary_en",
"teaser_zh",
"rc",
]
def row(summary: Summary) -> list[str]:
zh = summary.zh
return [
summary.id,
china_date(summary.date),
summary.date_kind,
china_date(summary.dates.published),
china_date(summary.dates.issued),
china_date(summary.dates.implemented),
china_date(summary.dates.added),
summary.type,
summary.level,
summary.topic,
summary.issuer,
summary.en.title,
"".join(zh.headline or ()) if zh else "",
summary.document_number or "",
summary.en.summary or "",
(zh.teaser or "") if zh else "",
summary.rc,
]Paging through the results
A search answers with its first page and, when there are more, a next value to ask for the
following one. The loop below goes on until a page comes without next.
Two things can happen on a long run. New documents arrive while you page, which can move a
document you already have onto the next page, so a document seen before is skipped. And your
organization's agreement sets how deep a search can page: client.get_me().agreement.depth
says how many results. The page that reaches that depth carries no next either, but it
carries truncated, whose reason is depth, so the program tells you that paging stopped
before the end. Treat any truncated that way, whatever its reason: there are more results.
Narrowing the search, for instance to a shorter time, gets you the rest.
The file is written as UTF-8 with a byte order mark (utf-8-sig). Excel needs the mark to
show Chinese text as Chinese, and Python and pandas read it with or without.
def main(client: Client) -> None:
page: SearchFirstPage | SearchPage
if SAVED_SEARCH is None:
page = client.search(PARAMETERS)
else:
page = client.run_saved_search(SCOPE, SAVED_SEARCH)
hits = page.hits
seen: set[str] = set()
with open(OUTPUT, "w", newline="", encoding="utf-8-sig") as file:
writer = csv.writer(file)
writer.writerow(COLUMNS)
while True:
for summary in page.summaries:
if summary.id not in seen:
seen.add(summary.id)
writer.writerow(row(summary))
if page.next is None:
break
page = client.continue_search(page.next)
print(f"{len(seen)} documents written to {OUTPUT}")
if page.truncated is not None:
print(
f"The search has {hits} results, and paging stopped before the end "
f"({page.truncated.reason}). Narrow the search to get the rest.",
file=sys.stderr,
)Logging in and running it
The program asks you to log in every time it runs: it prints a link, you open it and log in with your reconnectchina.org account, and the login ends with the program. Nothing is saved, so there is no secret to keep safe.
A program that runs again and again, or with nobody at the keyboard, can keep a login in a file instead: see Creating a token for a script in the API documentation.
if __name__ == "__main__":
# The API is for partner organizations. To try the example on the sandbox, which every
# account in an organization can use, pass server="https://sandbox.api.reconnectchina.org".
client = Client(prompt=ConsolePrompt())
main(client)Opening the file in Excel
The headlines come from the internet and summaries from ML models, and a CSV file cannot say
that a cell is text. When you open a CSV file in Excel by double-clicking it, Excel treats a
cell starting with =, +, - or @ as a formula and runs it, and a formula can fetch
web pages or change what a cell shows. This program writes the text as it is, since changing
it would change it for every other program too.
So in Excel, import the file rather than opening it: Data → From Text/CSV, choose the file, then Load. That reads every cell as a value. The workbook examples write an Excel file directly, where text is always text.
An Excel sheet holds at most 1,048,576 rows, and Excel keeps the whole sheet in memory. A search without a term, or over a long time, can find more documents than that. For a file that size, load it with pandas, or in Excel on Windows choose Load To… instead of Load and add it to the Data Model, which has no such row limit and which PivotTables can count from.