rusty-req 0.2.0__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rusty-req might be problematic. Click here for more details.
rusty_req/__init__.py
ADDED
|
Binary file
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rusty-req
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Classifier: Programming Language :: Python
|
|
5
|
+
Classifier: Programming Language :: Python :: 3
|
|
6
|
+
Classifier: Programming Language :: Rust
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Summary: High-performance async HTTP client built with Rust for Python.
|
|
10
|
+
Author-email: KAY53N <kaysen820@gmail.com>
|
|
11
|
+
License: MIT
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
14
|
+
Project-URL: Homepage, https://github.com/KAY53N/rusty-req
|
|
15
|
+
Project-URL: Repository, https://github.com/KAY53N/rusty-req
|
|
16
|
+
Project-URL: Bug Tracker, https://github.com/KAY53N/rusty-req/issues
|
|
17
|
+
Project-URL: Documentation, https://github.com/KAY53N/rusty-req#readme
|
|
18
|
+
|
|
19
|
+
# rusty-req
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
基于 Rust + Python 的高性能异步请求库,适用于需要批量发送 HTTP 请求的场景。通过 Rust 实现并发请求逻辑,并通过 [maturin](https://github.com/PyO3/maturin) 封装为 Python 模块,兼具性能与易用性。
|
|
23
|
+
|
|
24
|
+
## 🔧 安装
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install rusty-req
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
或从源码构建:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
maturin build --release
|
|
34
|
+
pip install target/wheels/rusty_req-*.whl
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 开发调试
|
|
38
|
+
```
|
|
39
|
+
cargo watch -s "maturin develop"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 🚀 功能特点
|
|
43
|
+
|
|
44
|
+
- 批量异步发送 HTTP 请求(支持 GET / POST)
|
|
45
|
+
- 支持自定义 headers / params / timeout / tag
|
|
46
|
+
- 支持全局超时时间控制(`total_timeout`)
|
|
47
|
+
- 返回响应内容、错误信息、Meta 数据
|
|
48
|
+
- 使用 Rust + Tokio 提升吞吐能力
|
|
49
|
+
|
|
50
|
+
## 📦 使用示例
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import asyncio
|
|
54
|
+
import time
|
|
55
|
+
import rusty_req
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def main():
|
|
59
|
+
# Using JSONPlaceholder - a free fake API for testing
|
|
60
|
+
requests = [
|
|
61
|
+
rusty_req.RequestItem(
|
|
62
|
+
url="https://httpbin.org/delay/2",
|
|
63
|
+
method="GET",
|
|
64
|
+
timeout=2.9,
|
|
65
|
+
tag=f"json-test-{i}",
|
|
66
|
+
)
|
|
67
|
+
for i in range(100) # 100 concurrent requests
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
# Disable debug output
|
|
71
|
+
rusty_req.set_debug(False)
|
|
72
|
+
|
|
73
|
+
print("🚀 Starting 100 concurrent JSON API requests...")
|
|
74
|
+
start_time = time.perf_counter()
|
|
75
|
+
|
|
76
|
+
responses = await rusty_req.fetch_requests(
|
|
77
|
+
requests,
|
|
78
|
+
total_timeout=3.0
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
total_time = time.perf_counter() - start_time
|
|
82
|
+
|
|
83
|
+
# Process results
|
|
84
|
+
success = 0
|
|
85
|
+
failed = 0
|
|
86
|
+
status_codes = {}
|
|
87
|
+
response_times = []
|
|
88
|
+
|
|
89
|
+
for r in responses:
|
|
90
|
+
if r.get("exception"):
|
|
91
|
+
failed += 1
|
|
92
|
+
else:
|
|
93
|
+
meta = r.get('meta', {})
|
|
94
|
+
status_code = meta.get("status_code", 0)
|
|
95
|
+
process_time = meta.get("process_time", 0)
|
|
96
|
+
|
|
97
|
+
status_codes[status_code] = status_codes.get(status_code, 0) + 1
|
|
98
|
+
response_times.append(process_time)
|
|
99
|
+
success += 1
|
|
100
|
+
|
|
101
|
+
# Calculate statistics
|
|
102
|
+
avg_response_time = sum(response_times) / len(response_times) if response_times else 0
|
|
103
|
+
min_response_time = min(response_times) if response_times else 0
|
|
104
|
+
max_response_time = max(response_times) if response_times else 0
|
|
105
|
+
req_per_sec = success / total_time if total_time > 0 else 0
|
|
106
|
+
|
|
107
|
+
print("\n📊 Load Test Results:")
|
|
108
|
+
print(f"⏱️ Total time: {total_time:.2f}s")
|
|
109
|
+
print(f"📈 Requests/sec: {req_per_sec:.1f}")
|
|
110
|
+
print(f"✅ Successful: {success}")
|
|
111
|
+
print(f"⚠️ Failed: {failed}")
|
|
112
|
+
print(f"🔄 Status codes: {status_codes}")
|
|
113
|
+
print(
|
|
114
|
+
f"⏳ Response times - Avg: {avg_response_time:.4f}s, Min: {min_response_time:.4f}s, Max: {max_response_time:.4f}s")
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
if __name__ == "__main__":
|
|
118
|
+
asyncio.run(main())
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 🧱 数据结构说明
|
|
122
|
+
|
|
123
|
+
### `RequestItem` 参数
|
|
124
|
+
|
|
125
|
+
| 字段名 | 类型 | 必须 | 说明 |
|
|
126
|
+
|------------|------------------|------|----------------------------------------|
|
|
127
|
+
| `url` | `str` | ✅ | 请求地址 |
|
|
128
|
+
| `method` | `str` | ✅ | 请求方法(`"GET"` 或 `"POST"`) |
|
|
129
|
+
| `params` | `dict` / `None` | 否 | 查询参数(GET)或表单数据(POST) |
|
|
130
|
+
| `headers` | `dict` / `None` | 否 | 自定义请求头 |
|
|
131
|
+
| `timeout` | `float` | ✅ | 单个请求超时(秒) |
|
|
132
|
+
| `tag` | `str` | 否 | 标记请求的来源、编号等辅助信息 |
|
|
133
|
+
|
|
134
|
+
### 返回格式
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
{
|
|
138
|
+
"response": "{\"code\":403,\"msg\":\"Method Not Allowed.\"}",
|
|
139
|
+
"meta": {
|
|
140
|
+
"process_time": "0.2439",
|
|
141
|
+
"request_time": "2025-07-29 19:17:11 -> 2025-07-29 19:17:11",
|
|
142
|
+
"tag": "test-baidu1"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## 📑 Headers 示例
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
RequestItem(
|
|
151
|
+
url="https://httpbin.org/headers",
|
|
152
|
+
method="GET",
|
|
153
|
+
headers={
|
|
154
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
155
|
+
"Connection": "keep-alive",
|
|
156
|
+
"X-Test-Header": "ChatGPT"
|
|
157
|
+
},
|
|
158
|
+
timeout=5.0
|
|
159
|
+
)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## 📄 License
|
|
163
|
+
|
|
164
|
+
MIT License
|
|
165
|
+
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
rusty_req-0.2.0.dist-info/METADATA,sha256=6uCkTEUVPt0ltCe4ElmdTF_aQfUZbUnk2Zpz3170fdw,4979
|
|
2
|
+
rusty_req-0.2.0.dist-info/WHEEL,sha256=Us6FjEGduB1m-stBmIOMafV3E7_L55J4E4CHCF69Kmg,94
|
|
3
|
+
rusty_req/__init__.py,sha256=XfQUTvk1FFMD7UyS817WUsedia2I8IeuvVba4QktOX0,119
|
|
4
|
+
rusty_req/rusty_req.cp39-win_amd64.pyd,sha256=2Vi2-xymmBbT-4XYc4Be6poG5RvgwENrSoM0jcnP-tY,3817984
|
|
5
|
+
rusty_req-0.2.0.dist-info/RECORD,,
|