redc 0.1.1__cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.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.
- redc/__init__.py +22 -0
- redc/callback.py +19 -0
- redc/callbacks.py +81 -0
- redc/client.py +796 -0
- redc/codes.py +151 -0
- redc/exceptions/__init__.py +22 -0
- redc/ext/redc.cpp +362 -0
- redc/ext/redc.h +91 -0
- redc/ext/utils/concurrentqueue.h +3747 -0
- redc/ext/utils/curl_utils.h +84 -0
- redc/redc_ext.cpython-313t-x86_64-linux-gnu.so +0 -0
- redc/response.py +68 -0
- redc/utils/__init__.py +5 -0
- redc/utils/headers.py +60 -0
- redc/utils/http.py +12 -0
- redc/utils/json_encoder.py +17 -0
- redc-0.1.1.dist-info/METADATA +65 -0
- redc-0.1.1.dist-info/RECORD +27 -0
- redc-0.1.1.dist-info/WHEEL +6 -0
- redc-0.1.1.dist-info/licenses/LICENSE +21 -0
- redc.libs/libcrypto-2321a809.so.3 +0 -0
- redc.libs/libcurl-a0db5b13.so.4.8.0 +0 -0
- redc.libs/libicudata-cb3ba60c.so.50.2 +0 -0
- redc.libs/libicuuc-1796a535.so.50.2 +0 -0
- redc.libs/libnghttp2-cc579893.so.14.17.0 +0 -0
- redc.libs/libpsl-9527e555.so.0.2.4 +0 -0
- redc.libs/libssl-ebec6e5c.so.3 +0 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
#ifndef CURL_UTILS_H
|
2
|
+
#define CURL_UTILS_H
|
3
|
+
|
4
|
+
#include <curl/curl.h>
|
5
|
+
|
6
|
+
struct CurlSlist {
|
7
|
+
curl_slist *slist = nullptr;
|
8
|
+
|
9
|
+
CurlSlist() = default;
|
10
|
+
|
11
|
+
~CurlSlist() {
|
12
|
+
if (slist) {
|
13
|
+
curl_slist_free_all(slist);
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
CurlSlist(const CurlSlist &) = delete;
|
18
|
+
CurlSlist &operator=(const CurlSlist &) = delete;
|
19
|
+
|
20
|
+
CurlSlist(CurlSlist &&other) noexcept : slist(other.slist) {
|
21
|
+
other.slist = nullptr;
|
22
|
+
}
|
23
|
+
|
24
|
+
CurlSlist &operator=(CurlSlist &&other) noexcept {
|
25
|
+
if (this != &other) {
|
26
|
+
if (slist) {
|
27
|
+
curl_slist_free_all(slist);
|
28
|
+
}
|
29
|
+
slist = other.slist;
|
30
|
+
other.slist = nullptr;
|
31
|
+
}
|
32
|
+
return *this;
|
33
|
+
}
|
34
|
+
};
|
35
|
+
|
36
|
+
struct CurlMime {
|
37
|
+
curl_mime *mime = nullptr;
|
38
|
+
|
39
|
+
CurlMime() = default;
|
40
|
+
|
41
|
+
~CurlMime() {
|
42
|
+
if (mime) {
|
43
|
+
curl_mime_free(mime);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
CurlMime(const CurlMime &) = delete;
|
48
|
+
CurlMime &operator=(const CurlMime &) = delete;
|
49
|
+
|
50
|
+
CurlMime(CurlMime &&other) noexcept : mime(other.mime) {
|
51
|
+
other.mime = nullptr;
|
52
|
+
}
|
53
|
+
|
54
|
+
CurlMime &operator=(CurlMime &&other) noexcept {
|
55
|
+
if (this != &other) {
|
56
|
+
if (mime) {
|
57
|
+
curl_mime_free(mime);
|
58
|
+
}
|
59
|
+
mime = other.mime;
|
60
|
+
other.mime = nullptr;
|
61
|
+
}
|
62
|
+
return *this;
|
63
|
+
}
|
64
|
+
};
|
65
|
+
|
66
|
+
class CurlGlobalInit {
|
67
|
+
public:
|
68
|
+
CurlGlobalInit() {
|
69
|
+
#if LIBCURL_VERSION_NUM >= 0x070800
|
70
|
+
curl_global_init(CURL_GLOBAL_DEFAULT);
|
71
|
+
#endif
|
72
|
+
}
|
73
|
+
|
74
|
+
~CurlGlobalInit() {
|
75
|
+
#if LIBCURL_VERSION_NUM >= 0x070800
|
76
|
+
curl_global_cleanup();
|
77
|
+
#endif
|
78
|
+
}
|
79
|
+
|
80
|
+
CurlGlobalInit(const CurlGlobalInit &) = delete;
|
81
|
+
CurlGlobalInit &operator=(const CurlGlobalInit &) = delete;
|
82
|
+
};
|
83
|
+
|
84
|
+
#endif // CURL_UTILS_H
|
Binary file
|
redc/response.py
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
from .exceptions import HTTPError
|
2
|
+
from .utils import Headers, json_loads
|
3
|
+
|
4
|
+
|
5
|
+
class Response:
|
6
|
+
def __init__(
|
7
|
+
self,
|
8
|
+
status_code: int,
|
9
|
+
headers: bytes,
|
10
|
+
response: bytes,
|
11
|
+
curl_code: int,
|
12
|
+
curl_error_message: str,
|
13
|
+
raise_for_status: bool = False,
|
14
|
+
):
|
15
|
+
"""Represents an HTTP response of RedC"""
|
16
|
+
|
17
|
+
self.status_code = status_code
|
18
|
+
"""HTTP response status code; If the value is ``-1``, it indicates a cURL error occurred"""
|
19
|
+
|
20
|
+
self.headers = None if status_code == -1 else Headers.parse_headers(headers)
|
21
|
+
"""HTTP response headers"""
|
22
|
+
|
23
|
+
self.__response = response
|
24
|
+
|
25
|
+
self.curl_code = curl_code
|
26
|
+
"""CURL return code"""
|
27
|
+
self.curl_error_message = curl_error_message
|
28
|
+
"""CURL error message"""
|
29
|
+
|
30
|
+
if raise_for_status:
|
31
|
+
self.raise_for_status()
|
32
|
+
|
33
|
+
@property
|
34
|
+
def content(self) -> bytes:
|
35
|
+
"""Returns the raw response content"""
|
36
|
+
return self.__response
|
37
|
+
|
38
|
+
@property
|
39
|
+
def ok(self):
|
40
|
+
"""Checks if the request is successful and with no errors"""
|
41
|
+
return bool(self)
|
42
|
+
|
43
|
+
def text(self, encoding: str = "utf-8"):
|
44
|
+
"""Decodes the response content into a string
|
45
|
+
|
46
|
+
Parameters:
|
47
|
+
encoding (``str``, *optional*):
|
48
|
+
The encoding to use for decoding. Default is "utf-8"
|
49
|
+
|
50
|
+
Returns:
|
51
|
+
``str``
|
52
|
+
"""
|
53
|
+
|
54
|
+
if self.status_code != -1:
|
55
|
+
return self.__response.decode(encoding=encoding)
|
56
|
+
|
57
|
+
def json(self):
|
58
|
+
"""Parses the response content as JSON"""
|
59
|
+
if self.status_code != -1:
|
60
|
+
return json_loads(self.__response)
|
61
|
+
|
62
|
+
def raise_for_status(self):
|
63
|
+
"""Raises an HTTPError if the response status indicates an error"""
|
64
|
+
if self.status_code == -1 or (400 <= self.status_code <= 599):
|
65
|
+
raise HTTPError(self.status_code, self.curl_code, self.curl_error_message)
|
66
|
+
|
67
|
+
def __bool__(self):
|
68
|
+
return self.status_code != -1 and 200 <= self.status_code <= 299
|
redc/utils/__init__.py
ADDED
redc/utils/headers.py
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
def check_key_dict(key: str, data: dict):
|
2
|
+
key = key.lower()
|
3
|
+
for k in data.keys():
|
4
|
+
if key == k.lower():
|
5
|
+
return True
|
6
|
+
|
7
|
+
return False
|
8
|
+
|
9
|
+
|
10
|
+
class Headers(dict):
|
11
|
+
def __init__(self, *args, **kwargs):
|
12
|
+
super().__init__()
|
13
|
+
self.update(*args, **kwargs)
|
14
|
+
|
15
|
+
def __setitem__(self, key, value):
|
16
|
+
super().__setitem__(key.lower(), value)
|
17
|
+
|
18
|
+
def __getitem__(self, key):
|
19
|
+
return super().__getitem__(key.lower())
|
20
|
+
|
21
|
+
def __delitem__(self, key):
|
22
|
+
super().__delitem__(key.lower())
|
23
|
+
|
24
|
+
def __contains__(self, key):
|
25
|
+
return super().__contains__(key.lower())
|
26
|
+
|
27
|
+
def get(self, key, default=None):
|
28
|
+
return super().get(key.lower(), default)
|
29
|
+
|
30
|
+
def pop(self, key, default=None):
|
31
|
+
return super().pop(key.lower(), default)
|
32
|
+
|
33
|
+
def setdefault(self, key, default=None):
|
34
|
+
return super().setdefault(key.lower(), default)
|
35
|
+
|
36
|
+
def update(self, *args, **kwargs):
|
37
|
+
if args:
|
38
|
+
if len(args) > 1:
|
39
|
+
raise TypeError(f"update expected at most 1 arguments, got {len(args)}")
|
40
|
+
other = args[0]
|
41
|
+
if isinstance(other, dict):
|
42
|
+
for key, value in other.items():
|
43
|
+
self[key] = value
|
44
|
+
elif hasattr(other, "__iter__"):
|
45
|
+
for key, value in other:
|
46
|
+
self[key] = value
|
47
|
+
else:
|
48
|
+
raise TypeError(f"'dict' object expected, got {type(other).__name__}")
|
49
|
+
for key, value in kwargs.items():
|
50
|
+
self[key] = value
|
51
|
+
|
52
|
+
@staticmethod
|
53
|
+
def parse_headers(headers_str: bytes):
|
54
|
+
lines = headers_str.decode().splitlines()
|
55
|
+
headers = Headers()
|
56
|
+
for line in lines[1:]:
|
57
|
+
if ":" in line:
|
58
|
+
key, value = line.split(":", 1)
|
59
|
+
headers[key] = value.strip()
|
60
|
+
return headers
|
redc/utils/http.py
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
from urllib.parse import urlparse
|
2
|
+
|
3
|
+
|
4
|
+
def parse_base_url(url: str) -> str:
|
5
|
+
res = urlparse(url)
|
6
|
+
|
7
|
+
if not res.scheme:
|
8
|
+
raise ValueError("URL is missing a scheme (e.g., 'http://' or 'https://')")
|
9
|
+
if not res.netloc:
|
10
|
+
raise ValueError("URL is missing a network location (e.g., 'example.com')")
|
11
|
+
|
12
|
+
return f"{url.rstrip('/')}/"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
try:
|
2
|
+
import orjson as json
|
3
|
+
|
4
|
+
def json_dumps(obj):
|
5
|
+
return json.dumps(obj).decode()
|
6
|
+
except ImportError:
|
7
|
+
try:
|
8
|
+
import ujson as json
|
9
|
+
except ImportError:
|
10
|
+
import json
|
11
|
+
|
12
|
+
def json_dumps(obj):
|
13
|
+
return json.dumps(obj)
|
14
|
+
|
15
|
+
|
16
|
+
def json_loads(obj):
|
17
|
+
return json.loads(obj)
|
@@ -0,0 +1,65 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: redc
|
3
|
+
Version: 0.1.1
|
4
|
+
Summary: RedC is a high-performance, asynchronous HTTP client library for Python, built on top of the powerful curl library
|
5
|
+
Keywords: asyncio,http,client,http-client,curl,libcurl
|
6
|
+
Author-Email: AYMEN Mohammed <let.me.code.safe@gmail.com>
|
7
|
+
License: MIT
|
8
|
+
Project-URL: Source, https://github.com/AYMENJD/redc
|
9
|
+
Project-URL: Tracker, https://github.com/AYMENJD/redc/issues
|
10
|
+
Requires-Python: >=3.9
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
|
13
|
+
<div align="center">
|
14
|
+
<img src="https://raw.githubusercontent.com/AYMENJD/redc/refs/heads/main/assets/images/redc-logo.png">
|
15
|
+
</div>
|
16
|
+
|
17
|
+
[](https://pypi.org/project/RedC) [](https://curl.se/ch/8.12.0.html) [](https://pepy.tech/project/redc)
|
18
|
+
|
19
|
+
**RedC** is a **high-performance**, asynchronous **HTTP** client library for **Python**, built on top of the powerful **curl** library. It provides a simple and intuitive interface for making HTTP requests and handling responses
|
20
|
+
|
21
|
+
## Features
|
22
|
+
|
23
|
+
- **Asynchronous by Design**: Built with `asyncio` for non-blocking HTTP requests
|
24
|
+
- **HTTP/2 Support**: Fully compatible with `HTTP/2` for faster and more efficient communication
|
25
|
+
- **curl Backend**: Leverages the speed and reliability of curl for HTTP operations
|
26
|
+
- **Streaming Support**: Stream large responses with ease using callback functions
|
27
|
+
- **Proxy Support**: Easily configure proxies for your requests
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
You can install RedC via pip:
|
32
|
+
|
33
|
+
```bash
|
34
|
+
pip install redc
|
35
|
+
```
|
36
|
+
|
37
|
+
## Quick Start
|
38
|
+
|
39
|
+
```python
|
40
|
+
import asyncio
|
41
|
+
from redc import Client
|
42
|
+
|
43
|
+
async def main():
|
44
|
+
async with Client(base_url="https://jsonplaceholder.typicode.com") as client:
|
45
|
+
# Make a GET request
|
46
|
+
response = await client.get("/posts/1")
|
47
|
+
response.raise_for_status()
|
48
|
+
print(response.status_code) # 200
|
49
|
+
print(response.json()) # {'userId': 1, 'id': 1, 'title': '...', 'body': '...'}
|
50
|
+
|
51
|
+
# Make a POST request with JSON data
|
52
|
+
response = await client.post(
|
53
|
+
"/posts",
|
54
|
+
json={"title": "foo", "body": "bar", "userId": 1},
|
55
|
+
)
|
56
|
+
response.raise_for_status()
|
57
|
+
print(response.status_code) # 201
|
58
|
+
print(response.json()) # {'id': 101, ...}
|
59
|
+
|
60
|
+
asyncio.run(main())
|
61
|
+
```
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
MIT [LICENSE](https://github.com/AYMENJD/redc/blob/main/LICENSE)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
redc-0.1.1.dist-info/WHEEL,sha256=IklvFvow-fIjjRRsxjKgYsPeAo3uRB_FQqgnasSUIME,158
|
2
|
+
redc-0.1.1.dist-info/RECORD,,
|
3
|
+
redc-0.1.1.dist-info/METADATA,sha256=TYgeJSgdQlBRo677QMW9TBVV9d5nTRpALlCKNfMaio8,2578
|
4
|
+
redc-0.1.1.dist-info/licenses/LICENSE,sha256=3yXboOp4DHykX75K9Rhnw_6LXjMa3EW2CQgKV9HhpUA,1068
|
5
|
+
redc.libs/libicuuc-1796a535.so.50.2,sha256=ZPT2z0tpkV6chLxylDTz47Zaw3Gt15-izOGUkLni31M,1796193
|
6
|
+
redc.libs/libnghttp2-cc579893.so.14.17.0,sha256=-G-ASfSzSSeZYNSVG5F4mC0bts_nVmt3N9TgKmw8Gvc,175065
|
7
|
+
redc.libs/libssl-ebec6e5c.so.3,sha256=InQFpfmQ3TBN-xqnhrzYNDbPreYOdZu-lFlv8zzVONY,1281721
|
8
|
+
redc.libs/libpsl-9527e555.so.0.2.4,sha256=6MsYFIUZczcz3ck8Bww9x8-dMXWvnHryv-Uv4A9OGMM,500633
|
9
|
+
redc.libs/libicudata-cb3ba60c.so.50.2,sha256=mi096d4G6tWwhWUE-5Q8VeNA2WoUS8GRbeOhH-IBpSk,20787817
|
10
|
+
redc.libs/libcurl-a0db5b13.so.4.8.0,sha256=QrutVPmxBPMPOAnBrSLkjgNFF9cGis_TKBT0sAeOt4E,897473
|
11
|
+
redc.libs/libcrypto-2321a809.so.3,sha256=AsyVX-fnJyEmdHZoFb3A7oGbBMfX_GJ4b0la2_phl6g,6751329
|
12
|
+
redc/codes.py,sha256=GIRC1cBIIBfiwOKwfnW-Xh7MXLAdB_jvITnJXlNb9gg,3862
|
13
|
+
redc/callback.py,sha256=1bjw4ZzYRztF2Jm3lXGbabNT71-gPnoEjGrLXAVBWWI,581
|
14
|
+
redc/response.py,sha256=TN2nAZf4h7eVPOOIDzWZS60BvNSEKg5s0B3h-j246M4,2021
|
15
|
+
redc/redc_ext.cpython-313t-x86_64-linux-gnu.so,sha256=aQvQn-lq_CVRXqIQMeXpim2R4N9HUgpQbLa-C4-ofoY,262209
|
16
|
+
redc/__init__.py,sha256=C-Kz-dnixxmzE6LuUEHriWtwLLrooQCy9A8Zi4oeFbQ,462
|
17
|
+
redc/callbacks.py,sha256=j13_4QbJH_SAVTDtf_Tflsfy4YIuDQuutbSzaaw4ZDU,3037
|
18
|
+
redc/client.py,sha256=SawnsyU8-nUPfyIlaHXrHyCA_ucCZcTJoS1L6cA3IJU,28416
|
19
|
+
redc/ext/redc.cpp,sha256=8f-8yWt1zCVzZYxnC-T4H3u0PwXUIz71fCpfotPMJPQ,11128
|
20
|
+
redc/ext/redc.h,sha256=q3taUAklU85kVTzsR6g91pIYWdKn6V9EaQ6_IDw96RE,2411
|
21
|
+
redc/ext/utils/concurrentqueue.h,sha256=UkvC3lgezJXmMu5qrCZ21qECmmkqnBtKMuSoBgirrV4,152879
|
22
|
+
redc/ext/utils/curl_utils.h,sha256=-hOQ-lMHM6nn-T7rm3jaQt6317qytptkxtZh0e61mH4,1566
|
23
|
+
redc/utils/__init__.py,sha256=R1AUdbRF4O2BFy-DeU59UKW11Nu0DtI4YhKAivhdZuI,214
|
24
|
+
redc/utils/json_encoder.py,sha256=D1pEFXqjq9TlZ5jeVXP24c7iSQS9Oks-dXTHIE5s8WE,306
|
25
|
+
redc/utils/headers.py,sha256=YY-yvyKFX5p3cSiAhveP_G5E4BKJ_ZMMnQQHPv55e0k,1840
|
26
|
+
redc/utils/http.py,sha256=D2F7eWtvI4vKJX0Bk0ax0JWCsfI8IWJQjqLhT58ROoc,346
|
27
|
+
redc/exceptions/__init__.py,sha256=frYN6YwAIuivKlresWzIuCFHuDpXPpRbAK6aHA2OWVQ,792
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 RedC, AYMEN
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|