rusty-req 0.1.1__tar.gz → 0.1.3__tar.gz

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.

@@ -85,9 +85,9 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
85
85
 
86
86
  [[package]]
87
87
  name = "cc"
88
- version = "1.2.27"
88
+ version = "1.2.30"
89
89
  source = "registry+https://github.com/rust-lang/crates.io-index"
90
- checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc"
90
+ checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7"
91
91
  dependencies = [
92
92
  "shlex",
93
93
  ]
@@ -309,9 +309,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
309
309
 
310
310
  [[package]]
311
311
  name = "h2"
312
- version = "0.3.26"
312
+ version = "0.3.27"
313
313
  source = "registry+https://github.com/rust-lang/crates.io-index"
314
- checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8"
314
+ checksum = "0beca50380b1fc32983fc1cb4587bfa4bb9e78fc259aad4a0032d2080309222d"
315
315
  dependencies = [
316
316
  "bytes",
317
317
  "fnv",
@@ -556,6 +556,17 @@ version = "2.0.6"
556
556
  source = "registry+https://github.com/rust-lang/crates.io-index"
557
557
  checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
558
558
 
559
+ [[package]]
560
+ name = "io-uring"
561
+ version = "0.7.8"
562
+ source = "registry+https://github.com/rust-lang/crates.io-index"
563
+ checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013"
564
+ dependencies = [
565
+ "bitflags 2.9.1",
566
+ "cfg-if",
567
+ "libc",
568
+ ]
569
+
559
570
  [[package]]
560
571
  name = "ipnet"
561
572
  version = "2.11.0"
@@ -902,9 +913,9 @@ checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
902
913
 
903
914
  [[package]]
904
915
  name = "redox_syscall"
905
- version = "0.5.13"
916
+ version = "0.5.15"
906
917
  source = "registry+https://github.com/rust-lang/crates.io-index"
907
- checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
918
+ checksum = "7e8af0dde094006011e6a740d4879319439489813bd0bcdc7d821beaeeff48ec"
908
919
  dependencies = [
909
920
  "bitflags 2.9.1",
910
921
  ]
@@ -949,20 +960,6 @@ dependencies = [
949
960
  "winreg",
950
961
  ]
951
962
 
952
- [[package]]
953
- name = "rust_http_client"
954
- version = "0.1.0"
955
- dependencies = [
956
- "chrono",
957
- "futures",
958
- "once_cell",
959
- "pyo3",
960
- "pyo3-asyncio",
961
- "reqwest",
962
- "serde_json",
963
- "tokio",
964
- ]
965
-
966
963
  [[package]]
967
964
  name = "rustc-demangle"
968
965
  version = "0.1.25"
@@ -971,15 +968,15 @@ checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f"
971
968
 
972
969
  [[package]]
973
970
  name = "rustix"
974
- version = "1.0.7"
971
+ version = "1.0.8"
975
972
  source = "registry+https://github.com/rust-lang/crates.io-index"
976
- checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266"
973
+ checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8"
977
974
  dependencies = [
978
975
  "bitflags 2.9.1",
979
976
  "errno",
980
977
  "libc",
981
978
  "linux-raw-sys",
982
- "windows-sys 0.59.0",
979
+ "windows-sys 0.60.2",
983
980
  ]
984
981
 
985
982
  [[package]]
@@ -997,6 +994,20 @@ version = "1.0.21"
997
994
  source = "registry+https://github.com/rust-lang/crates.io-index"
998
995
  checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d"
999
996
 
997
+ [[package]]
998
+ name = "rusty-req"
999
+ version = "0.1.3"
1000
+ dependencies = [
1001
+ "chrono",
1002
+ "futures",
1003
+ "once_cell",
1004
+ "pyo3",
1005
+ "pyo3-asyncio",
1006
+ "reqwest",
1007
+ "serde_json",
1008
+ "tokio",
1009
+ ]
1010
+
1000
1011
  [[package]]
1001
1012
  name = "ryu"
1002
1013
  version = "1.0.20"
@@ -1063,9 +1074,9 @@ dependencies = [
1063
1074
 
1064
1075
  [[package]]
1065
1076
  name = "serde_json"
1066
- version = "1.0.140"
1077
+ version = "1.0.141"
1067
1078
  source = "registry+https://github.com/rust-lang/crates.io-index"
1068
- checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
1079
+ checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3"
1069
1080
  dependencies = [
1070
1081
  "itoa",
1071
1082
  "memchr",
@@ -1208,17 +1219,19 @@ dependencies = [
1208
1219
 
1209
1220
  [[package]]
1210
1221
  name = "tokio"
1211
- version = "1.45.1"
1222
+ version = "1.46.1"
1212
1223
  source = "registry+https://github.com/rust-lang/crates.io-index"
1213
- checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779"
1224
+ checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17"
1214
1225
  dependencies = [
1215
1226
  "backtrace",
1216
1227
  "bytes",
1228
+ "io-uring",
1217
1229
  "libc",
1218
1230
  "mio",
1219
1231
  "parking_lot",
1220
1232
  "pin-project-lite",
1221
1233
  "signal-hook-registry",
1234
+ "slab",
1222
1235
  "socket2",
1223
1236
  "tokio-macros",
1224
1237
  "windows-sys 0.52.0",
@@ -1,6 +1,6 @@
1
1
  [package]
2
- name = "rust_http_client"
3
- version = "0.1.0"
2
+ name = "rusty-req"
3
+ version = "0.1.3"
4
4
  edition = "2021"
5
5
 
6
6
  [dependencies]
@@ -0,0 +1,129 @@
1
+ Metadata-Version: 2.4
2
+ Name: rusty-req
3
+ Version: 0.1.3
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: kaysen <kaysen820@gmail.com>
11
+ License: MIT
12
+ Requires-Python: >=3.7
13
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
14
+ Project-URL: Homepage, https://github.com/kaysen820/rusty-req
15
+ Project-URL: Repository, https://github.com/kaysen820/rusty-req
16
+ Project-URL: Bug Tracker, https://github.com/kaysen820/rusty-req/issues
17
+ Project-URL: Documentation, https://github.com/kaysen820/rusty-req#readme
18
+
19
+ # rusty-req
20
+
21
+ 基于 Rust + Python 的高性能异步请求库,适用于需要批量发送 HTTP 请求的场景。通过 Rust 实现并发请求逻辑,并通过 [maturin](https://github.com/PyO3/maturin) 封装为 Python 模块,兼具性能与易用性。
22
+
23
+ ## 🔧 安装
24
+
25
+ ```bash
26
+ pip install rusty-req
27
+ ```
28
+
29
+ 或从源码构建:
30
+
31
+ ```bash
32
+ maturin build --release
33
+ pip install target/wheels/rusty_req-*.whl
34
+ ```
35
+
36
+ ## 🚀 功能特点
37
+
38
+ - 批量异步发送 HTTP 请求(支持 GET / POST)
39
+ - 支持自定义 headers / params / timeout / tag
40
+ - 支持全局超时时间控制(`total_timeout`)
41
+ - 返回响应内容、错误信息、Meta 数据
42
+ - 使用 Rust + Tokio 提升吞吐能力
43
+
44
+ ## 📦 使用示例
45
+
46
+ ```python
47
+ import asyncio
48
+ import time
49
+ from rusty_req import fetch_requests, RequestItem
50
+
51
+ async def main():
52
+ requests = [
53
+ RequestItem(
54
+ url="https://httpbin.org/headers",
55
+ method="GET",
56
+ params=None,
57
+ timeout=3.0,
58
+ tag=f"test-get-{i}",
59
+ headers={
60
+ "Accept-Encoding": "gzip, deflate, br",
61
+ "Connection": "keep-alive",
62
+ "X-Test-Header": "ChatGPT"
63
+ }
64
+ )
65
+ for i in range(100)
66
+ ]
67
+
68
+ start = time.perf_counter()
69
+ responses = await fetch_requests(requests, total_timeout=5.0)
70
+ duration = time.perf_counter() - start
71
+
72
+ success = sum(1 for r in responses if not r["error"])
73
+ failure = len(responses) - success
74
+
75
+ print(f"✅ 成功请求数: {success}")
76
+ print(f"❌ 失败请求数: {failure}")
77
+ print(f"⏱️ 总耗时: {duration:.2f} 秒")
78
+
79
+ if __name__ == "__main__":
80
+ asyncio.run(main())
81
+ ```
82
+
83
+ ## 🧱 数据结构说明
84
+
85
+ ### `RequestItem` 参数
86
+
87
+ | 字段名 | 类型 | 必须 | 说明 |
88
+ |------------|------------------|------|----------------------------------------|
89
+ | `url` | `str` | ✅ | 请求地址 |
90
+ | `method` | `str` | ✅ | 请求方法(`"GET"` 或 `"POST"`) |
91
+ | `params` | `dict` / `None` | 否 | 查询参数(GET)或表单数据(POST) |
92
+ | `headers` | `dict` / `None` | 否 | 自定义请求头 |
93
+ | `timeout` | `float` | ✅ | 单个请求超时(秒) |
94
+ | `tag` | `str` | 否 | 标记请求的来源、编号等辅助信息 |
95
+
96
+ ### 返回格式
97
+
98
+ ```python
99
+ [
100
+ {
101
+ "response": str | None, # 成功时返回内容
102
+ "error": str | None, # 失败时错误信息
103
+ "meta": {
104
+ "tag": str,
105
+ "elapsed_ms": float # 请求耗时(毫秒)
106
+ }
107
+ },
108
+ ...
109
+ ]
110
+ ```
111
+
112
+ ## 📑 Headers 示例
113
+
114
+ ```python
115
+ RequestItem(
116
+ url="https://httpbin.org/headers",
117
+ method="GET",
118
+ headers={
119
+ "User-Agent": "MyApp/1.0",
120
+ "X-Custom": "123"
121
+ },
122
+ timeout=5.0
123
+ )
124
+ ```
125
+
126
+ ## 📄 License
127
+
128
+ MIT License
129
+
@@ -0,0 +1,110 @@
1
+ # rusty-req
2
+
3
+ 基于 Rust + Python 的高性能异步请求库,适用于需要批量发送 HTTP 请求的场景。通过 Rust 实现并发请求逻辑,并通过 [maturin](https://github.com/PyO3/maturin) 封装为 Python 模块,兼具性能与易用性。
4
+
5
+ ## 🔧 安装
6
+
7
+ ```bash
8
+ pip install rusty-req
9
+ ```
10
+
11
+ 或从源码构建:
12
+
13
+ ```bash
14
+ maturin build --release
15
+ pip install target/wheels/rusty_req-*.whl
16
+ ```
17
+
18
+ ## 🚀 功能特点
19
+
20
+ - 批量异步发送 HTTP 请求(支持 GET / POST)
21
+ - 支持自定义 headers / params / timeout / tag
22
+ - 支持全局超时时间控制(`total_timeout`)
23
+ - 返回响应内容、错误信息、Meta 数据
24
+ - 使用 Rust + Tokio 提升吞吐能力
25
+
26
+ ## 📦 使用示例
27
+
28
+ ```python
29
+ import asyncio
30
+ import time
31
+ from rusty_req import fetch_requests, RequestItem
32
+
33
+ async def main():
34
+ requests = [
35
+ RequestItem(
36
+ url="https://httpbin.org/headers",
37
+ method="GET",
38
+ params=None,
39
+ timeout=3.0,
40
+ tag=f"test-get-{i}",
41
+ headers={
42
+ "Accept-Encoding": "gzip, deflate, br",
43
+ "Connection": "keep-alive",
44
+ "X-Test-Header": "ChatGPT"
45
+ }
46
+ )
47
+ for i in range(100)
48
+ ]
49
+
50
+ start = time.perf_counter()
51
+ responses = await fetch_requests(requests, total_timeout=5.0)
52
+ duration = time.perf_counter() - start
53
+
54
+ success = sum(1 for r in responses if not r["error"])
55
+ failure = len(responses) - success
56
+
57
+ print(f"✅ 成功请求数: {success}")
58
+ print(f"❌ 失败请求数: {failure}")
59
+ print(f"⏱️ 总耗时: {duration:.2f} 秒")
60
+
61
+ if __name__ == "__main__":
62
+ asyncio.run(main())
63
+ ```
64
+
65
+ ## 🧱 数据结构说明
66
+
67
+ ### `RequestItem` 参数
68
+
69
+ | 字段名 | 类型 | 必须 | 说明 |
70
+ |------------|------------------|------|----------------------------------------|
71
+ | `url` | `str` | ✅ | 请求地址 |
72
+ | `method` | `str` | ✅ | 请求方法(`"GET"` 或 `"POST"`) |
73
+ | `params` | `dict` / `None` | 否 | 查询参数(GET)或表单数据(POST) |
74
+ | `headers` | `dict` / `None` | 否 | 自定义请求头 |
75
+ | `timeout` | `float` | ✅ | 单个请求超时(秒) |
76
+ | `tag` | `str` | 否 | 标记请求的来源、编号等辅助信息 |
77
+
78
+ ### 返回格式
79
+
80
+ ```python
81
+ [
82
+ {
83
+ "response": str | None, # 成功时返回内容
84
+ "error": str | None, # 失败时错误信息
85
+ "meta": {
86
+ "tag": str,
87
+ "elapsed_ms": float # 请求耗时(毫秒)
88
+ }
89
+ },
90
+ ...
91
+ ]
92
+ ```
93
+
94
+ ## 📑 Headers 示例
95
+
96
+ ```python
97
+ RequestItem(
98
+ url="https://httpbin.org/headers",
99
+ method="GET",
100
+ headers={
101
+ "User-Agent": "MyApp/1.0",
102
+ "X-Custom": "123"
103
+ },
104
+ timeout=5.0
105
+ )
106
+ ```
107
+
108
+ ## 📄 License
109
+
110
+ MIT License
@@ -0,0 +1,41 @@
1
+ [package]
2
+ name = "rusty-req"
3
+ version = "0.1.3"
4
+ edition = "2021"
5
+ authors = ["kaysen <kaysen820@gmail.com>"]
6
+ description = "High-performance async HTTP client built with Rust for Python."
7
+ license = "MIT"
8
+ homepage = "https://github.com/kaysen820/rusty-req"
9
+ repository = "https://github.com/kaysen820/rusty-req"
10
+ documentation = "https://github.com/kaysen820/rusty-req#readme"
11
+ readme = "README.md"
12
+
13
+ [build-system]
14
+ requires = ["maturin>=1.4,<2.0"]
15
+ build-backend = "maturin"
16
+
17
+ [project]
18
+ name = "rusty-req"
19
+ version = "0.1.3"
20
+ description = "High-performance async HTTP client built with Rust for Python."
21
+ readme = "README.md"
22
+ authors = [{ name = "kaysen", email = "kaysen820@gmail.com" }]
23
+ license = "MIT"
24
+ requires-python = ">=3.7"
25
+ classifiers = [
26
+ "Programming Language :: Python",
27
+ "Programming Language :: Python :: 3",
28
+ "Programming Language :: Rust",
29
+ "License :: OSI Approved :: MIT License",
30
+ "Operating System :: OS Independent",
31
+ ]
32
+
33
+ [project.urls]
34
+ "Homepage" = "https://github.com/kaysen820/rusty-req"
35
+ "Repository" = "https://github.com/kaysen820/rusty-req"
36
+ "Bug Tracker" = "https://github.com/kaysen820/rusty-req/issues"
37
+ "Documentation" = "https://github.com/kaysen820/rusty-req#readme"
38
+
39
+ [tool.maturin]
40
+ bindings = "pyo3"
41
+ module-name = "rusty_req"
@@ -1,3 +1,4 @@
1
+ #![allow(non_local_definitions)]
1
2
  use pyo3::prelude::*;
2
3
  use pyo3::types::{PyDict, PyList};
3
4
  use std::collections::HashMap;
@@ -8,6 +9,7 @@ use serde_json::Value;
8
9
  use chrono::{DateTime, Local};
9
10
  use once_cell::sync::Lazy;
10
11
  use tokio::sync::Mutex;
12
+ use reqwest::header::{HeaderMap, HeaderName, HeaderValue, ACCEPT_ENCODING, CONNECTION};
11
13
 
12
14
 
13
15
  // 全局共享的HTTP客户端
@@ -31,6 +33,8 @@ pub struct RequestItem {
31
33
  pub timeout: Option<f64>,
32
34
  #[pyo3(get, set)]
33
35
  pub tag: Option<String>, // ✅ 新增字段
36
+ #[pyo3(get, set)]
37
+ pub headers: Option<Py<PyDict>>, // ✅ 新增字段
34
38
  }
35
39
 
36
40
  #[pymethods]
@@ -42,8 +46,9 @@ impl RequestItem {
42
46
  params: Option<Py<PyDict>>,
43
47
  timeout: Option<f64>,
44
48
  tag: Option<String>, // ✅ 新增字段
49
+ headers: Option<Py<PyDict>>, // ✅ 新增字段
45
50
  ) -> Self {
46
- Self { url, method, params, timeout, tag }
51
+ Self { url, method, params, timeout, tag, headers }
47
52
  }
48
53
  }
49
54
 
@@ -102,6 +107,32 @@ fn fetch_requests<'py>(
102
107
  &req.url
103
108
  );
104
109
 
110
+ // 设置 Header
111
+ let mut headers = HeaderMap::new();
112
+
113
+ // 默认值
114
+ headers.insert(ACCEPT_ENCODING, HeaderValue::from_static("gzip, deflate, br"));
115
+ headers.insert(CONNECTION, HeaderValue::from_static("keep-alive"));
116
+
117
+ // 如果 Python 中传了 headers,就覆盖或追加
118
+ if let Some(py_headers) = &req.headers {
119
+ if let Ok(dict) = py_headers.as_ref(py).downcast::<PyDict>() {
120
+ for (k, v) in dict.iter() {
121
+ if let (Ok(k_str), Ok(v_str)) = (k.extract::<String>(), v.extract::<String>()) {
122
+ if let (Ok(h_name), Ok(h_val)) = (
123
+ HeaderName::from_bytes(k_str.as_bytes()),
124
+ HeaderValue::from_str(&v_str),
125
+ ) {
126
+ headers.insert(h_name, h_val);
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+
133
+ builder = builder.headers(headers);
134
+
135
+ // 设置 body 参数
105
136
  if let Some(params_dict) = &req.params {
106
137
  if let Ok(dict) = params_dict.as_ref(py).downcast::<PyDict>() {
107
138
  if let Ok(json_value) = py_to_json(py, dict) {
@@ -109,6 +140,7 @@ fn fetch_requests<'py>(
109
140
  }
110
141
  }
111
142
  }
143
+
112
144
  builder
113
145
  });
114
146
 
rusty_req-0.1.1/PKG-INFO DELETED
@@ -1,17 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: rusty-req
3
- Version: 0.1.1
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: kaysen <kaysen820@gmail.com>
11
- License: MIT
12
- Requires-Python: >=3.7
13
- Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
14
-
15
- # rusty-req
16
- rusty-req
17
-
rusty_req-0.1.1/README.md DELETED
@@ -1,2 +0,0 @@
1
- # rusty-req
2
- rusty-req
@@ -1,23 +0,0 @@
1
- [build-system]
2
- requires = ["maturin>=1.4,<2.0"]
3
- build-backend = "maturin"
4
-
5
- [project]
6
- name = "rusty-req"
7
- version = "0.1.1"
8
- description = "High-performance async HTTP client built with Rust for Python."
9
- readme = "README.md"
10
- authors = [{ name = "kaysen", email = "kaysen820@gmail.com" }]
11
- license = "MIT"
12
- requires-python = ">=3.7"
13
- classifiers = [
14
- "Programming Language :: Python",
15
- "Programming Language :: Python :: 3",
16
- "Programming Language :: Rust",
17
- "License :: OSI Approved :: MIT License",
18
- "Operating System :: OS Independent",
19
- ]
20
-
21
- [tool.maturin]
22
- bindings = "pyo3"
23
- module-name = "rusty_req"
File without changes
File without changes
File without changes
File without changes