Skip to main content

一个用于批量处理数据并发送HTTP请求的Python工具包

Project description

批量数据测试工具 (Batch Data Test Tool)

一个用于批量处理数据并发送HTTP请求的Python工具包。支持CSV和Excel文件读取,提供交互式Jupyter界面,方便进行批量API测试。

功能特性

  • 📊 数据文件支持: 支持CSV和Excel文件读取
  • 🔄 批量处理: 批量发送HTTP请求并处理响应
  • 🎛️ 交互式界面: 基于Jupyter Widgets的友好用户界面
  • 📈 数据预览: 实时预览处理结果
  • 💾 结果导出: 支持将处理结果导出为Excel文件
  • 🛠️ 灵活配置: 支持自定义API端点和请求参数

安装

pip install batch-data-test-tool

快速开始

在Jupyter Notebook中使用

from batch_data_test_tool import simple_start

# 启动交互式界面
simple_start()

作为命令行工具使用

batch-test-tool

使用示例

1. 基本用法

from batch_data_test_tool import (
    read_dataframe_from_file,
    sync_http_request,
    structure_request_params
)
import json

# 读取数据文件
df = read_dataframe_from_file('data/test.xlsx')

# 配置API
api_url = 'http://your-api-endpoint.com/api'
headers = {
    "Content-Type": "application/json",
    "User-Agent": "BatchDataTestTool/1.0"
}

# 处理单条数据
input_data = df.iloc[0]['your_column']
params = structure_request_params(input_data, 'async_sales_qa')
response = sync_http_request(api_url, json.dumps(params), headers)

2. 批量处理

from batch_data_test_tool.apps.simple_start import process_batch_http_request

# 批量处理数据
results = process_batch_http_request(
    df=df,
    input_field_name='your_column',
    stream_parser=True,
    data_processing_methods=[],
    api_url=api_url,
    api_type='async_sales_qa',
    headers=headers
)

API 参考

核心函数

read_dataframe_from_file(filepath)

从文件中读取DataFrame,支持CSV和Excel格式。

参数:

  • filepath (str): 文件路径

返回:

  • pandas.DataFrame: 读取的数据

sync_http_request(url, request_json_data, headers)

发送同步HTTP请求。

参数:

  • url (str): 请求URL
  • request_json_data (str): JSON格式的请求数据
  • headers (dict): 请求头

返回:

  • requests.Response: HTTP响应对象

structure_request_params(data, api_type)

根据API类型构建请求参数。

参数:

  • data: 输入数据
  • api_type (str): API类型

返回:

  • dict: 构建的请求参数

数据预处理

clean_dataframe_for_json(df)

清理DataFrame中的NaN值,使其能够正确序列化为JSON。

join_list_with_delimiter(list_data, delimiter)

使用分隔符连接列表数据。

配置

API类型配置

目前支持的API类型:

  • async_sales_qa: 异步销售问答API

数据预处理方法

  • join_list_with_delimiter: 列表数据连接

开发

安装开发依赖

pip install -e ".[dev]"

运行测试

pytest

代码格式化

black batch_data_test_tool/

许可证

本项目采用 MIT 许可证。详见 LICENSE 文件。

贡献

欢迎提交Issue和Pull Request!

更新日志

v1.0.0

  • 初始版本发布
  • 支持CSV和Excel文件读取
  • 提供交互式Jupyter界面
  • 支持批量HTTP请求处理
  • 支持结果导出

支持

如果您遇到任何问题或有建议,请:

  1. 查看 文档
  2. 搜索 已知问题
  3. 创建新的 Issue

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

batch_data_test_tool-1.0.0.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

batch_data_test_tool-1.0.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file batch_data_test_tool-1.0.0.tar.gz.

File metadata

  • Download URL: batch_data_test_tool-1.0.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for batch_data_test_tool-1.0.0.tar.gz
Algorithm Hash digest
SHA256 baf19f2ef876ef940820850dd82ae77f8b3a37d8217657f32f8adaa86f249b0a
MD5 197941ad1c879baee7c9466a4c3181bb
BLAKE2b-256 009a2949b7d69735b0ecb15d9a55d2bf7c1b2cb7d582bced08357e7f30db13bd

See more details on using hashes here.

File details

Details for the file batch_data_test_tool-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for batch_data_test_tool-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c7089e3ef4720b2e4ace5a546e94f7ff361bd49c6db5c5a5a74dea1639cebf7
MD5 11b7e05f94149955a88c9bfe238fb725
BLAKE2b-256 b176d7ab07ae92674f010ca7c002763fca6a12fe8fd74360eb94d510ee304227

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page