httprest 0.4.2__tar.gz → 0.4.4__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.
@@ -1,25 +1,24 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: httprest
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: A library for making simple REST-like HTTP requests
5
5
  License: MIT
6
6
  License-File: LICENSE
7
7
  Author: Andrii Nechaiev
8
8
  Author-email: andrewnech@gmail.com
9
- Requires-Python: >=3.9,<4.0
9
+ Requires-Python: >=3.11,<4.0
10
10
  Classifier: Development Status :: 4 - Beta
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: License :: OSI Approved :: MIT License
13
13
  Classifier: Operating System :: POSIX :: Linux
14
14
  Classifier: Programming Language :: Python
15
15
  Classifier: Programming Language :: Python :: 3
16
- Classifier: Programming Language :: Python :: 3.9
17
- Classifier: Programming Language :: Python :: 3.10
18
16
  Classifier: Programming Language :: Python :: 3.11
19
17
  Classifier: Programming Language :: Python :: 3.12
20
18
  Classifier: Programming Language :: Python :: 3.13
21
19
  Classifier: Programming Language :: Python :: 3.14
22
20
  Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: Programming Language :: Python :: 3.9
23
22
  Classifier: Programming Language :: Python :: Implementation :: CPython
24
23
  Classifier: Topic :: Software Development :: Libraries
25
24
  Classifier: Topic :: Utilities
@@ -1,5 +1,6 @@
1
1
  """HTTP client which uses `requests` under the hood."""
2
2
 
3
+ from types import ModuleType
3
4
  from typing import Optional, Union
4
5
 
5
6
  import requests
@@ -12,11 +13,25 @@ from .timeout import Timeout
12
13
 
13
14
 
14
15
  class RequestsHTTPClient(HTTPClient):
15
- """`requests` HTTP client."""
16
+ """`requests` HTTP client.
16
17
 
17
- def __init__(self, timeout: Optional[Timeout] = None) -> None:
18
+ By default a reusable ``requests.Session`` is used (connection reuse).
19
+ Pass ``requester`` to override this:
20
+
21
+ * a custom ``requests.Session`` (e.g. with retries/adapters configured), or
22
+ * the ``requests`` module itself, to make independent module-level calls
23
+ with no connection reuse.
24
+ """
25
+
26
+ def __init__(
27
+ self,
28
+ timeout: Optional[Timeout] = None,
29
+ requester: Optional[Union[requests.Session, ModuleType]] = None,
30
+ ) -> None:
18
31
  super().__init__(timeout)
19
- self._session = requests.Session()
32
+ self._requester = (
33
+ requester if requester is not None else requests.Session()
34
+ )
20
35
 
21
36
  def _request(
22
37
  self,
@@ -37,7 +52,7 @@ class RequestsHTTPClient(HTTPClient):
37
52
  )
38
53
  try:
39
54
  response: requests.Response = getattr(
40
- self._session, method.lower()
55
+ self._requester, method.lower()
41
56
  )(
42
57
  url,
43
58
  data=data,
@@ -33,7 +33,7 @@ class UrllibHTTPClient(HTTPClient):
33
33
  data = urllib.parse.urlencode(data).encode() # type: ignore
34
34
  headers["Content-Type"] = "application/x-www-form-urlencoded"
35
35
 
36
- if json:
36
+ if json is not None:
37
37
  headers["Content-Type"] = "application/json"
38
38
  data = _jsonlib.dumps(json).encode()
39
39
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "httprest"
3
- version = "0.4.2"
3
+ version = "0.4.4"
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"
@@ -26,19 +26,19 @@ classifiers=[
26
26
 
27
27
 
28
28
  [tool.poetry.dependencies]
29
- python = "^3.9"
29
+ python = "^3.11"
30
30
  requests = {version = "^2", optional = true}
31
31
 
32
32
  [tool.poetry.extras]
33
33
  requests-client = ["requests"]
34
34
 
35
35
  [tool.poetry.group.test.dependencies]
36
- pytest = "^8.3.2"
37
- pytest-cov = "^5.0.0"
38
- responses = "^0.25.3"
36
+ pytest = "^9"
37
+ pytest-cov = "^7"
38
+ responses = "^0.26"
39
39
 
40
40
  [tool.poetry.group.lint.dependencies]
41
- black = {version = "^25", python = "3.11"}
41
+ black = {version = "^26", python = "3.11"}
42
42
  pylint = {version = "^4", python = "3.11"}
43
43
  flake8 = {version = "^7.1.1", python = "3.11"}
44
44
  flake8-bugbear = {version = "^25", python = "3.11"}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes