httprest 0.1.0__tar.gz → 0.1.1__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.
- {httprest-0.1.0 → httprest-0.1.1}/PKG-INFO +7 -4
- {httprest-0.1.0 → httprest-0.1.1}/README.md +4 -3
- httprest-0.1.1/httprest/http/requests_client.py +46 -0
- {httprest-0.1.0 → httprest-0.1.1}/pyproject.toml +9 -2
- {httprest-0.1.0 → httprest-0.1.1}/LICENSE +0 -0
- {httprest-0.1.0 → httprest-0.1.1}/httprest/__init__.py +0 -0
- {httprest-0.1.0 → httprest-0.1.1}/httprest/api.py +0 -0
- {httprest-0.1.0 → httprest-0.1.1}/httprest/http/__init__.py +0 -0
- {httprest-0.1.0 → httprest-0.1.1}/httprest/http/base.py +0 -0
- {httprest-0.1.0 → httprest-0.1.1}/httprest/http/urllib_client.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: httprest
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: A library for making simple REST-like HTTP requests
|
|
5
5
|
Home-page: https://github.com/litteratum/httprest
|
|
6
6
|
License: MIT
|
|
@@ -21,6 +21,8 @@ Classifier: Programming Language :: Python :: 3 :: Only
|
|
|
21
21
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
22
22
|
Classifier: Topic :: Software Development :: Libraries
|
|
23
23
|
Classifier: Topic :: Utilities
|
|
24
|
+
Provides-Extra: requests-client
|
|
25
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0) ; extra == "requests-client"
|
|
24
26
|
Project-URL: Repository, https://github.com/litteratum/httprest
|
|
25
27
|
Description-Content-Type: text/markdown
|
|
26
28
|
|
|
@@ -51,10 +53,11 @@ pip install httprest
|
|
|
51
53
|
|
|
52
54
|
|
|
53
55
|
## HTTP client
|
|
54
|
-
The library exposes an `HTTPClient` interface
|
|
55
|
-
|
|
56
|
+
The library exposes an `HTTPClient` interface and provides two implementations for it:
|
|
57
|
+
1. `http.urllib_client.UrllibHTTPClient`: the default implementation, uses the `urllib` library under the hood
|
|
58
|
+
2. `http.requests_client.RequestsHTTPClient`: uses the `requests` library under the hood
|
|
56
59
|
|
|
57
|
-
You may define your own HTTP client like this:
|
|
60
|
+
You may also define your own HTTP client like this:
|
|
58
61
|
```python
|
|
59
62
|
from httprest.http import HTTPClient, HTTPResponse
|
|
60
63
|
|
|
@@ -25,10 +25,11 @@ pip install httprest
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
## HTTP client
|
|
28
|
-
The library exposes an `HTTPClient` interface
|
|
29
|
-
|
|
28
|
+
The library exposes an `HTTPClient` interface and provides two implementations for it:
|
|
29
|
+
1. `http.urllib_client.UrllibHTTPClient`: the default implementation, uses the `urllib` library under the hood
|
|
30
|
+
2. `http.requests_client.RequestsHTTPClient`: uses the `requests` library under the hood
|
|
30
31
|
|
|
31
|
-
You may define your own HTTP client like this:
|
|
32
|
+
You may also define your own HTTP client like this:
|
|
32
33
|
```python
|
|
33
34
|
from httprest.http import HTTPClient, HTTPResponse
|
|
34
35
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""HTTP client which uses `requests` under the hood."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
|
|
7
|
+
from .base import (
|
|
8
|
+
HTTPClient,
|
|
9
|
+
HTTPConnectionError,
|
|
10
|
+
HTTPRequestError,
|
|
11
|
+
HTTPResponse,
|
|
12
|
+
HTTPTimeoutError,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class RequestsHTTPClient(HTTPClient):
|
|
17
|
+
"""`requests` HTTP client."""
|
|
18
|
+
|
|
19
|
+
def __init__(self, request_timeout: float = 5) -> None:
|
|
20
|
+
super().__init__(request_timeout)
|
|
21
|
+
self._session = requests.Session()
|
|
22
|
+
|
|
23
|
+
def _request(
|
|
24
|
+
self,
|
|
25
|
+
method: str,
|
|
26
|
+
url: str,
|
|
27
|
+
json: Optional[dict] = None,
|
|
28
|
+
headers: Optional[dict] = None,
|
|
29
|
+
) -> HTTPResponse:
|
|
30
|
+
try:
|
|
31
|
+
response: requests.Response = getattr(
|
|
32
|
+
self._session, method.lower()
|
|
33
|
+
)(url, json=json, timeout=self.request_timeout, headers=headers)
|
|
34
|
+
except ConnectionError as exc:
|
|
35
|
+
raise HTTPConnectionError(exc) from exc
|
|
36
|
+
except requests.Timeout as exc:
|
|
37
|
+
raise HTTPTimeoutError(exc) from exc
|
|
38
|
+
except requests.RequestException as exc:
|
|
39
|
+
raise HTTPRequestError(exc) from exc
|
|
40
|
+
|
|
41
|
+
return HTTPResponse(
|
|
42
|
+
response.status_code, response.content, dict(response.headers)
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
def __str__(self) -> str:
|
|
46
|
+
return self.__class__.__name__
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "httprest"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.1"
|
|
4
4
|
description = "A library for making simple REST-like HTTP requests"
|
|
5
5
|
authors = ["Andrii Nechaiev <andrewnech@gmail.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -22,13 +22,18 @@ classifiers=[
|
|
|
22
22
|
"Topic :: Utilities",
|
|
23
23
|
]
|
|
24
24
|
|
|
25
|
+
|
|
25
26
|
[tool.poetry.dependencies]
|
|
26
27
|
python = "^3.9"
|
|
28
|
+
requests = {version = "^2.32.3", optional = true}
|
|
27
29
|
|
|
30
|
+
[tool.poetry.extras]
|
|
31
|
+
requests-client = ["requests"]
|
|
28
32
|
|
|
29
33
|
[tool.poetry.group.test.dependencies]
|
|
30
34
|
pytest = "^8.3.2"
|
|
31
35
|
pytest-cov = "^5.0.0"
|
|
36
|
+
responses = "^0.25.3"
|
|
32
37
|
|
|
33
38
|
|
|
34
39
|
[tool.poetry.group.lint.dependencies]
|
|
@@ -38,6 +43,7 @@ flake8 = {version = "^7.1.1", python = "3.11"}
|
|
|
38
43
|
flake8-bugbear = {version = "^24.8.19", python = "3.11"}
|
|
39
44
|
mypy = {version = "^1.11.1", python = "3.11"}
|
|
40
45
|
pydocstyle = {version = "^6.3.0", python = "3.11"}
|
|
46
|
+
types-requests = "^2.32.0.20240914"
|
|
41
47
|
|
|
42
48
|
[build-system]
|
|
43
49
|
requires = ["poetry-core"]
|
|
@@ -61,7 +67,7 @@ ignore_missing_imports = true
|
|
|
61
67
|
ignore = "D102,D105,D107,D203,D213,D413"
|
|
62
68
|
|
|
63
69
|
[tool.pylint.'MAIN']
|
|
64
|
-
py-version=3.
|
|
70
|
+
py-version=3.9
|
|
65
71
|
|
|
66
72
|
[tool.pylint.'BASIC']
|
|
67
73
|
good-names = [
|
|
@@ -76,6 +82,7 @@ good-names = [
|
|
|
76
82
|
[tool.pylint.'MESSAGES CONTROL']
|
|
77
83
|
disable = [
|
|
78
84
|
"fixme",
|
|
85
|
+
"import-error"
|
|
79
86
|
]
|
|
80
87
|
|
|
81
88
|
[tool.pylint.'VARIABLES']
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|