Skip to content

Commit d953cde

Browse files
committed
Switch from requests to httpx
Closes #15
1 parent e43c96f commit d953cde

File tree

8 files changed

+127
-14
lines changed

8 files changed

+127
-14
lines changed

openapi_python_client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88
from typing import Any, Dict, Optional
99

10-
import requests
10+
import httpx
1111
from jinja2 import Environment, PackageLoader
1212

1313
from .openapi_parser import OpenAPI, import_string_from_reference
@@ -38,7 +38,7 @@ def _get_json(*, url: Optional[str], path: Optional[Path]) -> Dict[str, Any]:
3838
if url is not None and path is not None:
3939
raise ValueError("Provide URL or Path, not both.")
4040
elif url is not None:
41-
response = requests.get(url)
41+
response = httpx.get(url)
4242
json_bytes = response.content
4343
elif path is not None:
4444
json_bytes = path.read_bytes()

openapi_python_client/templates/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ Things to know:
3434
1. Any endpoint which did not have a tag will be in `{{ package_name }}.api.default`
3535
1. If the API returns a response code that was not declared in the OpenAPI document, a
3636
`{{ package_name }}.api.errors.ApiResponseError` wil be raised
37-
with the `response` attribute set to the `requests.Response` that was received.
37+
with the `response` attribute set to the `httpx.Response` that was received.

openapi_python_client/templates/endpoint_module.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from dataclasses import asdict
22
from typing import Dict, List, Optional, Union
33

4-
import requests
4+
import httpx
55

66
from ..client import AuthenticatedClient, Client
77
from .errors import ApiResponseError
@@ -60,7 +60,7 @@ def {{ endpoint.name }}(
6060
{% endfor %}
6161
{% endif %}
6262

63-
response = requests.{{ endpoint.method }}(
63+
response = httpx.{{ endpoint.method }}(
6464
url=url,
6565
headers=client.get_headers(),
6666
{% if endpoint.form_body_reference %}

openapi_python_client/templates/errors.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from requests import Response
1+
from httpx import Response
22

33
class ApiResponseError(Exception):
44
""" An exception raised when an unknown response occurs """

openapi_python_client/templates/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ include = ["CHANGELOG.md", "{{ package_name }}/py.typed"]
1414

1515
[tool.poetry.dependencies]
1616
python = "^3.8"
17-
requests = "^2.22.0"
17+
httpx = "^0.12.1"

poetry.lock

Lines changed: 115 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ include = ["CHANGELOG.md", "openapi_python_client/py.typed"]
1616

1717
[tool.poetry.dependencies]
1818
python = "==3.*,>=3.8.0"
19-
requests = "^2.22.0"
2019
jinja2 = "^2.11.1"
2120
stringcase = "^1.2.0"
2221
typer = "^0.1.0"
2322
colorama = {version = "^0.4.3", markers = "sys_platform == 'win32'"}
2423
shellingham = "^1.3.2"
24+
httpx = "^0.12.1"
2525

2626
[tool.poetry.scripts]
2727
openapi-python-client = "openapi_python_client.cli:app"

tests/test___init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_update_existing_client(mocker):
5656

5757
class TestGetJson:
5858
def test__get_json_no_url_or_path(self, mocker):
59-
get = mocker.patch("requests.get")
59+
get = mocker.patch("httpx.get")
6060
Path = mocker.patch("openapi_python_client.Path")
6161
loads = mocker.patch("json.loads")
6262

@@ -70,7 +70,7 @@ def test__get_json_no_url_or_path(self, mocker):
7070
loads.assert_not_called()
7171

7272
def test__get_json_url_and_path(self, mocker):
73-
get = mocker.patch("requests.get")
73+
get = mocker.patch("httpx.get")
7474
Path = mocker.patch("openapi_python_client.Path")
7575
loads = mocker.patch("json.loads")
7676

@@ -84,7 +84,7 @@ def test__get_json_url_and_path(self, mocker):
8484
loads.assert_not_called()
8585

8686
def test__get_json_url_no_path(self, mocker):
87-
get = mocker.patch("requests.get")
87+
get = mocker.patch("httpx.get")
8888
Path = mocker.patch("openapi_python_client.Path")
8989
loads = mocker.patch("json.loads")
9090

@@ -98,7 +98,7 @@ def test__get_json_url_no_path(self, mocker):
9898
loads.assert_called_once_with(get().content)
9999

100100
def test__get_json_path_no_url(self, mocker):
101-
get = mocker.patch("requests.get")
101+
get = mocker.patch("httpx.get")
102102
loads = mocker.patch("json.loads")
103103

104104
from openapi_python_client import _get_json

0 commit comments

Comments
 (0)