redc 0.1.1.dev1__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.
@@ -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
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
@@ -0,0 +1,5 @@
1
+ __all__ = ["check_key_dict", "Headers", "json_dumps", "json_loads", "parse_base_url"]
2
+
3
+ from .headers import check_key_dict, Headers
4
+ from .json_encoder import json_dumps, json_loads
5
+ from .http import parse_base_url
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,64 @@
1
+ Metadata-Version: 2.1
2
+ Name: redc
3
+ Version: 0.1.1.dev1
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
+ [![Version](https://img.shields.io/pypi/v/redc?style=flat&logo=curl&logoColor=red&color=red)](https://pypi.org/project/RedC) [![CURL version](https://img.shields.io/badge/Curl-v8.11.1-red?logo=curl)](https://curl.se/ch/8.11.1.html) [![Downloads](https://static.pepy.tech/personalized-badge/redc?period=month&units=none&left_color=grey&right_color=brightgreen&left_text=Downloads)](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
+ - **curl Backend**: Leverages the speed and reliability of libcurl for HTTP operations
25
+ - **Streaming Support**: Stream large responses with ease using callback functions
26
+ - **Proxy Support**: Easily configure proxies for your requests
27
+
28
+ ## Installation
29
+
30
+ You can install RedC via pip:
31
+
32
+ ```bash
33
+ pip install redc
34
+ ```
35
+
36
+ ## Quick Start
37
+
38
+ ```python
39
+ import asyncio
40
+ from redc import Client
41
+
42
+ async def main():
43
+ async with Client(base_url="https://jsonplaceholder.typicode.com") as client:
44
+ # Make a GET request
45
+ response = await client.get("/posts/1")
46
+ response.raise_for_status()
47
+ print(response.status_code) # 200
48
+ print(response.json()) # {'userId': 1, 'id': 1, 'title': '...', 'body': '...'}
49
+
50
+ # Make a POST request with JSON data
51
+ response = await client.post(
52
+ "/posts",
53
+ json={"title": "foo", "body": "bar", "userId": 1},
54
+ )
55
+ response.raise_for_status()
56
+ print(response.status_code) # 201
57
+ print(response.json()) # {'id': 101, ...}
58
+
59
+ asyncio.run(main())
60
+ ```
61
+
62
+ ## License
63
+
64
+ MIT [LICENSE](https://github.com/AYMENJD/redc/blob/main/LICENSE)
@@ -0,0 +1,27 @@
1
+ redc.libs/libicuuc-1796a535.so.50.2,sha256=ZPT2z0tpkV6chLxylDTz47Zaw3Gt15-izOGUkLni31M,1796193
2
+ redc.libs/libnghttp2-cc579893.so.14.17.0,sha256=-G-ASfSzSSeZYNSVG5F4mC0bts_nVmt3N9TgKmw8Gvc,175065
3
+ redc.libs/libssl-ebec6e5c.so.3,sha256=TarUKl2_3ugZkLdYDg2S8HkT1RH1U5e3FoTONW-j538,1281721
4
+ redc.libs/libcrypto-cff6b41d.so.3,sha256=RxjpVlMDGw0QxlV9viNkEZNj-sgUM-wCFda-IAw9UKg,6751329
5
+ redc.libs/libpsl-9527e555.so.0.2.4,sha256=6MsYFIUZczcz3ck8Bww9x8-dMXWvnHryv-Uv4A9OGMM,500633
6
+ redc.libs/libicudata-cb3ba60c.so.50.2,sha256=mi096d4G6tWwhWUE-5Q8VeNA2WoUS8GRbeOhH-IBpSk,20787817
7
+ redc.libs/libcurl-bf2af365.so.4.8.0,sha256=l417JwQpv9QHvLkLSxeIcxAFLU36pd6Q_uhUmKfS1oo,889209
8
+ redc/codes.py,sha256=GIRC1cBIIBfiwOKwfnW-Xh7MXLAdB_jvITnJXlNb9gg,3862
9
+ redc/callback.py,sha256=1bjw4ZzYRztF2Jm3lXGbabNT71-gPnoEjGrLXAVBWWI,581
10
+ redc/response.py,sha256=TN2nAZf4h7eVPOOIDzWZS60BvNSEKg5s0B3h-j246M4,2021
11
+ redc/redc_ext.cpython-313t-x86_64-linux-gnu.so,sha256=sW1Nz3ojPHh3pidweaESNRGqjZCMDMl7cF8EZfVFiAw,245713
12
+ redc/__init__.py,sha256=foI3tfCffF3JJgEVyniCx2ckIz2PpT1FmPlX5rBIkGk,467
13
+ redc/callbacks.py,sha256=j13_4QbJH_SAVTDtf_Tflsfy4YIuDQuutbSzaaw4ZDU,3037
14
+ redc/client.py,sha256=SawnsyU8-nUPfyIlaHXrHyCA_ucCZcTJoS1L6cA3IJU,28416
15
+ redc/ext/redc.cpp,sha256=8f-8yWt1zCVzZYxnC-T4H3u0PwXUIz71fCpfotPMJPQ,11128
16
+ redc/ext/redc.h,sha256=q3taUAklU85kVTzsR6g91pIYWdKn6V9EaQ6_IDw96RE,2411
17
+ redc/ext/utils/concurrentqueue.h,sha256=UkvC3lgezJXmMu5qrCZ21qECmmkqnBtKMuSoBgirrV4,152879
18
+ redc/ext/utils/curl_utils.h,sha256=-hOQ-lMHM6nn-T7rm3jaQt6317qytptkxtZh0e61mH4,1566
19
+ redc/utils/__init__.py,sha256=R1AUdbRF4O2BFy-DeU59UKW11Nu0DtI4YhKAivhdZuI,214
20
+ redc/utils/json_encoder.py,sha256=D1pEFXqjq9TlZ5jeVXP24c7iSQS9Oks-dXTHIE5s8WE,306
21
+ redc/utils/headers.py,sha256=YY-yvyKFX5p3cSiAhveP_G5E4BKJ_ZMMnQQHPv55e0k,1840
22
+ redc/utils/http.py,sha256=D2F7eWtvI4vKJX0Bk0ax0JWCsfI8IWJQjqLhT58ROoc,346
23
+ redc/exceptions/__init__.py,sha256=frYN6YwAIuivKlresWzIuCFHuDpXPpRbAK6aHA2OWVQ,792
24
+ redc-0.1.1.dev1.dist-info/WHEEL,sha256=IklvFvow-fIjjRRsxjKgYsPeAo3uRB_FQqgnasSUIME,158
25
+ redc-0.1.1.dev1.dist-info/RECORD,,
26
+ redc-0.1.1.dev1.dist-info/METADATA,sha256=hyiwmVWTP0bjyDMrgaZqsrt0iYbUm5mHh1KAFn8apfQ,2489
27
+ redc-0.1.1.dev1.dist-info/licenses/LICENSE,sha256=3yXboOp4DHykX75K9Rhnw_6LXjMa3EW2CQgKV9HhpUA,1068
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: scikit-build-core 0.10.7
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313t-manylinux_2_17_x86_64
5
+ Tag: cp313-cp313t-manylinux2014_x86_64
6
+
@@ -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