rusty-req 0.1.3__tar.gz → 0.1.5__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.

@@ -17,6 +17,21 @@ version = "2.0.1"
17
17
  source = "registry+https://github.com/rust-lang/crates.io-index"
18
18
  checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
19
19
 
20
+ [[package]]
21
+ name = "alloc-no-stdlib"
22
+ version = "2.0.4"
23
+ source = "registry+https://github.com/rust-lang/crates.io-index"
24
+ checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3"
25
+
26
+ [[package]]
27
+ name = "alloc-stdlib"
28
+ version = "0.2.2"
29
+ source = "registry+https://github.com/rust-lang/crates.io-index"
30
+ checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece"
31
+ dependencies = [
32
+ "alloc-no-stdlib",
33
+ ]
34
+
20
35
  [[package]]
21
36
  name = "android-tzdata"
22
37
  version = "0.1.1"
@@ -32,6 +47,20 @@ dependencies = [
32
47
  "libc",
33
48
  ]
34
49
 
50
+ [[package]]
51
+ name = "async-compression"
52
+ version = "0.4.25"
53
+ source = "registry+https://github.com/rust-lang/crates.io-index"
54
+ checksum = "40f6024f3f856663b45fd0c9b6f2024034a702f453549449e0d84a305900dad4"
55
+ dependencies = [
56
+ "brotli",
57
+ "flate2",
58
+ "futures-core",
59
+ "memchr",
60
+ "pin-project-lite",
61
+ "tokio",
62
+ ]
63
+
35
64
  [[package]]
36
65
  name = "autocfg"
37
66
  version = "1.5.0"
@@ -71,6 +100,27 @@ version = "2.9.1"
71
100
  source = "registry+https://github.com/rust-lang/crates.io-index"
72
101
  checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
73
102
 
103
+ [[package]]
104
+ name = "brotli"
105
+ version = "8.0.1"
106
+ source = "registry+https://github.com/rust-lang/crates.io-index"
107
+ checksum = "9991eea70ea4f293524138648e41ee89b0b2b12ddef3b255effa43c8056e0e0d"
108
+ dependencies = [
109
+ "alloc-no-stdlib",
110
+ "alloc-stdlib",
111
+ "brotli-decompressor",
112
+ ]
113
+
114
+ [[package]]
115
+ name = "brotli-decompressor"
116
+ version = "5.0.0"
117
+ source = "registry+https://github.com/rust-lang/crates.io-index"
118
+ checksum = "874bb8112abecc98cbd6d81ea4fa7e94fb9449648c93cc89aa40c81c24d7de03"
119
+ dependencies = [
120
+ "alloc-no-stdlib",
121
+ "alloc-stdlib",
122
+ ]
123
+
74
124
  [[package]]
75
125
  name = "bumpalo"
76
126
  version = "3.19.0"
@@ -128,6 +178,15 @@ version = "0.8.7"
128
178
  source = "registry+https://github.com/rust-lang/crates.io-index"
129
179
  checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
130
180
 
181
+ [[package]]
182
+ name = "crc32fast"
183
+ version = "1.4.2"
184
+ source = "registry+https://github.com/rust-lang/crates.io-index"
185
+ checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
186
+ dependencies = [
187
+ "cfg-if",
188
+ ]
189
+
131
190
  [[package]]
132
191
  name = "displaydoc"
133
192
  version = "0.2.5"
@@ -170,6 +229,16 @@ version = "2.3.0"
170
229
  source = "registry+https://github.com/rust-lang/crates.io-index"
171
230
  checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
172
231
 
232
+ [[package]]
233
+ name = "flate2"
234
+ version = "1.1.2"
235
+ source = "registry+https://github.com/rust-lang/crates.io-index"
236
+ checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d"
237
+ dependencies = [
238
+ "crc32fast",
239
+ "miniz_oxide",
240
+ ]
241
+
173
242
  [[package]]
174
243
  name = "fnv"
175
244
  version = "1.0.7"
@@ -926,6 +995,7 @@ version = "0.11.27"
926
995
  source = "registry+https://github.com/rust-lang/crates.io-index"
927
996
  checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62"
