Skip to main content

No project description provided

Project description

示例

1. 准备数据和处理输入输出的函数

# a. 输入数据 (DataFrame格式)
L = [{"user_id": i, "algo": 0, "position": i % 5} for i in range(50)]
df = pd.DataFrame(L)

# b. 处理输入的函数
import json
def makeReqData(json_str):
    # json_str: row.to_json()
    json_str = json.loads(json_str)
    return json_str

# c. 处理输出的函数
def makeResult(r):
    # r: res.json()
    data = r.get("data")
    return data

2. 多线程调用接口保存文件

# 方法一
from multi_request import mreq

m = mreq.MultiRequest()
m.url = "http://127.0.0.1:8080/hello"  # 请求接口, 目前只支持 POST 方法
m.makeReqData = makeReqData  # 你的生成一次请求数据的函数
m.makeResult = makeResult  # (可选) 处理一次返回数据的函数, 生成最终结果字典
m.input_data = df  # 原始请求数据, pandas的 DataFrame 格式
m.parallel_batch_size = 20  # (可选) 并发数,默认: 100
m.save_batch_size = 12  # (可选) 每几个保存一个文件,默认: 5000
m.res_format = "fth"  # (可选) 默认: fth, 支持格式: fth, csv, xlsx
m.res_dir = "data"  # (可选) 保存结果的目录, 默认: ./data
m.run()
# 方法二
from multi_request import mreq

params = {
    "url": "http://127.0.0.1:8080/hello",
    "makeReqData": makeReqData,
    "makeResult": makeResult,
    "input_data": df,
    "parallel_batch_size": 20,
    "save_batch_size": 8,
    "res_format": "csv",
    "res_dir": "tmp_csv",
}
m = mreq.MultiRequest(**params)
m.run()

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

multi_request-0.0.5.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

multi_request-0.0.5-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file multi_request-0.0.5.tar.gz.

File metadata

  • Download URL: multi_request-0.0.5.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.12

File hashes

Hashes for multi_request-0.0.5.tar.gz
Algorithm Hash digest
SHA256 2e2335232fb37c355e4c90b0062715ab95a49416516c60c0b71ab621da657b01
MD5 b848197953757fc25cdb878edef0dae9
BLAKE2b-256 d2d92b8f38d6970894039d74602839a766e60709806bf66f87fbe79906f3e79f

See more details on using hashes here.

File details

Details for the file multi_request-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for multi_request-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 465594adc38b8f559978df09ac07bc0131e7cf24839be9be45839ebb030743a6
MD5 da82d69c308549e464658116172754df
BLAKE2b-256 80e2f2a0abfc91b288e54e1d90f31a6cedd0f4b7cfb95f508ccb21b5861e6167

See more details on using hashes here.

Supported by

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