928
997
  dependencies = [
998
+ "async-compression",
929
999
  "base64",
930
1000
  "bytes",
931
1001
  "encoding_rs",
@@ -952,10 +1022,12 @@ dependencies = [
952
1022
  "system-configuration",
953
1023
  "tokio",
954
1024
  "tokio-native-tls",
1025
+ "tokio-util",
955
1026
  "tower-service",
956
1027
  "url",
957
1028
  "wasm-bindgen",
958
1029
  "wasm-bindgen-futures",
1030
+ "wasm-streams",
959
1031
  "web-sys",
960
1032
  "winreg",
961
1033
  ]
@@ -996,7 +1068,7 @@ checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d"
996
1068
 
997
1069
  [[package]]
998
1070
  name = "rusty-req"
999
- version = "0.1.3"
1071
+ version = "0.1.5"
1000
1072
  dependencies = [
1001
1073
  "chrono",
1002
1074
  "futures",
@@ -1432,6 +1504,19 @@ dependencies = [
1432
1504
  "unicode-ident",
1433
1505
  ]
1434
1506
 
1507
+ [[package]]
1508
+ name = "wasm-streams"
1509
+ version = "0.4.2"
1510
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1511
+ checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65"
1512
+ dependencies = [
1513
+ "futures-util",
1514
+ "js-sys",
1515
+ "wasm-bindgen",
1516
+ "wasm-bindgen-futures",
1517
+ "web-sys",
1518
+ ]
1519
+
1435
1520
  [[package]]
1436
1521
  name = "web-sys"
1437
1522
  version = "0.3.77"
@@ -0,0 +1,26 @@
1
+ [package]
2
+ name = "rusty-req"
3
+ version = "0.1.5"
4
+ edition = "2021"
5
+
6
+ [dependencies]
7
+ serde_json = "1.0"
8
+ chrono = "0.4"
9
+ futures = "0.3"
10
+ once_cell = "1.18"
11
+
12
+ [dependencies.pyo3]
13
+ version = "0.20"
14
+ features = [ "extension-module",]
15
+
16
+ [dependencies.pyo3-asyncio]
17
+ version = "0.20"
18
+ features = [ "tokio-runtime",]
19
+
20
+ [dependencies.tokio]
21
+ version = "1.0"
22
+ features = [ "full",]
23
+
24
+ [dependencies.reqwest]
25
+ version = "0.11"
26
+ features = [ "json", "brotli", "gzip", "deflate", "stream",]
@@ -1,20 +1,20 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rusty-req
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Classifier: Programming Language :: Python
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Rust
7
7
  Classifier: License :: OSI Approved :: MIT License
8
8
  Classifier: Operating System :: OS Independent
9
9
  Summary: High-performance async HTTP client built with Rust for Python.
10
- Author-email: kaysen <kaysen820@gmail.com>
10
+ Author-email: KAY53N <kaysen820@gmail.com>
11
11
  License: MIT
12
12
  Requires-Python: >=3.7
13
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
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
18
 
19
19
  # rusty-req
20
20
 
@@ -46,11 +46,11 @@ pip install target/wheels/rusty_req-*.whl
46
46
  ```python
47
47
  import asyncio
48
48
  import time
49
- from rusty_req import fetch_requests, RequestItem
49
+ import rusty_req
50
50
 
51
51
  async def main():
52
52
  requests = [
53
- RequestItem(
53
+ rusty_req.RequestItem(
54
54
  url="https://httpbin.org/headers",
55
55
  method="GET",
56
56
  params=None,
@@ -66,7 +66,9 @@ async def main():
66
66
  ]
67
67
 
68
68
  start = time.perf_counter()
69
- responses = await fetch_requests(requests, total_timeout=5.0)
69
+
70
+ rusty_req.set_debug(False)
71
+ responses = await rusty_req.fetch_requests(requests, total_timeout=5.0)
70
72
  duration = time.perf_counter() - start
71
73
 
72
74
  success = sum(1 for r in responses if not r["error"])
@@ -116,8 +118,9 @@ RequestItem(
116
118
  url="https://httpbin.org/headers",
117
119
  method="GET",
118
120
  headers={
119
- "User-Agent": "MyApp/1.0",
120
- "X-Custom": "123"
121
+ "Accept-Encoding": "gzip, deflate, br",
122
+ "Connection": "keep-alive",
123
+ "X-Test-Header": "ChatGPT"
121
124
  },
122
125
  timeout=5.0
123
126
  )
@@ -28,11 +28,11 @@ pip install target/wheels/rusty_req-*.whl
28
28
  ```python
29
29
  import asyncio
30
30
  import time
31
- from rusty_req import fetch_requests, RequestItem
31
+ import rusty_req
32
32
 
33
33
  async def main():
34
34
  requests = [
35
- RequestItem(
35
+ rusty_req.RequestItem(
36
36
  url="https://httpbin.org/headers",
37
37
  method="GET",
38
38
  params=None,
@@ -48,7 +48,9 @@ async def main():
48
48
  ]
49
49
 
50
50
  start = time.perf_counter()
51
- responses = await fetch_requests(requests, total_timeout=5.0)
51
+
52
+ rusty_req.set_debug(False)
53
+ responses = await rusty_req.fetch_requests(requests, total_timeout=5.0)
52
54
  duration = time.perf_counter() - start
53
55
 
54
56
  success = sum(1 for r in responses if not r["error"])
@@ -98,8 +100,9 @@ RequestItem(
98
100
  url="https://httpbin.org/headers",
99
101
  method="GET",
100
102
  headers={
101
- "User-Agent": "MyApp/1.0",
102
- "X-Custom": "123"
103
+ "Accept-Encoding": "gzip, deflate, br",
104
+ "Connection": "keep-alive",
105
+ "X-Test-Header": "ChatGPT"
103
106
  },
104
107
  timeout=5.0
105
108
  )
@@ -0,0 +1,37 @@
1
+ [package]
2
+ name = "rusty-req"
3
+ version = "0.1.5"
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/KAY53N/rusty-req"
9
+ repository = "https://github.com/KAY53N/rusty-req"
10
+ documentation = "https://github.com/KAY53N/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.5"
20
+ description = "High-performance async HTTP client built with Rust for Python."
21
+ readme = "README.md"
22
+ license = "MIT"
23
+ requires-python = ">=3.7"
24
+ classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Rust", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent",]
25
+ [[project.authors]]
26
+ name = "KAY53N"
27
+ email = "kaysen820@gmail.com"
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/KAY53N/rusty-req"
31
+ Repository = "https://github.com/KAY53N/rusty-req"
32
+ "Bug Tracker" = "https://github.com/KAY53N/rusty-req/issues"
33
+ Documentation = "https://github.com/KAY53N/rusty-req#readme"
34
+
35
+ [tool.maturin]
36
+ bindings = "pyo3"
37
+ module-name = "rusty_req"
@@ -1,25 +1,69 @@
1
1
  #![allow(non_local_definitions)]
2
- use pyo3::prelude::*;
3
- use pyo3::types::{PyDict, PyList};
2
+ // PyO3 宏和类型
3
+ use pyo3::{pyclass, pymethods, pyfunction, pymodule};
4
+ use pyo3::{PyResult, Python, PyAny, Py, wrap_pyfunction};
5
+ use pyo3::types::{PyDict, PyList, PyModule};
6
+ use pyo3::IntoPy;
7
+
8
+ // 其他库
4
9
  use std::collections::HashMap;
5
- use reqwest::Client;
10
+ use reqwest::{Client, Request, StatusCode};
6
11
  use std::time::{Duration, SystemTime};
7
12
  use futures::future::join_all;
8
13
  use serde_json::Value;
9
14
  use chrono::{DateTime, Local};
10
15
  use once_cell::sync::Lazy;
11
16
  use tokio::sync::Mutex;
17
+ use std::sync::atomic::{AtomicBool, Ordering};
12
18
  use reqwest::header::{HeaderMap, HeaderName, HeaderValue, ACCEPT_ENCODING, CONNECTION};
13
19
 
20
+ static DEBUG_MODE: AtomicBool = AtomicBool::new(false);
14
21
 
15
22
  // 全局共享的HTTP客户端
16
23
  static GLOBAL_CLIENT: Lazy<Mutex<Client>> = Lazy::new(|| {
17
24
  Mutex::new(Client::builder()
18
25
  .timeout(Duration::from_secs(30))
26
+ .gzip(true) // 开启 gzip 自动解压
27
+ .brotli(true) // 开启 brotli 自动解压
28
+ .deflate(true) // 开启 deflate 自动解压
19
29
  .build()
20
30
  .expect("Failed to create HTTP client"))
21
31
  });
22
32
 
33
+ #[pyfunction]
34
+ fn set_debug(enabled: bool) {
35
+ DEBUG_MODE.store(enabled, Ordering::Relaxed);
36
+ }
37
+
38
+ pub fn is_debug() -> bool {
39
+ DEBUG_MODE.load(Ordering::Relaxed)
40
+ }
41
+
42
+ fn debug_log(
43
+ tag: &str,
44
+ request: &Request,
45
+ status: StatusCode,
46
+ headers: &HeaderMap,
47
+ body: &str,
48
+ ) {
49
+ if !is_debug() {
50
+ return;
51
+ }
52
+
53
+ println!("\n================== [DEBUG: {}] ==================", tag);
54
+ println!("Request Method : {}", request.method());
55
+ println!("Request URL : {}", request.url());
56
+ println!("--------------------------------------------------");
57
+ println!("Response Status: {}", status);
58
+ println!("Response Headers:");
59
+ for (key, value) in headers.iter() {
60
+ println!(" {}: {:?}", key, value);
61
+ }
62
+ println!("--------------------------------------------------");
63
+ println!("Response Body:\n{}", body);
64
+ println!("==================================================\n");
65
+ }
66
+
23
67
  #[pyclass]
24
68
  #[derive(Clone)]
25
69
  pub struct RequestItem {
@@ -145,10 +189,16 @@ fn fetch_requests<'py>(
145
189
  });
146
190
 
147
191
  // 发起请求,使用单个请求超时控制
148
- let timeout = Duration::from_secs_f64(req.timeout.unwrap_or(5.0).max(5.0));
192
+ let timeout = Duration::from_secs_f64(req.timeout.unwrap_or(3.0).max(3.0));
193
+ let tag = req.tag.clone().unwrap_or_else(|| "no-tag".to_string());
194
+ let request_to_send = builder.try_clone().unwrap().build().unwrap();
149
195
  match tokio::time::timeout(timeout, builder.send()).await {
150
196
  Ok(Ok(res)) => {
197
+ let status = res.status();
198
+ let headers = res.headers().clone(); // 必须 clone,HeaderMap 实现了 Clone
199
+
151
200
  if let Ok(text) = res.text().await {
201
+ debug_log(&tag, &request_to_send, status, &headers, &text);
152
202
  result.insert("response".to_string(), text);
153
203
  }
154
204
  },
@@ -237,5 +287,6 @@ fn format_datetime(time: SystemTime) -> String {
237
287
  fn rusty_req(_py: Python, m: &PyModule) -> PyResult<()> {
238
288
  m.add_class::<RequestItem>()?;
239
289
  m.add_function(wrap_pyfunction!(fetch_requests, m)?)?;
290
+ m.add_function(wrap_pyfunction!(set_debug, m)?)?;
240
291
  Ok(())
241
292
  }
@@ -0,0 +1,17 @@
1
+ import toml
2
+
3
+ # 读取版本号文件
4
+ with open("version.txt", "r") as f:
5
+ version = f.read().strip()
6
+
7
+ # 更新 Cargo.toml
8
+ cargo = toml.load("Cargo.toml")
9
+ cargo['package']['version'] = version
10
+ with open("Cargo.toml", "w") as f:
11
+ toml.dump(cargo, f)
12
+
13
+ # 更新 pyproject.toml
14
+ pyproject = toml.load("pyproject.toml")
15
+ pyproject['package']['version'] = version # 这里改为访问 package
16
+ with open("pyproject.toml", "w") as f:
17
+ toml.dump(pyproject, f)
@@ -0,0 +1 @@
1
+ 0.1.5
@@ -1,14 +0,0 @@
1
- [package]
2
- name = "rusty-req"
3
- version = "0.1.3"
4
- edition = "2021"
5
-
6
- [dependencies]
7
- pyo3 = { version = "0.20", features = ["extension-module"] }
8
- pyo3-asyncio = { version = "0.20", features = ["tokio-runtime"] }
9
- tokio = { version = "1.0", features = ["full"] }
10
- reqwest = { version = "0.11", features = ["json"] }
11
- serde_json = "1.0"
12
- chrono = "0.4"
13
- futures = "0.3"
14
- once_cell = "1.18"
@@ -1,41 +0,0 @@
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"
File without changes
File without changes
File without changes
File without changes